Connect to AXIS 1.4 Webservice through a proxy

11,277

Try this, in my case it works, it is not a good idea to use System.setProperty as it sets the value for VM. Using AxisProperties will set the value only for specific connection. I am using AXIS 1.4 client.

AxisProperties.getProperties().put("proxySet","true");

    AxisProperties.setProperty("http.proxyHost", PROXY_HOST); 
    AxisProperties.setProperty("http.proxyPort", PROXY_PORT); 
Share:
11,277
Marc Giombetti
Author by

Marc Giombetti

Chief Product Architect @ Two Impulse | Coder, husband and father.

Updated on July 14, 2022

Comments

  • Marc Giombetti
    Marc Giombetti almost 2 years

    I am using AXIS 1.4 to generate the subs for my webservice. The generation works fine as it is, but I am facing a problem to connect to the webservice though a WebProxy.

    I use the axistools-maven-plugin to generate my axis classes.

       <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>axistools-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
     <urls>
      <url>http://mywiki/rpc/soap-axis/confluenceservice-v1?wsdl</url>
     </urls>
    
     <outputDirectory>${project.build.directory}/generated-wsdl-sources</outputDirectory>
     <packageSpace>de.allianz.wsdl.confluence</packageSpace>
     <testCases>false</testCases>
     <serverSide>false</serverSide>
     <subPackageByFileName>false</subPackageByFileName>
    </configuration>
    <executions>
     <execution>
      <id>add wsdl source</id>
      <phase>generate-sources</phase>
      <goals>
       <goal>wsdl2java</goal>
      </goals>
     </execution>
    </executions>
    <dependencies>
     <dependency>
      <groupId>axis</groupId>
      <artifactId>axis</artifactId>
      <version>1.4</version>
     </dependency>
    </dependencies>
    

    If I use the following properties before the connect - everything works fine, but I set the properties VM wide which is not desirable:

     public void setProxyHost(String proxyHost) {
      this.proxyHost = proxyHost;
      if(proxyHost != null){
       System.setProperty("http.proxyHost", proxyHost);
       AxisProperties.setProperty("http.proxyHost", proxyHost);  
    
      }  
     }
    
     public void setProxyPort(int proxyPort) {
      this.proxyPort = proxyPort;
      System.setProperty("http.proxyPort", ""+proxyPort);
      AxisProperties.setProperty("http.proxyPort", ""+proxyPort);  
     }

    Is there any way to tell axis to generate sources to connect through a proxy? (I already read about how th specify a proxy when generating the sources (to access the WSDL) but this is not what I need - I need to connect to the final webservice through a proxy)

    I already tried to do the following:

    private ConfluenceSoapService createConfluenceSoapService()
       throws ServiceException {
      ConfluenceSoapServiceServiceLocator csssl = new ConfluenceSoapServiceServiceLocator();
      ConfluenceSoapService confluenceSoapService;
      if (confluenceserviceAddress == null) {
       confluenceSoapService = csssl.getConfluenceserviceV1();
      } else {
       URL endpoint;
       try {
        //endpoint = new URL(confluenceserviceAddress);
        endpoint = new URL("http",proxyHost,proxyPort,confluenceserviceAddress);
       } catch (java.net.MalformedURLException e) {
        throw new javax.xml.rpc.ServiceException(e);
       }
       confluenceSoapService = csssl.getConfluenceserviceV1(endpoint);
      }
      ConfluenceserviceV1SoapBindingStub stub = (ConfluenceserviceV1SoapBindingStub) confluenceSoapService;
      stub.setTimeout(timeout);
      return confluenceSoapService;
     }
    
    and change the endpoint to an URL using a proxy - but this leads to the following problem at runtime (even though the proxy settings are set correctly to the URL object. If I use the URL object without the proxy, I get to errors.
    java.net.MalformedURLException: For input string: "8080http:"
     at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
     at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
     at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
     at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
     at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
     at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
     at org.apache.axis.client.Call.invoke(Call.java:2767)
    
    My Questions: - Am I missing something? - Is there a way to tell axis to generate the sources to work with a web proxy (to be accessed through a web proxy)

    Thanks a lot for your help! Please let me know if you need more/other information to help.