我正在调用部署在 HTTPS 端点中的SOAP Web服务。我的客户端是使用Eclipse生成的JAXWS客户端。在独立测试中测试客户端时,它可以正常工作。
问题在于,当我在 WebSphere Liberty Profile 上部署的Web应用程序中使用它时,它会抛出异常。我从来没有在HTTP端点中调用服务这个问题,这可能是错误的原因?
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
答案 0 :(得分:2)
问题是我需要使用服务证书设置Websphere Liberty Profile Server信任。
要做到这一点:
1)使用一对密钥生成密钥库:
keytool -genkey -alias default -keystore myKey.jks -dname "CN=myServer, O=IBM, C=CN"
2)添加服务证书(以及链中的其他证书):
keytool -import -alias service1 -file service.com.crt -keystore ./myKey.jks
3)将myKey.jks放入[WLP_DIR]/usr/servers/defaultServer/resources/security/
4)设置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"/>