You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Peter Valencic <pe...@siol.net> on 2007/07/27 01:12:56 UTC

Simple Question about RPC in java

Hello to all...
I'am asking for a help..

I'am new in RPC but what i would like to do is...  the rpc server and 
both methods in the same class..
for example... I have the class which name is TimerTest...
If you look this class you can see that I have declared the RPC server...
What I need is (if is possible) using methods like "add" from the same 
class..

I have declared:
PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.addHandler("TimerTest", TimerTest.class);  <-- the same class..

but when I run client program I get Exception:

-----------
Exception in thread main
org.apache.xmlrpc.XmlRpcException: Failed to create input stream: 
Connection refused: connect
    at org.apache.xmlrpc.XmlRpcException.<init>(XmlRpcException.java:59)
    at 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:60)
    at 
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
    at 
org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:93)
    at 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:39)
    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 virtualmaster.test.Client.main(Client.java:15)
Caused by:
java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.Socket.connect(Socket.java:507)
    at java.net.Socket.connect(Socket.java:457)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:565)
    at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:936)
    at 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:58)
    at 
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
    at 
org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:93)
    at 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:39)
    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 virtualmaster.test.Client.main(Client.java:15)
-----------------------------------


This is my ServerSide app:

package virtualmaster.test;

//~--- non-JDK imports 
--------------------------------------------------------

import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

//~--- JDK imports 
------------------------------------------------------------

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.net.BindException;

import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.swing.Timer;

//~--- classes 
----------------------------------------------------------------

public class TimerTest {
  
    int            port           = 6666;    // RPC port
   

    //~--- constructors 
-------------------------------------------------------

    public TimerTest() {

    

        try {
            WebServer              webServer    = new WebServer(port);
            XmlRpcServer           xmlRpcServer = 
webServer.getXmlRpcServer();
            PropertyHandlerMapping phm          = new 
PropertyHandlerMapping();

            phm.addHandler("TimerTest", TimerTest.class);
           
            xmlRpcServer.setHandlerMapping(phm);

            XmlRpcServerConfigImpl serverConfig =
                (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();

            serverConfig.setEnabledForExtensions(true);
            serverConfig.setContentLengthOptional(false);
            webServer.start();
            System.out.println("RPC-Server started on localhost port: "
                               + port);
          
           

          
        } catch (Exception e) {
            if (timer != null) {
                timer.stop();
            }

            System.out.println("Err: " + e.toString());
            System.exit(1);
        }
    }

    //~--- methods 
------------------------------------------------------------

    public static void main(String[] args) {
        TimerTest timerTest = new TimerTest();
    }

    //this is my rpc procedure i like to use...
    public int  add(int a,int b) {
       
        return a+b;
    }
   
}

---------------------------------------------------------------------------

this is my Client app:

  import java.net.URL;

  import org.apache.xmlrpc.client.XmlRpcClient;
  import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
  public class Client {
      public static void main(String[] args) throws Exception {
          XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
             config.setServerURL(new URL("http://localhost:6666/xmlrpc"));
             XmlRpcClient client = new XmlRpcClient();
             client.setConfig(config);
             Object[] params = new Object[]{new Integer(33), new 
Integer(9)};
             Integer result = (Integer) client.execute("TimerTest.add", 
params);
             System.out.println(result.toString());
        
      }
  }


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: Simple Question about RPC in java

Posted by Kevin Brown <ke...@air2web.com>.
What interface is the server running on?  192.168.x.x, 0.0.0.0 or 
127.0.0.1?  What OS?  Wireshark and netstat are your friends. 

Jochen Wiedmann wrote:
> On 7/27/07, Peter Valencic <pe...@siol.net> wrote:
>
>   
>> Connection refused: connect
>>     at org.apache.xmlrpc.XmlRpcException.<init>(XmlRpcException.java:59)
>>     
>
> Sounds like the server is not running, or is running on another host
> than localhost, or is running on another port like 6666, or the client
> is not configured to use port 6666 or not localhost. (The latter might
> be possible, for example, if you are using a proxy server.)
>
> Jochen
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: Simple Question about RPC in java

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 7/27/07, Peter Valencic <pe...@siol.net> wrote:

> Connection refused: connect
>     at org.apache.xmlrpc.XmlRpcException.<init>(XmlRpcException.java:59)

Sounds like the server is not running, or is running on another host
than localhost, or is running on another port like 6666, or the client
is not configured to use port 6666 or not localhost. (The latter might
be possible, for example, if you are using a proxy server.)

Jochen

-- 
"Besides, manipulating elections is under penalty of law, resulting in
a preventative effect against manipulating elections.

The german government justifying the use of electronic voting machines
and obviously  believing that we don't need a police, because all
illegal actions are forbidden.

http://dip.bundestag.de/btd/16/051/1605194.pdf

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org