Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Using xmlRpc in java

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Using xmlRpc in java

    Hello i want create gui for aria2c( internet download manager ) with java for doing this aria2c has built in xmlrpc. i use xmlRpc to create gui for aria2c. in aria2c support site there is a example code for python programming language that uses xmlrpc
    >>> import xmlrpclib
    >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc')
    >>> s.aria2.addUri(['http://example.org/file'])
    '1'
    i write this java code for doing this in java
    package Aria2c;
     
    import java.net.MalformedURLException;
    import org.apache.xmlrpc.XmlRpcException;
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
    import java.net.URL;
    import org.apache.xmlrpc.client.XmlRpcClient;
    import java.util.Vector;
     
    public class JavaClient{
     
    	private static Vector< String > params;
    	public JavaClient( )
    	{
    		params.add("http://rs230dt.rapidshare.com/files/344243800/10012723.LinuxCBT.Debian.part8.rar");
    	}
        	public static void main( String[] args )
        	{
        		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        		try {
    				config.setServerURL(new URL("http://localhost:6800/rpc"));
    			} catch (MalformedURLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
        		XmlRpcClient client = new XmlRpcClient();
        		client.setConfig(config);
     
        		try {
    				client.execute("aria2.addUri", params );
    			} catch (XmlRpcException e1) {
    				// TODO Auto-generated catch block
    				e1.printStackTrace();
    			}
     
        }
    }
    but when i want compile this i have these exceptions
    org.apache.xmlrpc.XmlRpcException: Failed to read server's response: Connection refused
    	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:161)
    	at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
    	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
    	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
    	at Aria2c.JavaClient.main(JavaClient.java:30)
    Caused by: java.net.ConnectException: Connection refused
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
    	at java.net.Socket.connect(Socket.java:546)
    	at java.net.Socket.connect(Socket.java:495)
    	at sun.net.NetworkClient.doConnect(NetworkClient.java:174)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
    	at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
    	at sun.net.www.http.HttpClient.New(HttpClient.java:321)
    	at sun.net.www.http.HttpClient.New(HttpClient.java:338)
    	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:814)
    	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:755)
    	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:680)
    	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:858)
    	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.writeRequest(XmlRpcSunHttpTransport.java:104)
    	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:151)
    	... 7 more
    Caused by:
    java.net.ConnectException: Connection refused
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
    	at java.net.Socket.connect(Socket.java:546)
    	at java.net.Socket.connect(Socket.java:495)
    	at sun.net.NetworkClient.doConnect(NetworkClient.java:174)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
    	at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
    	at sun.net.www.http.HttpClient.New(HttpClient.java:321)
    	at sun.net.www.http.HttpClient.New(HttpClient.java:338)
    	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:814)
    	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:755)
    	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:680)
    	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:858)
    	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.writeRequest(XmlRpcSunHttpTransport.java:104)
    	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:151)
    	at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
    	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
    	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
    	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
    	at Aria2c.JavaClient.main(JavaClient.java:30)
    how i can improve this cod?
    please help me


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Using xmlRpc in java

    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
    config.setServerURL(new URL("http://localhost:6800/rpc"));
    } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);

    try {
    client.execute("aria2.addUri", params );
    } catch (XmlRpcException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }

    }


    This part appears to be throwing those exceptions.

    Then it calls printStackTrace();

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Using xmlRpc in java

    By any chance is this supposed to be an applet, just wondering? Applets don't have a main method.

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Using xmlRpc in java

    This exception is thrown by the XmlRpcClient, if an invocation of the remote method failed. Failure may have two reasons: The invocation failed on the remote side (for example, an exception was thrown within the server) or the communication with the server failed. The latter is indicated by throwing an instance of XmlRpcClientException.

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Using xmlRpc in java

    at Aria2c.JavaClient.main(JavaClient.java:30)

    Looks like the problems is at line 30, or it's calling the method that causes the problem, directly or indirectly, there.

    This error is beyond my knowledge. I've no clue about networking yet.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using xmlRpc in java

    I've never use the package you are referring to, but it seems you are attempting to access the localhost (your machine) on port 6800...which means something should be listening and/or broadcasting on said port. Given the exception I'd say this is not the case, so you probably need to figure out if there are additional installation steps to set up the listener/broadcaster for that port.

  8. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (November 9th, 2010)