how to set proxy server details on WebServiceTemplate

后端 未结 2 1939
迷失自我
迷失自我 2021-01-05 20:54

I have a SOAP webservice endpoint url(let\'s say :\"EP1\") which we can connect only through a proxy server.

We are using org.springframework.ws

2条回答
  •  别那么骄傲
    2021-01-05 21:29

    You can specify custom HttpClient via HttpComponentsMessageSender when constructing the WebServiceTemplate. You can then pass default request config which includes the proxy to the client. Something like this should work:

    RequestConfig config = RequestConfig
            .custom()
            .setProxy(new HttpHost("host"))
            .build();
    
    CloseableHttpClient client = HttpClients
            .custom()
            .setDefaultRequestConfig(config)
            .build();
    
    HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender(client);
    
    WebServiceTemplate wsTemplate = new WebServiceTemplate();
    wsTemplate.setMessageSender(messageSender);
    // Set other required properties ...
    

    You might need to set other properties on the WebServiceTemplate object or the HttpClient depending on your needs so on. But this should demonstrate the basic concept.

    Also take a look at this sample illustrating the usage of proxies in Apache HTTP client.

提交回复
热议问题