我正在尝试使用Spring Boot创建CXF客户端。 WSDL包含在我的项目中。用cxf-codegen-plugin
生成的源。当我发送请求时,客户端抛出错误:
WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://bip.bee.kz/SyncChannel/v10/Interfaces}ISyncChannelHttpService#{http://bip.bee.kz/SyncChannel/v10/Interfaces}SendMessage has thrown exception, unwinding now
java.lang.NullPointerException: null
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.createConnection(URLConnectionHTTPConduit.java:112)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.setupConnection(URLConnectionHTTPConduit.java:125)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:505)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:47)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
at com.sun.proxy.$Proxy35.sendMessage(Unknown Source)
at kz.alfabank.egovenforcementagencies.TestClient.main(TestClient.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set
at org.apache.cxf.jaxws.JaxWsClientProxy.mapException(JaxWsClientProxy.java:195)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
at com.sun.proxy.$Proxy35.sendMessage(Unknown Source)
at kz.alfabank.egovenforcementagencies.TestClient.main(TestClient.java:112)
... 8 more
Caused by: java.lang.NullPointerException
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.createConnection(URLConnectionHTTPConduit.java:112)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.setupConnection(URLConnectionHTTPConduit.java:125)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:505)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:47)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
... 10 more
我在StackOverflow和社区中进行了搜索,他们建议向SOAP请求添加一些标头,因为问题可能与请求标头有关。但是在他们的情况下,他们能够记录CXF消息。我什至看不到这些消息,因为在发送之前抛出了错误。有人可以帮我找出解决方案吗?
实施
try {
// ISyncChannelHttpService service = new ISyncChannelHttpService(new URL("https://url"));
ISyncChannelHttpService service = new ISyncChannelHttpService();
/*
* Retrieve the port (interface) from the service information
* to invoke available methods
*/
ISyncChannel syncChannelHttpPort = service.getSyncChannelHttpPort();
Client client = ClientProxy.getClient(syncChannelHttpPort);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Endpoint endpoint = client.getEndpoint();
/*
* Preparing SyncSendMessageRequest as parameter to invoke sendMessage method
* from interface syncChannelHttpPort
*/
SyncSendMessageRequest syncSendMessageRequest = new SyncSendMessageRequest();
/*
* Preparing message info for syncSendMessageRequest
*/
SyncMessageInfo syncMessageInfo = new SyncMessageInfo();
SenderInfo sender = new SenderInfo();
sender.setSenderId(senderId);
sender.setPassword(senderPassword);
syncMessageInfo.setMessageId(UUID.randomUUID().toString());
syncMessageInfo.setMessageId(accountRequestServiceId);
syncMessageInfo.setMessageDate(getXMLGregorianCalendarFromDate(new Date()));
syncMessageInfo.setSender(sender);
/*
* Preparing message data for syncSendMessageRequest
*/
RequestData requestData = new RequestData();
RequestData.Data value = new RequestData.Data();
R01 r01 = new R01();
R01RequestMessage r01RequestMessage = new R01RequestMessage();
r01RequestMessage.setBankID(bankId);
r01.setItems(r01RequestMessage);
value.setR01(r01);
// TODO 2 sign r01
requestData.setData(value);
syncSendMessageRequest.setRequestInfo(syncMessageInfo);
syncSendMessageRequest.setRequestData(requestData);
/*
* Sending e-gov's synchronous request message
* and retrieve e-gov's synchronous response message
*/
logger.info(">>>>>>>>> sending message...");
SyncSendMessageResponse syncSendMessageResponse = syncChannelHttpPort.sendMessage(syncSendMessageRequest);
// TODO 3
// TODO 4
// TODO 5
} catch (SendMessageSendMessageFaultMsg sendMessageSendMessageFaultMsg) {
sendMessageSendMessageFaultMsg.printStackTrace();
}