how to set proxy server details on WebServiceTemplate

隐身守侯 提交于 2019-12-13 14:40:56

问题


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.client.core.WebServiceTemplate class to consume webservices.

My question is, Is there a way that I can pass/set the proxy server details on WebServiceTemplate to connect to endpoint url "EP1"?


回答1:


You must use VM arguments: -Dhttp.proxyHost=mydomain.com -Dhttp.proxyPort=8080

Having in mind that this setting applies to all HTTP requests made from Java.




回答2:


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.



来源:https://stackoverflow.com/questions/33879300/how-to-set-proxy-server-details-on-webservicetemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!