Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to reuse javax.xml.ws.Service objects?

I have JAX-WS style web service client that was auto-generated with the NetBeans IDE.

The generated proxy factory (extends javax.xml.ws.Service) delegates proxy creation to the various Service.getPort methods. The application that I am maintaining instantiates the factory and obtains a proxy each time it calls the targetted service.

Creating the new proxy factory instances repeatedly has been shown to be expensive, given that the WSDL documentation supplied to the factory constructor, an HTTP URI, is re-retrieved for each instantiation.

We had success in improving the performance by caching the WSDL. But this has ugly maintenance and packaging implications for us.

I would like to explore the suitability of caching the proxy factory itself. Is it safe, e.g., can two different client classes, executing on the same JVM and targetting the same web service, safely use the same factory to obtain distinct proxy objects (or a shared, reentrant one)?

I've been unable to find guidance from either the JAX-WS specification nor the javax.xml.ws API documentation. The factory-proxy multiplicity is unclear to me. Having Service.getPort rather than Service.createPort does not inspire confidence.

like image 895
Noel Ang Avatar asked Mar 17 '10 21:03

Noel Ang


People also ask

Is javax XML WS service thread safe?

Official JAX-WS answer: No. According to the JAX-WS spec, the client proxies are NOT thread safe. To write portable code, you should treat them as non-thread safe and synchronize access or use a pool of instances or similar.

What is javax XML WS holder?

A javax. xml. ws. Holder is a simple wrapper object that can be passed into the @WebService method as a parameter. The application sets the value of the holder during the request and the server will send the value back as an OUT parameter.

What is javax XML WS BindingProvider?

Java API for XML Web Services ( JAX-WS) is a Java programming language for creating web services, particularly SOAP services. BindingProvider is an interface which provides access to the protocol binding and associated context objects for request and response message processing.


1 Answers

you can 10000 ports in fraction of second, so it is a good idea to store service. It is also possible to store the wsdl local and change the endppoint later.

example peopleWsdl & peopleEndpoint:
file:/C:/Users/richard/Workspaces/OSB/SyllabusMailing/war/WEB-INF/wsdl/people/People_2_0.wsdl http://myserver:8011/domain/sem/People_2_0?wsdl

    private static DSSeMPeople service = null;  
private DsSemPeoplePort getPort() throws Exception
{   
    String wsdl = AppUtil.getWebXmlParameter( "peopleWsdl" );
    String endpoint = AppUtil.getWebXmlParameter( "peopleEndpoint" );
    if( wsdl==null || "".equals(wsdl) ) {
        wsdl = endpoint;
    }

    try { 
        if( service==null ) {

            log.info( "create peopleService from wsdl: " + wsdl );              
            log.info( "use peopleService endpoint: " + (endpoint==null?"(from wsdl)":endpoint) );

            URL url = new URL( wsdl );              
            service = new DSSeMPeople( url, new QName( "http://www.tudelft.nl/domain/sem/people_2_0/", "DS_SeM_People") );
        }

        DsSemPeoplePort port = service.getDsSemPeoplePort();

        // set endpoint
        if( endpoint!=null && !"".equals(endpoint) && !endpoint.equals(wsdl) ) {

            BindingProvider provider = (BindingProvider) port;
            provider.getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint );
        }

        return port;

    } catch (Exception e) {

        String msg = "Failed to connect to people webservice. ";
        log.error( msg );
        throw new Exception( msg, e );
    }       
}
like image 125
Ricahard van den den berg Avatar answered Sep 18 '22 05:09

Ricahard van den den berg