How can I avoid reinstalling the client? Run when (JAX-WS) webservice moves elsewhere?

Sorry to ask the same question twice.

I deployed a JAX-WS web service and used it from my client code. My requirement: how should I avoid generating my client-side code (stub) when moving my JAX-WS web service from one location to another?

Thank.

+2


source to share


3 answers


If you are using Spring, you can create a helper bean to configure your client (this is what I did in a recent project):

<bean name="exampleClient" class="com.lingoswap.ws.util.JaxWsClientFactoryBean">
    <property name="wsdlDocumentLocation" value="${exampleClient.wsdlDocumentLocation}" />
    <property name="namespaceURI" value="http://com.example/exampleClient" />
    <property name="localPart" value="ExampleService" />
    <property name="serviceEndpointInterface" value="com.example.ExampleServicePortType" />
</bean>

      

The parts between $ {...} are property placeholders, which means that this value is viewed from a properties file that is set by PropertyPlaceholderConfigurer. An example of specifying a value looks like this:

## Web Service WSDL locations
exampleClient.wsdlDocumentLocation=http://www.example.com/exampleService?wsdl

      



Then you can modify the properties file (probably "myapplication.properties") to change the location of the WSDL as needed (even at runtime if you are using a custom TargetSource with a ProxyFactoryBean). For what it's worth, here is my implementation of a simple JaxWsClientFactoryBean (no automatic property modification support):

package com.lingoswap.ws.util;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

public class JaxWsClientFactoryBean implements FactoryBean, InitializingBean {

    private URL wsdlDocumentLocation;
    private Class<?> serviceEndpointInterface;
    private String namespaceURI;
    private String localPart;

    // derived from namespaceURI and localPart
    private QName serviceName;

    public void afterPropertiesSet() {    
        serviceName = new QName(namespaceURI, localPart);
    }

    public Object getObject() {
        Service service = Service.create(wsdlDocumentLocation, serviceName);
        Object port = service.getPort(serviceEndpointInterface);
        return port;
    }
    public Class<?> getObjectType() {
        return serviceEndpointInterface;
    }
    public boolean isSingleton() {
        return false;
    }
    public URL getWsdlDocumentLocation() {
        return wsdlDocumentLocation;
    }
    public void setWsdlDocumentLocation(final URL wsdlDocumentLocation) {
        this.wsdlDocumentLocation = wsdlDocumentLocation;
    }
    public Class<?> getServiceEndpointInterface() {
        return serviceEndpointInterface;
    }
    public void setServiceEndpointInterface(
        final Class<?> serviceEndpointInterface) {
        this.serviceEndpointInterface = serviceEndpointInterface;
    }
    public String getNamespaceURI() {
        return namespaceURI;
    }
    public void setNamespaceURI(final String namespaceURI) {
        this.namespaceURI = namespaceURI;
    }
    public String getLocalPart() {
        return localPart;
    }
    public void setLocalPart(final String localPart) {
        this.localPart = localPart;
    }
}

      

I decided to offer an answer even though you already answered your own question. You may find this advice helpful. The good thing about using a FactoryBean-like implementation is that it can be reused for all of your web service clients and encapsulate the creation of web services from its consumers. Objects of the web tier or business tier will only depend on the SEI (Service Endpoint Interface).

+3


source


I got a solution for my question:

In fact, I used the default web service constructor to instantiate the service.

we can use the already created stubs with the constructor that recently moved WSDLURL as a parameter , so we don't need to stub the clients again.



more about it here:

thank.

0


source


The code to create the stub can be written as

URL wsdlLocation = new URL("http://example.org/my.wsdl");  
QName serviceName = new QName("http://example.org/sample", "MyService");  
Service s = Service.create(wsdlLocation, serviceName);

      

We can use the properties file to change the location of the wsdl at runtime.
You don't even need to compile the client code.

0


source







All Articles