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 "Adiga, Gururaj (IE)" <ga...@telcordia.com> on 2003/08/21 22:40:51 UTC

SecureXmlRpcClient problems

Hi all
    Can somebody provide me some sample code as to how to get the
SecureXmlRpcClient working. Also please let me know how to use the
SecurityTool for configuration. Any help would be appreciated.
I tried using the info in the site
http://www.mail-archive.com/rpc-user@xml.apache.org/msg00218.html
<http://www.mail-archive.com/rpc-user@xml.apache.org/msg00218.html> 
but it did not work.
I keep getting the message NoSuchMethodError. This is the output of the
execution.
 
D:\xmlrpchome\guru_object>d:\jdk1.3.1_01\bin\java -classpath
.;d:\xmlrpchome\xml
rpc-1.2-b1\xmlrpc-1.2-b1.jar;d:\xmlrpchome\guru_object\xmlParserAPIs.jar;d:\
xmlr
pchome\guru_object\jsse.jar HelloClient Guru
SAX driver found...
Created client to url space https://localhost:8888/RPC2
<https://localhost:8888/RPC2> 
Client created...
Client calling procedure 'Hello.sayHello' with parameters [Guru]
Exception in thread "main" java.lang.NoSuchMethodError
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.a(Unknown
Source)
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.<init>(Unknown
Sour
ce)
        at
com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl.engineInit(Unkno
wn Source)
        at javax.net.ssl.TrustManagerFactory.init(Unknown Source)
        at com.sun.net.ssl.internal.ssl.SSLContextImpl.e(Unknown Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.<init>(Unknown
Sour
ce)
        at java.lang.Class.newInstance0(Native Method)
        at java.lang.Class.newInstance(Class.java:237)
        at javax.net.ssl.SSLSocketFactory.getDefault(Unknown Source)
        at
com.sun.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(Unknown
 Source)
        at com.sun.net.ssl.HttpsURLConnection.<init>(Unknown Source)
        at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
.<init>(Unknown Source)
        at
com.sun.net.ssl.internal.www.protocol.https.Handler.openConnection(Un
known Source)
        at java.net.URL.openConnection(URL.java:781)
        at
org.apache.xmlrpc.XmlRpcClient$Worker.execute(XmlRpcClient.java:419)
        at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClient.java:163)
        at HelloClient.main(HelloClient.java:83)
----------------------------------------------------------------------------
--------------------------------------------------------------------------
 
This is the code I have written
 
import java.net.MalformedURLException;

import java.util.Vector;

import javax.net.ssl.*;

import java.security.Security;

import java.security.cert.X509Certificate;

import org.apache.xmlrpc.XmlRpc;

import org.apache.xmlrpc.XmlRpcClient;

import org.apache.xmlrpc.secure.SecureXmlRpcClient;

import org.apache.xmlrpc.XmlRpcException;

public class HelloClient

{

public void setupSSL()

{

//set our system properties

try

{

System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");

System.setProperty("com.sun.net.ssl.dhKeyExchangeFix", "true");

Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());

//needed for untrusted sites

X509TrustManager tm = new MyX509TrustManager();

KeyManager[] km = null;

TrustManager[] tma = { tm };

SSLContext sc = SSLContext.getInstance("SSL");

sc.init(km,tma,new java.security.SecureRandom());

SSLSocketFactory sf1 = sc.getSocketFactory();

HttpsURLConnection.setDefaultSSLSocketFactory(sf1);

//Added to allow sites with different names then are on the certificate

//completely optional

HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier()

{ 

public boolean verify(String urlHostname, String certHostname)

{ return true;}

 

public boolean verify(String urlHostname, SSLSession session)

{ return true;}

} );

}

catch(Exception e)

{

System.out.println(e.toString());

}

}

 

class MyX509TrustManager implements X509TrustManager

{

public boolean isClientTrusted( java.security.cert.X509Certificate[] chain )

{return true;} 

public boolean isServerTrusted( java.security.cert.X509Certificate[] chain )

{return true;}

public java.security.cert.X509Certificate[] getAcceptedIssuers() 

{return null;}

public void checkClientTrusted(X509Certificate[] chain, String authtype )

{

}

public void checkServerTrusted(X509Certificate[] chain, String authtype )

{

}

} 

public static void main(String[] args)

{

if (args.length < 1)

{

System.out.println("Usage HelloClient <your name>");

System.exit(-1);

}

try

{

HelloClient hello = new HelloClient();

hello.setupSSL();

XmlRpc.setDebug(true);

XmlRpc.setDriver("uk.co.wilson.xml.MinML");

System.out.println("SAX driver found...");

SecureXmlRpcClient client = new
SecureXmlRpcClient("https://localhost:8888/RPC2");

System.out.println("Client created...");

Vector parms = new Vector();

parms.addElement(args[0]);

String result = (String) client.execute("Hello.sayHello",parms);

System.out.println("Hello Handler returned.." + result);

}

catch (MalformedURLException e)

{

System.out.println("Incorrect URL..." + e.toString());

System.exit(-1);

}

catch (Exception e)

{

System.out.println("General Exception..." + e.toString());

System.exit(-1);

}

}

}

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

 
Thanks in advance
Guru Adiga