自从我编写SOAP客户端以来已经有一段时间了,但是我试图编写一个通过https和通过防火墙连接/使用外部SOAP服务的客户端。
我已经手动提取了wsdl和模式,并使用Eclipse Web Service Client功能来生成Web服务代码。我现在通过get请求调用客户端代码,只是看我是否可以连接到WS。我可以在Chrome \ IE中浏览WSDL,并能够使用ReadyApi测试Java和RAD / WebSphere之外的连接。
@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中,我可以指定一个使用ssl连接套接字工厂的Proxy凭据提供程序的httpclient。我不确定如何使用使用WebServiceTemplate封送,发送和接收的SOAP客户端执行此操作。这是个好主意吗?
又如何记录或查看实际的SOAP请求以确保我发送的格式正确?
对于那些熟悉WebSphere的人来说,如何确保远程证书已正确安装和可用?
答案 0 :(得分:1)
对于问题的最后一部分,通常将选择“ CellDefaultTrustStore”和“从端口检索”,并指定远程服务器和端口:
(关于代理人问题,我没有答案。)
答案 1 :(得分:1)
@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;
}