通过代理连接到 AXIS 1.4 Web 服务
我正在使用 AXIS 1.4 为我的网络服务生成子程序。该生成工作正常,但我面临着通过 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>
如果我在连接之前使用以下属性 - 一切正常,但我在虚拟机范围内设置了属性,这是不可取的:
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;
}
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)非常感谢您的帮助!如果您需要更多/其他信息来帮助,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,在我的例子中它有效,使用 System.setProperty 不是一个好主意,因为它设置了 VM 的值。使用 AxisProperties 将仅为特定连接设置值。我正在使用 AXIS 1.4 客户端。
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.