I develop a code to access a SOAP-Server via proxy and regarding to the description here I can set a global Proxy. Although my question seems Naive but I have not find any guide how to set Username and Password for this proxy setting in my java code?
Asked
Active
Viewed 4,706 times
2 Answers
2
you can at runtime get the System's properties and set all what you need to configurate the proxy...
Example:
System.getProperties().put("http.proxyHost", "myProxyURL");
System.getProperties().put("http.proxyPort", "myProxyPort");
System.getProperties().put("http.proxyUser", "myUserName");
System.getProperties().put("http.proxyPassword", "myPassword");

Community
- 1
- 1

ΦXocę 웃 Пepeúpa ツ
- 47,427
- 17
- 69
- 97
-
1Thanks @ΦXocę 웃 Пepeúpa ツ. Please note that I need to change proxy setting back in other parts of the application and I have to work without any Proxy Setting. How can I do this ? This properties change the Proxy setting globally in my system. – Mazy Sep 13 '16 at 07:35
1
After some days I found the solution in my case and I try to explain it here.
- It is important to know which kind of SOAP Client service you have wrote. In my case I used CXF 3.1.7 to generate Java code. To be more explicit I had a WSDL file and Generated the code via wsdl2java plugin in maven with the mentioned version.
In the level of the WebService the follwoing can be done in code to enter the proxy Setting
private void setProxySetting(EventPortType port) { try{ Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getClient().setProxyServer("***host***"); http.getClient().setProxyServerPort(80); http.getProxyAuthorization().setUserName("***username***"); http.getProxyAuthorization().setPassword("***password***"); }catch (Exception e) { logger.error("Please Enter your proxy setting in MyClass class", e); } }
The port is comming from the Service Level that I got like this
EventService es = new EventService(); EventPortType port = es.getEventPort(); setProxySetting();

Mazy
- 175
- 1
- 4
- 9