我试图通过我编写的小客户端调用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合同,有这些“硬编码端点”的详细信息:
...
<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
鉴于我使用以下代码覆盖默认绑定,将调用正确的目标系统:
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,我的客户端会遇到连接异常。该错误表明以下内容:
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和我的小客户)
答案 0 :(得分:2)
引起:javax.wsdl.WSDLException:WSDLException(at / wsdl:definitions / wsdl:types / xsd:schema):faultCode = PARSER_ERROR: 解析问题 &#39; http://10.10.10.10:80/samplews/wsdl/eventmessagesws.xsd&#39;: java.net.ConnectException:连接被拒绝:连接
为了详细说明我的评论,看起来像预定义的远程主机将请求重定向到动态重置端点。您可以尝试从http://10.10.10.10:80制作eventmessagesws.xsd和samplews.xsd的本地副本,并将其放在资源目录中。更新theschemaLocation以指向本地副本。
<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>