Joche,

Do you have any input on this matter? Does it seem to be a misconfiguration
or a bug?

Regards,
Jimisola


Jimisola Laursen wrote:
> 
> Hi!
> 
> I am trying to send a file over XMLRPC using an byte array (byte[]), but
> an exception is thrown when content length optional is set to true.
> At first I thought it had to do with the byte array, but I this exception
> with a simple ping/echo method as well.
> 
> I am using PropertyHandlerMapping on the server-side and a Proxy solution
> on the Agent side.
> I've used this same setup before, but I had to recreate the test from
> scratch so I am thinking that  I might have missed out on something.
> But since it works when content length optional is set to false I have my
> doubts.
> 
> Regards,
> Jimisola
> 
> These are the outputs that I get:
>  
> Client:
>  
>  [Fatal Error] :2:6: The processing instruction target matching
> "[xX][mM][lL]" is not allowed.
> Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
>       at $Proxy0.echo(Unknown Source)
>       at xmlrpctest.Client.main(Client.java:33)
> Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse
> servers response: The processing instruction target matching
> "[xX][mM][lL]" is not allowed.
>       at
> org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:177)
>       at
> org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:145)
>       at
> org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
>       at
> org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
>       at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
>       at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
>       at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
>       at
> org.apache.xmlrpc.client.util.ClientFactory$1.invoke(ClientFactory.java:104)
>       ... 2 more
>       
> Server:
> lFatal Error] :1:1: Content is not allowed in prolog.
> 
> The code:
> 
> package xmlrpctest;
> 
> import java.io.IOException;
> import java.net.InetAddress;
> 
> import org.apache.xmlrpc.XmlRpcException;
> import org.apache.xmlrpc.server.PropertyHandlerMapping;
> import org.apache.xmlrpc.server.XmlRpcServer;
> import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
> import org.apache.xmlrpc.webserver.WebServer;
> 
> public class Server
> {
>     public static void main(String[] args) throws XmlRpcException,
> IOException
>     {
>         WebServer webServer = new WebServer(8080,
> InetAddress.getByName("localhost"));
>         
>         XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
> 
>         // use reflection for (dynamic) mapping
>         PropertyHandlerMapping phm = new PropertyHandlerMapping();
> 
>         // add handler - using full name for use by dynamic proxy
>         phm.addHandler(TestRPC.class.getName(), TestRPCImpl.class);        
>         xmlRpcServer.setHandlerMapping(phm);
>         
>         XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)
> xmlRpcServer.getConfig();
>         serverConfig.setEnabledForExtensions(true);
>         serverConfig.setContentLengthOptional(true);
> 
>         webServer.start();
>     }
> }
> 
> package xmlrpctest;
> 
> import java.io.FileInputStream;
> import java.net.URL;
> 
> import org.apache.xmlrpc.client.XmlRpcClient;
> import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
> import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
> import org.apache.xmlrpc.client.util.ClientFactory;
> 
> public class Client
> {
>     public static void main(String[] args) throws Exception
>     {
>         URL url = new URL("http://localhost:8080/RPC2";);
> 
>         XmlRpcClientConfigImpl clientConfig = new
> XmlRpcClientConfigImpl();
> 
>         clientConfig.setServerURL(url);
>         clientConfig.setEnabledForExtensions(true);
>         clientConfig.setContentLengthOptional(true);
>         XmlRpcClient client = new XmlRpcClient();
> 
>         // use Commons HttpClient as transport
>         client.setTransportFactory(new
> XmlRpcCommonsTransportFactory(client));
>         // set configuration
>         client.setConfig(clientConfig);
> 
>         // make a call using dynamic proxy
>         ClientFactory factory = new ClientFactory(client);
>         TestRPC testRPC = (TestRPC) factory.newInstance(TestRPC.class);
> 
>         System.out.println(testRPC.echo("ping"));
> 
>         /*
>         FileInputStream fis = new FileInputStream("/tmp/java.txt");
>         byte[] ba = new byte[fis.available()];
>         
>         fis.read(ba);
>         fis.close();
>         int length = testRPC.upload(ba);
>         
>         System.out.println(length);
>         */
>     }
> }
> 
> package xmlrpctest;
> 
> import org.apache.xmlrpc.XmlRpcException;
> 
> public interface TestRPC
> {
>     int upload(byte[] data) throws XmlRpcException, Exception;
> 
>     String echo(String s);
> 
> }
> 
> package xmlrpctest;
> 
> import java.io.FileOutputStream;
> 
> import org.apache.xmlrpc.XmlRpcException;
> 
> public class TestRPCImpl implements TestRPC
> {
> 
>     public int upload(byte[] data) throws XmlRpcException, Exception
>     {
>         FileOutputStream fos = new FileOutputStream("/tmp/java.txt.out");
>         fos.write(data);
>         fos.close();
>         
>         return data.length;
>     }
> 
>     public String echo(String s)
>     {
>         System.out.println("Returning: " + s);
>         return s;
>     }
> }
> 
> pom.xml:
> <?xml version="1.0" encoding="UTF-8"?><project>
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>test</groupId>
>   <artifactId>test</artifactId>
>   <version>0.0.1</version>
>   <description></description>
>   <dependencies>
>     <dependency>
>       <groupId>org.apache.xmlrpc</groupId>
>       <artifactId>xmlrpc-common</artifactId>
>       <version>3.0</version>
>     </dependency>
>     <dependency>
>       <groupId>org.apache.xmlrpc</groupId>
>       <artifactId>xmlrpc-client</artifactId>
>       <version>3.0</version>
>     </dependency>
>     <dependency>
>       <groupId>org.apache.xmlrpc</groupId>
>       <artifactId>xmlrpc-server</artifactId>
>       <version>3.0</version>
>     </dependency>
>             <dependency>
>                 <artifactId>commons-codec</artifactId>
>                 <groupId>commons-codec</groupId>
>                 <version>1.3</version>
>             </dependency>
> 
>             <dependency>
>                 <artifactId>commons-httpclient</artifactId>
>                 <groupId>commons-httpclient</groupId>
>                 <version>3.0.1</version>
>             </dependency>
> 
>             <dependency>
>                 <artifactId>commons-lang</artifactId>
>                 <groupId>commons-lang</groupId>
>                 <version>2.1</version>
>             </dependency>
>   </dependencies>
> </project>
> 

-- 
View this message in context: 
http://www.nabble.com/Exception-thrown-when-setting-content-length-optional-to-true-tf2268435.html#a6362347
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to