SOAP Spring 通过 https 和防火墙的客户端请求

SOAP Spring Client Request over https and through firewall

自从我编写 SOAP 客户端以来已经有一段时间了,但我正在尝试编写一个跨 https 并通过防火墙连接/使用外部 SOAP 服务的客户端。

我手动提取了 wsdl 和模式,并使用 Eclipse Web 服务客户端功能生成了 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 中,我能够指定一个 httpclient,它使用带有 ssl 连接套接字工厂的 Proxy 凭据提供程序。我不确定如何对使用 WebServiceTemplate 进行编组、发送和接收的 SOAP 客户端执行此操作。这是个好主意吗?

另外,我如何记录或查看实际的 SOAP 请求以确保我发送的格式正确?

对于熟悉WebSphere 的人来说,如何确保远程证书正确安装和可用?

对于问题的最后一部分,您通常会 select "CellDefaultTrustStore" 和 "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;
}