Ok. Here are my hello world's and a readme for my secure xml-rpc issues. Basically, I can start the server by creating a keystore called "testkeys" and password "password", but my client chokes on the connection.
I'm not sure what I need to add to the keystore, change via the SecurityTool, or modify in the client.
I would eventually like to get *everything* working (e.g., TLS, SSL, Authentication, etc), but its best to start with the basics, I guess.
Any pointers gratefully received.
cheers,
Martin
import java.util.Vector; import java.io.IOException; import java.lang.NumberFormatException;
import org.apache.xmlrpc.secure.SecurityTool;
import org.apache.xmlrpc.secure.SecureWebServer;
import org.apache.xmlrpc.XmlRpcHandler;
/**
* This is a class for testing xmlrpc.
*
* It only has one function, which returns the value 42.
*
* Usage: java TestServer <port>
*
*/
public class TestSecureServer implements XmlRpcHandler{
/**
* @param method The name of the method that has been invoked.
* @param params The parameters of the method call.
* @return An object containing the results of the method call.
* @throws An Exception if there are any problems.
*/
public Object execute(String method, Vector params) throws Exception{
System.err.println("TestSecureServer: executing " + method);
Integer result = new Integer(42);
return result;
}
/**
* Launches a server, to listen on port XX.
*
* @param args The supplied command line arguments.
*/
public static void main(String args[]){
int port = 8080;
if(args.length > 0){
try{
port = Integer.parseInt(args[0]);
}
catch(NumberFormatException e){
e.printStackTrace();
}
}
System.out.println("Starting XML-RPC TestSecureServer on port " + port);
SecureWebServer webServer = null;
try{
SecurityTool securityTool = new SecurityTool();
System.out.println("DEFAULT_KEY_MANAGER_TYPE = " +
securityTool.DEFAULT_KEY_MANAGER_TYPE);
System.out.println("DEFAULT_KEY_STORE = " +
securityTool.DEFAULT_KEY_STORE);
System.out.println("DEFAULT_KEY_STORE_PASSWORD = " +
securityTool.DEFAULT_KEY_STORE_PASSWORD);
System.out.println("DEFAULT_KEY_STORE_TYPE = " +
securityTool.DEFAULT_KEY_STORE_TYPE);
System.out.println("DEFAULT_PROTOCOL_HANDLER_PACKAGES = " +
securityTool.DEFAULT_PROTOCOL_HANDLER_PACKAGES);
System.out.println("DEFAULT_SECURITY_PROTOCOL = " +
securityTool.DEFAULT_SECURITY_PROTOCOL);
System.out.println("DEFAULT_SECURITY_PROVIDER_CLASS = " +
securityTool.DEFAULT_SECURITY_PROVIDER_CLASS);
System.out.println("DEFAULT_TRUST_STORE = " +
securityTool.DEFAULT_TRUST_STORE);
System.out.println("DEFAULT_TRUST_STORE_PASSWORD = " +
securityTool.DEFAULT_TRUST_STORE_PASSWORD);
System.out.println("DEFAULT_TRUST_STORE_TYPE = " +
securityTool.DEFAULT_TRUST_STORE_TYPE);
System.out.println("KEY_MANAGER_TYPE = " + securityTool.KEY_MANAGER_TYPE);
System.out.println("KEY_STORE = " + securityTool.KEY_STORE);
System.out.println("KEY_STORE_PASSWORD = " +
securityTool.KEY_STORE_PASSWORD);
System.out.println("KEY_STORE_TYPE = " + securityTool.KEY_STORE_TYPE);
System.out.println("PROTOCOL_HANDLER_PACKAGES = " +
securityTool.PROTOCOL_HANDLER_PACKAGES);
System.out.println("SECURITY_PROTOCOL = " +
securityTool.SECURITY_PROTOCOL);
System.out.println("SECURITY_PROVIDER_CLASS = " +
securityTool.SECURITY_PROVIDER_CLASS);
System.out.println("TRUST_STORE = " + securityTool.TRUST_STORE);
System.out.println("TRUST_STORE_PASSWORD = " +
securityTool.TRUST_STORE_PASSWORD);
System.out.println("TRUST_STORE_TYPE = " + securityTool.TRUST_STORE_TYPE);
webServer = new SecureWebServer(port);
}
catch(IOException e){
e.printStackTrace();
System.exit(-1);
}
TestSecureServer testSecureServer = new TestSecureServer();
webServer.addHandler("test", testSecureServer);
}
}
import java.util.Vector;
import org.apache.xmlrpc.secure.SecureXmlRpcClient;
/**
* A very basic secure XML-RPC client.
*
* Usage: java TestSecureClient <url> <method> <arg>>
*
*/
public class TestSecureClient {
public final static String DEFAULT_URL_STRING = "http://127.0.0.1:8080/RPC2";
public final static String DEFAULT_METHOD = "test.testmethod";
/**
* Makes a request to the test server, and prints the results to stderr.
*/
public static void main(String args[]) throws Exception{
try{
String url = DEFAULT_URL_STRING;
if(args.length >= 1) url = args[0];
String method = DEFAULT_METHOD;
if(args.length >= 2) method = args[1];
Vector v = new Vector();
for (int i = 2; i < args.length; i++){
try{
v.addElement(new Integer(Integer.parseInt(args[i])));
}
catch(NumberFormatException nfx){
v.addElement(args[i]);
}
}
SecureXmlRpcClient secureClient = new SecureXmlRpcClient(url);
try{
System.err.println(secureClient.execute(method, v));
}
catch(Exception ex){
ex.printStackTrace();
}
}
catch(Exception x){
System.err.println(x);
System.err.println("Usage: java TestSecureClient <url> <method> <arg>
....");
System.err.println("Arguments are sent as integers or strings.");
}
}
}
Assuming that you have xmlrpc-1.1.jar in your current directory:
to compile:
javac -classpath xmlrpc-1.1.jar *.java
to run:
java -classpath xmlrpc-1.1.jar:. TestSecureServer &
then
java -classpath xmlrpc-1.1.jar:. TestSecureClient &
TestSecureServer will generate an IOException while trying to read the testkeys
KeyStore file,
as it has not yet been created.
To create a keystore, try the following:
keytool -genkey -keystore testkeys -storepass password
Leave all the values as they are for the moment. e.g. do not change
"password" to something sensible).
At the prompts, enter the appropriate information (first and last name, etc.).
Your TestSecureServer will now start without complaining.
However, TestSecureClient will produce the following error:
java.io.IOException: Unexpected end of file from server
at org.apache.xmlrpc.XmlRpcClient$Worker.execute(XmlRpcClient.java)
at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClient.java)
at TestSecureClient.main(TestSecureClient.java:40)
This is where I'm stuck.
