title: Apache CXF client error in testing server which needs Server Name Indication (SNI)
body: <p>we had a client made with Apache CXF which  was working Ok, using certain server(i.e: <a href="https://serverexample.com/application/webservice?wsdl">https://serverexample.com/application/webservice?wsdl</a>).</p>
  
  <p>But the server has moved to another IP, and now it has two SSL Certificates with TLS and SNI(Server Name Indication) in the same IP, and now our applications fails with this error:</p>
  
  <pre><code>javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching serverexample.com found
  </code></pre>
  
  <p>I understand that this occurs when the https is getting the wrong certificate (it has another server name), and thus is not matching mine. </p>
  
  <p>I tried to find out what happening with openssl, and the url only works if I put servername:</p>
  
  <pre><code># openssl s_client -connect serverexample.com:443 -tls1
  Certificate chain
   0 s:/CN=otherserver.com/OU=Servers/O=MyOrganization/C=ES
     i:/CN=ACV20/OU=PKACV/O=ACV/C=ES
  
  # openssl s_client -connect serverexample.com:443 -servername serverexample.com
  Certificate chain
   0 s:/CN=serverexample.com/OU=Servers/O=MyOrganization/C=ES
     i:/CN=ACV220/OU=PKACV1/O=ACV2/C=ES
  </code></pre>
  
  <p>The error happened in the generated apache client in this point:</p>
  
  <pre><code>final URL wsdlURL = new URL("https://serverexample.com/application/webservice?wsdl");
  final Operation_Service ss = new Operation_Service(wsdlURL, SERVICE_NAME);
  </code></pre>
  
  <p>Fails in the new Operation_Service:</p>
  
  <pre><code>@WebServiceClient(name = "ENI.Operation", 
                    wsdlLocation = "https://serverexample.com/application/webservice?wsdl",
                    targetNamespace = "http://inter.ra.es/awrp/wsdl") 
  public class Operation_Service extends Service {
      public final static URL WSDL_LOCATION;
      public final static QName SERVICE = new QName("http://inter.ra.es/awrp/wsdl", "ENI.Operation");
      public final static QName Operation = new QName("http://inter.ra.es/awrp/wsdl", "ENI.Operation");
      static {
          URL url = null;
          try {
              url = new URL("https://serverexample.com/application/webservice?wsdl");
          } catch (final MalformedURLException e) {
              java.util.logging.Logger.getLogger(Operation_Service.class.getName())
                  .log(java.util.logging.Level.INFO, 
                       "Can not initialize the default wsdl from {0}", "https://serverexample.com/application/webservice?wsdl");
          }
          WSDL_LOCATION = url;
      }
  
       public Operation_Service(final URL wsdlLocation, final QName serviceName) {
          super(wsdlLocation, serviceName);
      }
  </code></pre>
  
  <p>javax.xml.ws.Service calls javax.xml.ws.spi.ServiceDelegate, an abastract class implemented by some class in org.apache.cxf.jaxws.. but here I'm losing it, I don't know what to look...</p>
  
  <p>Our client is runnring in java 7.0 with apache cxf 3.0.4 on a weblogic 12.1.1.0. I read that in Java 6 there was problems with SNI, but we are using 7.0 here. </p>
  
  <p>I don't know what can I do. Is there some option in java or in our client to indicate the servername (like in openssl) we're trying to connect? </p>