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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]