2

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?

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Φ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.
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();
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.