gpt4 book ai didi

java - 无法从 WSDL 创建客户端

转载 作者:行者123 更新时间:2023-11-30 02:17:40 24 4
gpt4 key购买 nike

我正在尝试通过我编写的小型客户端调用 SOAP 服务。我使用 maven 解析并创建 wsdl 类型。

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/META-INF/wsdl</wsdlDirectory>
<wsdlLocation>http://localhost/wsdl/sample.wsdl</wsdlLocation>
<packageName>com.sample</packageName>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated-sources/</sourceDestDir>
</configuration>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
</plugin>

我收到的 wsdl 契约(Contract)有这些“硬编码端点”详细信息:

...
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://sample.com/sample/1.0">
<xsd:include
schemaLocation="http://10.10.10.10:80/samplews/wsdl/eventmessagesws.xsd" />
<xsd:include
schemaLocation="http://10.10.10.10:80/samplews/wsdl/samplews.xsd" />
</xsd:schema>
</wsdl:types>
...

<wsdl:port name="samplePort" binding="tns:sampleServiceSOAP">
<soap:address location="http://10.10.10.10:80/samplews" />
</wsdl:port>

我最初注意到的是元素中的默认位置用于调用预定义的目标。但是,我的应用程序不希望出现这种行为。相反,我想动态调整它。因此,研究让我看到了这篇文章:overriding or setting web service endpoint at runtime for code generated with wsimport.

鉴于我使用以下代码覆盖默认绑定(bind),将调用正确的目标系统:

final String endpoint = "http://20.20.20.10:80/samplews";
final SampleService service = new SampleService();
final SamplePortType samplePort = service.getSamplePort();

final BindingProvider provider = (BindingProvider) samplePort;
provier.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
samplePort.doSomething();

这样做,我成功解决了这个问题。即当我调用我的小客户端时,正确的目标会收到消息。

但是,我现在注意到的问题是,如果主机 10.10.10.10:80 出现故障,而我对 20.20.20.10:80 的覆盖绑定(bind)仍然存在,我会在客户端中收到连接异常。该错误指出以下内容:

Caused by: javax.wsdl.WSDLException: WSDLException (at /wsdl:definitions/wsdl:types/xsd:schema): faultCode=PARSER_ERROR: Problem parsing 'http://10.10.10.10:80/samplews/wsdl/eventmessagesws.xsd'.: java.net.ConnectException: Connection refused: connect

当我尝试使用 maven 重新编译客户端时也是如此,因为我会收到以下错误:

parsing WSDL...
[ERROR] Connection timed out: connect

在确保“从不”使用默认值而始终使用动态值方面,我是否遗漏了一些东西? (maven 和我的小客户端)

最佳答案

Caused by: javax.wsdl.WSDLException: WSDLException (at /wsdl:definitions/wsdl:types/xsd:schema): faultCode=PARSER_ERROR: Problem parsing 'http://10.10.10.10:80/samplews/wsdl/eventmessagesws.xsd'.: java.net.ConnectException: Connection refused: connect

为了详细说明我的评论,看起来像是预定义的远程主机将请求重定向到动态重置端点。您可以尝试从http://10.10.10.10:80制作eventmessagesws.xsd和samplews.xsd的本地副本并将其放在资源目录中。更新 schemaLocation 以指向本地副本。

<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://sample.com/sample/1.0">
<xsd:include
schemaLocation="src/main/resources/samplews/wsdl/eventmessagesws.xsd" />
<xsd:include
schemaLocation="src/main/resources/samplews/wsdl/samplews.xsd" />
</xsd:schema>
</wsdl:types>

关于java - 无法从 WSDL 创建客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802103/

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