4

我正在使用 AXIS 1.4 为我的 web 服务生成 subs。这一代工作正常,但我面临通过 WebProxy 连接到 Web 服务的问题。

我使用axistools-maven-plugin 来生成我的轴类。

   <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>

如果我在连接之前使用以下属性 - 一切正常,但我将属性设置为 VM 范围,这是不可取的:

 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);  
 }

有没有办法告诉轴生成通过代理连接的源?(我已经阅读了如何在生成源(以访问 WSDL)时指定代理,但这不是我需要的——我需要通过代理连接到最终的 web 服务)

我已经尝试执行以下操作:

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;
 }
并使用代理将端点更改为 URL - 但这会在运行时导致以下问题(即使代理设置已正确设置为 URL 对象。如果我在没有代理的情况下使用 URL 对象,则会出现错误。
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)
我的问题: - 我错过了什么吗?- 有没有办法告诉轴生成与 Web 代理一起使用的源(通过 Web 代理访问)

非常感谢你的帮助!如果您需要更多/其他信息来帮助,请告诉我。

4

1 回答 1

5

试试这个,在我的情况下它可以工作,使用 System.setProperty 不是一个好主意,因为它设置了 VM 的值。使用 AxisProperties 将仅为特定连接设置值。我正在使用 AXIS 1.4 客户端。

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

    AxisProperties.setProperty("http.proxyHost", PROXY_HOST); 
    AxisProperties.setProperty("http.proxyPort", PROXY_PORT); 
于 2013-05-15T17:20:52.323 回答