tags:

views:

194

answers:

2

sorry ,i am asking the same question twice, I deployed the JAX-WS web service, and consuming it from my client code. My requirement is , how should i avoid building my client code (Stubs) while relocating my JAX-WS web service from one place to another?

Thanks you.

A: 

hi all, i got the solution for my question :

actually i was using the default constructor of web-Service for creating service instance.

we can use the already created stubs with the Constructor having newly relocated WSDLURL as parameter,so we need not create the client stubs once more.

more on this given here:

thanks you.

vipin k.
+1  A: 

If you are using Spring, you can create a helper bean for configuring your client (which is what I've done on 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 the ${...} are property placeholders, which means that the value is looked up from a properties file, which is specified by a PropertyPlaceholderConfigurer. An example of specifying the value looks as follows:

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

You can then modify the properties file (maybe 'myapplication.properties') to change the WSDL location as needed (even at runtime if you use 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've already answered your own question. Maybe you will find this advice useful. The good thing about using a FactoryBean-like implementation is that it can be reused for all of your web service clients and encapsulates the creation of the web services from their consumers. Your web tier or business tier objects will only depend on the SEI (service endpoint interface).

LES2