Search code examples
javamavenweb-servicessoapwsdl

Cannot create client from WSDL


I am attempting to call a SOAP service through a small client that i've written. I parse and create the wsdl types using maven.

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

The wsdl contract I have been given, has these "hardcoded endpoint" details :

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

What I've originally noticed is that the default location in the element is used to make calls to the pre-defined target. However, this behavior was not desired by my application. Instead, I'd like to dynamically adjust that. Hence, research has lead me to this post: overriding or setting web service endpoint at runtime for code generated with wsimport .

Given that I override the default binding, with the following code, the right target system gets invoked:

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

Doing this, I managed to solve the problem. i.e When I'd invoke my small client, the right target would get the message.

However, the issue that I am now noticing is that if host 10.10.10.10:80 goes down, while my overridden binding to 20.20.20.10:80 remains, I get connection exceptions in my client. The error states the following:

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

The same is also true when I try to re-compile my client with maven, in that I'd get the following error:

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

Am I missing something in ensuring that the default values are "never" used, and the dynamic value always is? ( Both maven and in my small client )


Solution

  • 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

    To elaborate my comment, look like pre-defined remote host redirect the request to dynamically reset endpoint. You could try making a local copy of eventmessagesws.xsd and samplews.xsd from http://10.10.10.10:80 and place it in resource directory. Update theschemaLocation to point to local copy.

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