Search code examples
web-servicessslwebspherejax-wswebsphere-liberty

Websphere Liberty Profile - NullPointerException when calling a SSL SOAP Web Service from a JAXWS Client - Truststore setup


I am calling a SOAP web service deployed in a HTTPS endpoint. My client is a JAXWS client generated with Eclipse. When testing the client in a standalone test it works OK.

The problem is that when I use it within a web application deployed on WebSphere Liberty Profile it throws an exception. I have never had this problem calling services in HTTP endpoints, what could be the reason of the error?

 Interceptor for {http://-----/}SomeService#{http://---- has thrown exception, unwinding now
NullPointerException invoking https://somehost/services/SomeService: null
[err] javax.xml.ws.soap.SOAPFaultException: NullPointerException invoking https://somehost/services/SomeService: null
[err]   at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
[err]   at com.sun.proxy.$Proxy175.exportProfiles(Unknown Source)
[err]   at com.codependent.SomeServiceClient.export(SomeServiceClient.java:48)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:497)
[err]   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
[err]   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
[err]   at com.sun.proxy.$Proxy117.callWs(Unknown Source)
[err]   at com.codependent.service.impl.BusinessServiceImpl.callWs(BusinessServiceImpl.java:117)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:497)
[err]   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
[err]   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
[err]   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
[err]   at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
[err]   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
[err]   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
[err]   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[err]   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
[err]   at com.sun.proxy.$Proxy123.testBS(Unknown Source)
[err]   at com.codependent.controller.HomeController.getData(HomeController.java:66)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[err]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[err]   at java.lang.reflect.Method.invoke(Method.java:497)
[err]   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
[err]   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
[err]   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
[err]   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
[err]   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
[err]   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
[err]   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
[err]   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
[err]   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
[err]   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
[err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
[err]   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
[err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
[err]   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1275)
[err]   at [internal classes]
[err]   at [internal classes]
[err]   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
[err]   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[err]   at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
[err]   at [internal classes]
[err]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[err]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[err]   at java.lang.Thread.run(Thread.java:745)
[err] Caused by: java.lang.NullPointerException: NullPointerException invoking https://somehost/services/SomeService: null
[err]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[err]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[err]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[err]   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
[err]   at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1468)
[err]   at [internal classes]
[err]   ... 75 more
[err] Caused by: java.lang.NullPointerException
[err]   at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:472)
[err]   at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
[err]   at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1282)
[err]   at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1257)
[err]   at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
[err]   at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1411)
[err]   at [internal classes]
[err]   ... 85 more

Solution

  • The problem was that I needed to set up the Websphere Liberty Profile Server trustore with the service certificate.

    To do that:

    1) Generate keystore with a pair of keys:

    keytool -genkey -alias default -keystore myKey.jks -dname "CN=myServer, O=IBM, C=CN"
    

    2) Add the service certificate (and the other certificates from the chain):

    keytool -import -alias service1 -file service.com.crt -keystore ./myKey.jks
    

    3) Put myKey.jks in [WLP_DIR]/usr/servers/defaultServer/resources/security/

    4) Setup server.xml:

    <sslDefault sslRef="customizeSSLConfig"/>
    <ssl id="customizeSSLConfig" keyStoreRef="serverKeyStore" trustStoreRef="serverTrustStore"/>
    <keyStore id="serverKeyStore" location="myKey.jks" password="pass" type="JKS"/>
    <keyStore id="serverTrustStore" location="myKey.jks" password="pass" type="JKS"/>