gpt4 book ai didi

ssl - 使用 ProxySelector 的 Jax-WS Axis2 Proxy over SSL 错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:38 25 4
gpt4 key购买 nike

在我的项目中,我有以下项目结构:

我有一个生成 war 文件的模块,可以部署在 Tomcat 应用程序服务器中。此模块依赖于 Axis2 库:

<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-webapp</artifactId>
<type>war</type>
</dependency>

并且这个类在WEB-INF下的conf文件夹中包含一个axis2.xml文件。

现在这个模块依赖于一个 jar 包类型的单元模块。

现在在我的网络模块中,在我的 stub 代码中有以下代码:

瞪羚对象验证器.getInstance().validateObject();

XcpdValidationService 是 jar 模块(依赖项)中的一个类,此方法通过 SSL 并使用代理调用外部 Web 服务。

此 Web 服务客户端由 JAX WS RI 生成

但是这个类不使用父模块中的 axis2.xml 配置,而是使用它自己的轴配置,作为默认配置,我的代理没有配置...

@WebEndpoint(name = "GazelleObjectValidatorPort")
public GazelleObjectValidator getGazelleObjectValidatorPort() {
return super.getPort(new QName("http://ws.validator.sch.gazelle.ihe.net/", "GazelleObjectValidatorPort"), GazelleObjectValidator.class);
}

方法本身是这样的:

@WebMethod
@WebResult(name = "validationResult", targetNamespace = "")
@RequestWrapper(localName = "validateObject", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObject")
@ResponseWrapper(localName = "validateObjectResponse", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObjectResponse")
public String validateObject(
@WebParam(name = "base64ObjectToValidate", targetNamespace = "")
String base64ObjectToValidate,
@WebParam(name = "xmlReferencedStandard", targetNamespace = "")
String xmlReferencedStandard,
@WebParam(name = "xmlMetadata", targetNamespace = "")
String xmlMetadata)
throws SOAPException_Exception
;

我的 GazelleObjectValidatorService 由以下插件生成:

 <plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>${axis2.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>package-aar</id>
<phase>prepare-package</phase>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
<configuration>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/wsdl</directory>
<outputDirectory>META-INF</outputDirectory>
<includes>
<include>**/*.xsd</include>
</includes>
</fileSet>
</fileSets>
<servicesXmlFile>${project.build.outputDirectory}/axis2/services.xml</servicesXmlFile>
<wsdlFile>${project.build.outputDirectory}/wsdl/ClientConnectorService.wsdl</wsdlFile>
</configuration>
</plugin>

我试图用我自己定义的 MyCommonsHttpTransportSender 覆盖我的 axis2.xml 配置中的 transportSender:

<transportSender name="http"
class="eu.epsos.pt.cc.MyCommonsHTTPTransportSender">
<parameter name="PROTOCOL">HTTP/1.1</parameter>
<parameter name="Transfer-Encoding">chunked</parameter>

<transportSender name="https"
class="eu.epsos.pt.cc.MyCommonsHTTPTransportSender">
<parameter name="PROTOCOL">HTTP/1.1</parameter>
<parameter name="Transfer-Encoding">chunked</parameter>
</transportSender>

知道代理。

但不幸的是,由于 Web 服务客户端在依赖于 war 的 jar 中,它似乎没有使用我的 axis2.xml 配置,而是使用它自己的轴配置,它不知道代理.

这会导致以下错误,您可以清楚地看到它使用默认的 CommonsHTTPTransportSender 并因此抛出错误:

Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:578)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:127)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:93)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:373)
... 40 common frames omitted

有没有办法让子 jar 中的 WS 客户端使用与父模块相同的 axis2 配置(这是一个可部署的 war 并且具有 axis2 依赖项?)

更新:

我的 WAR 文件有一个 axis2 配置,从这个 war 的源代码来看,调用了一个使用 wsimport 生成的服务,该服务位于一个 JAR 中,该 JAR 是父 WAR 的依赖项。该服务调用外部 Web 服务,这发生在 Axis 上(尽管不使用 axis2.xml 配置文件,因为它位于 JAR 的 WEB-INF 文件夹中。难道没有任何可能在没有 Axis 的情况下在 JAR 中进行外部 WebService 调用并仅使用 JAXWS 吗?这将解决我的问题...

最佳答案

Axis2 提供了一个方便的方法to configure the HTTP Transport .因此,根据您的示例代码:

HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.new ProxyProperties();
proxyProperties.setProxyHostName("hostName");
proxyProperties.setProxyPort("hostPort");
proxyProperties.setUsername("User");
proxyProperties.setPassword("pw");
//set the properties
objectValidatorService.getServiceClient().getOptions().setProperty(HttpConstants.PROXY, proxyProperties);

以上内容对您不起作用,因为您使用的是普通 JAX-WS 实现,而不是 the Axis2-specific client .根据您的堆栈跟踪,您似乎正在连接到受 TLS 保护的端点。 There's a solution for that

我做了很多研究,但无法使用普通 JAX-WS 访问底层 HTTPUrlConnection。我们所拥有的是一种通往set a custom SSLContextFactory的方法.所以我们首先创建一个自定义工厂,that will connect to the proxy first :

public class CustomSocketFactory extends SSLProtocolSocketFactory {

private static final CustomSocketFactory factory = new CustomSocketFactory();

static CustomSocketFactory getSocketFactory(){
return factory;
}

public CustomSocketFactory() {
super();
}

@Override
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) {
Socket socket = null;
try {
int proxyPort = 1000;
InetSocketAddress proxyAddr = new InetSocketAddress("proxyAddr", proxyPort);
Socket proxyConn = new Socket(new Proxy(Proxy.Type.SOCKS, proxyAddr));
proxyConn.connect(new InetSocketAddress("endHost", 443));
socket = (SSLSocket) super.createSocket(proxyConn, "proxyEndpoint", proxyPort, true);

} catch (IOException ex) {

Logger.getLogger(CustomSocketFactory.class.getName()).log(Level.SEVERE, null, ex);
}
return socket;
}
}

我们现在将向 Apache HTTPClient 运行时注册这个自定义套接字工厂(Axis 使用标准的 java HTTPUrlConnection,正如您的堆栈跟踪所证明的那样):

Protocol.registerProtocol("https",new Protocol("https", new CustomSocketFactory(), 443));

这仅适用于 TLS 连接。(尽管自定义套接字工厂也适用于非 https 端点)。您还需要将超时设置为 0 so we can guarantee that your overriden createSocket gets invoked

关于ssl - 使用 ProxySelector 的 Jax-WS Axis2 Proxy over SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45964639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com