Java Spring Boot:如何访问本地 WSDL 而不是公共 WSDL URL?
我一直在使用公共 WSDL URL 来呼叫我们的客户。现在,客户决定隐藏公共 WSDL URL,并且要求我使用需要部署在我自己的服务器上的本地 WSDL。
我正在使用 Java Spring Boot,这是我之前调用公共 WSDL URL 的代码:
try {
SaajSoapMessageFactory messageFactory= new SaajSoapMessageFactory(MessageFactory.newInstance());
messageFactory.afterPropertiesSet();
WebServiceTemplate webServiceTemplate = new WebServiceTemplate( messageFactory);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(appConfig.SOAP_PKG);
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
WebServiceMessageSender messageSender = this.webServiceMessageSender();
webServiceTemplate.setMessageSender(messageSender);
try {
response = webServiceTemplate.marshalSendAndReceive(soapURL, request, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message) {
try {
SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
Map mapRequest = new HashMap();
mapRequest.put("loginuser", soapUsername);
mapRequest.put("loginpass", soapPassword);
StrSubstitutor substitutor = new StrSubstitutor(mapRequest, "%(", ")");
String finalXMLRequest = substitutor.replace(appConfig.SOAP_HEADER);
StringSource headerSource = new StringSource(finalXMLRequest);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, soapHeader.getResult());
} catch (Exception e) {
logger.error("Error while invoking session service :", e.getMessage() );
}
}
});
}catch (SoapFaultClientException e){
logger.error("Error while invoking session service : " + e.getMessage());
}
....
我现在应该如何用本地 wsdl 替换“soapURL”(marshalSendAndReceive 中使用的公共 WSDL URL)?
I have been using a public WSDL URL to make a call to our customer. Now the customer decided to hide the public WSDL URL and I have been asked to use a local WSDL that I need to deploy on my own server.
I'm using Java Spring Boot and here's my previous code to call the public WSDL URL:
try {
SaajSoapMessageFactory messageFactory= new SaajSoapMessageFactory(MessageFactory.newInstance());
messageFactory.afterPropertiesSet();
WebServiceTemplate webServiceTemplate = new WebServiceTemplate( messageFactory);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(appConfig.SOAP_PKG);
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
WebServiceMessageSender messageSender = this.webServiceMessageSender();
webServiceTemplate.setMessageSender(messageSender);
try {
response = webServiceTemplate.marshalSendAndReceive(soapURL, request, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message) {
try {
SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
Map mapRequest = new HashMap();
mapRequest.put("loginuser", soapUsername);
mapRequest.put("loginpass", soapPassword);
StrSubstitutor substitutor = new StrSubstitutor(mapRequest, "%(", ")");
String finalXMLRequest = substitutor.replace(appConfig.SOAP_HEADER);
StringSource headerSource = new StringSource(finalXMLRequest);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, soapHeader.getResult());
} catch (Exception e) {
logger.error("Error while invoking session service :", e.getMessage() );
}
}
});
}catch (SoapFaultClientException e){
logger.error("Error while invoking session service : " + e.getMessage());
}
....
How am I supposed now to replace "soapURL" which is the public WSDL URL used in marshalSendAndReceive with the local wsdl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 wsd2ljava 在 eclipse 中生成源代码,如下所示。
Java 类已创建。生成所有类后下一步是什么?我应该创建 CXF 客户端配置吗?
I used wsd2ljava to generate the sources in eclipse as shown below.
Java classes have been created. What is the next step after generating all the classes? Shall I create a CXF client configuration?