title: Spring-WS client with certificate
body: <p>I am new to web services and I need to write simple spring-ws client that will comunicate with server over SSL. The situation is:</p>
  
  <ul>
  <li>My client works well with http on my localhost ws server on my Glassfish (problem is remote server and https)</li>
  <li>Remote server works correctly. I will work just with data it sends me</li>
  <li>I have server's https address</li>
  <li>I have client certificate from server provider</li>
  </ul>
  
  <p>I thought it'll be easy to find a simple tutorial for such task but I have problem to find something like that. Is it really so unusual or is it problem in me? Do you know some good tutorial/book for create this? It could be some simple quick steps, I really just need to connect to that server and get data from it.</p>
  
  <p>I am using:</p>
  
  <ul>
  <li>STS 3.0.0.M3</li>
  <li>JDK 1.7</li>
  <li>Client as Java Application (later probably as dynamic web app)</li>
  <li>Generated classes from server's wsdl (JAXB)</li>
  <li>I folowed this tutorial for creating my client <a href="http://justcompiled.blogspot.sk/2010/11/web-service-client-with-spring-ws.html" rel="nofollow">http://justcompiled.blogspot.sk/2010/11/web-service-client-with-spring-ws.html</a></li>
  </ul>
  
  <p><strong>EDIT:</strong> More details on the topic</p>
  
  <p>I changed the client from tutorial I mentioned to work with my webservice I created on localhost (No SSL). It worked well, Requests and Responses was correct. Then I changed it to work with remote server. I generated new classes and set new address of the server in ApplicationContext. First error was missing commons-logging libraries. I added it. Then new error appeard (short version of that error): </p>
  
  <pre><code>org.springframework.ws.client.WebServiceIOException: I/O error: java.security.cert.CertificateException: No name matching certificatename found; nested exception is javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching certificatename found
  </code></pre>
  
  <p>I added my certificate to cacerts in my jdk using keytool. It didn't help. I found something about that error and tried to add code from last post in here:</p>
  
  <p><a href="http://www.coderanch.com/t/557677/sockets/java/CertificateException-No-name-matching-hostname" rel="nofollow">http://www.coderanch.com/t/557677/sockets/java/CertificateException-No-name-matching-hostname</a></p>
  
  <p>It shouldn't be very secure but I tried it. The new error was:</p>
  
  <pre><code>Exception in thread "main" org.springframework.ws.client.WebServiceTransportException: Internal Server Error [500]
  at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:663)
  at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587)
  at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
  at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:384)
  at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)
  ...
  </code></pre>