我已经有一段时间没有编写SOAP客户端了,但我正在尝试编写一个通过https和防火墙连接/使用外部SOAP服务的客户端。
我手动提取了wsdl和模式,并使用EclipseWebServiceClient特性生成Web服务代码。我现在通过get请求调用客户端代码,只是想看看我是否可以连接到WS。我可以在Chrome\IE中浏览WSDL,并能够使用ReadyApi来测试Java和RAD/Web之外的连接。
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.complianceservice.client");
try {
marshaller.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return marshaller;
}
@Bean
public VendorClient vendorClient(Jaxb2Marshaller marshaller) {
VendorClient client = new VendorClient ();
client.setDefaultUri("https://webservice.vendor.com/WebServices/productServices.svc?wsdl");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
这将调用客户端服务代码。。。
@GetMapping(value = "/health")
public String getHealth() throws ResponseException {
Response response = vendorComplianceService.processHealth();
return response!= null?"Health, OK":"Problem detected";
}
@Override
public MessageResponse processHealth() throws ResponseException {
try {
GetDaysUntilPasswordExpiresResponse response = vendorClient.getGetDaysUntilPasswordExpires();
if (response != null){
MessageResponse myResponse = new MessageResponse();
//set something
return myResponse;
}
} catch (Exception e) {
e.printStackTrace();
throw new ResponseException(e);
}
return null;
}
public GetDaysUntilPasswordExpiresResponse getGetDaysUntilPasswordExpires( ){
GetDaysUntilPasswordExpires requestPayload = new GetDaysUntilPasswordExpires();
requestPayload.setContext(healthClientContext());
log.info("Requesting expire info for :" + clientContext.getUserID());
GetDaysUntilPasswordExpiresResponse response = (GetDaysUntilPasswordExpiresResponse) getWebServiceTemplate()
.marshalSendAndReceive("https://webservice.vendor.com/WebServices/IAccount/GetDaysUntilPasswordExpires", requestPayload
);
return response;
}
这将只是从服务器寻找连接响应的超时,因为我们的防火墙正在阻止它
我如何告诉这个客户端代码使用代理设置来通过Java/Spring中的防火墙?在REST中,我可以指定一个http客户端,该客户端使用带有ssl连接套接字工厂的代理凭据提供程序。我不知道如何对使用WebServiceTemplate封送、发送和接收的SOAP客户端执行此操作。这是个好主意吗?
此外,我如何记录或查看实际的SOAP请求,以确保我发送的格式正确?
对于那些熟悉WebSphere的人,我如何确保远程证书正确安装并可用?
对于问题的最后一部分,您通常会选择"CellDefaultTrustStore"one_answers"Retrieve from port",指定远程服务器和端口:
https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/usec_sslretrievesignercert.html
(我没有代理问题的答案。(
@dbreaux帮助将CA添加到WAS和以下内容的组合解决了问题。
在AppConfig中,我添加了这个bean。。。
@Bean
public WebServiceTemplate webServiceTemplate(){
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
MessageFactory msgFactory = null;
try {
msgFactory = MessageFactory.newInstance(SOAPConstants.DEFAULT_SOAP_PROTOCOL);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
webServiceTemplate.setMessageFactory(newSoapMessageFactory);
webServiceTemplate.setMarshaller(marshaller());
webServiceTemplate.setUnmarshaller(marshaller());
return webServiceTemplate;
}
//and then wired into the client component and set system properties for https proxy
public GetDaysUntilPasswordExpiresResponse getGetDaysUntilPasswordExpires( ){
System.getProperties().put("https.proxyHost", HTTPS_PROXY_HOST );
System.getProperties().put("https.proxyPort", HTTPS_PROXY_PORT);
System.getProperties().put("https.proxyUser", HTTPS_PROXY_USER );
System.getProperties().put("https.proxyPassword", HTTPS_PROXY_PASSWORD);
GetDaysUntilPasswordExpires requestPayload = new GetDaysUntilPasswordExpires();
requestPayload.setContext( healthClientContext());
log.info("Requesting expire info for :" + healthClientContext.getUserID());
GetDaysUntilPasswordExpiresResponse response = (GetDaysUntilPasswordExpiresResponse) webServiceTemplate
.marshalSendAndReceive(
VENDOR_WS_URL+"/Account"
,requestPayload
,new SoapActionCallback(VENDOR_WS_NAMESPACE_URL+"/IAccount/GetDaysUntilPasswordExpires"){
@Override
public void doWithMessage(WebServiceMessage message)
throws IOException {
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
soapMessage.setSoapAction(VENDOR_WS_NAMESPACE_URL+"/IAccount/GetDaysUntilPasswordExpires");
}
}
);
return response;
}