3

I have created the stub classes for consuming the web service with wsdl2java but I need to specify a client certificate for the transport. How do I do this?

In .NET I am used to be able to directly attach a X509Certificate object to similar stub classes before making the call.

lox
  • 1,602
  • 4
  • 27
  • 41

1 Answers1

1

In Java, you have a couple options:

  • Specify the java.net.ssl* parameters to setup a cert store, password, etc. You'll want to use keytool to set up these objects.

Here's the code, or these can be specified on the command line with -D. Note that these will be global to your app.

System.setProperty("javax.net.ssl.keyStore", "myKeyStore.p12");
System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
  • Create a custom SSLFactory which configures your certs at a lower level and set it on your WS context. You can google for this and find lots of info out there. Also check this question (the author says it's for JAX-RPC, but in the comments he changes his impl to JAX-WS).

You can find more info in the JSSE docs (this for java 1.5).

Community
  • 1
  • 1
Tim Jones
  • 985
  • 8
  • 14