One entry point for several web services using Spring WS 1.0

Defining one entry point for every web service request in the system can be advisable in specific scenarios such as security based on URL ones. Below it’s described this kind of solution using Spring WS 1.0 as web service stack and XMLBeans 2 as marshalling method.

web.xml

Define desired URL (for instance, http://server/app/services/)

<!-- Defines the Spring-WS MessageDispatcherServlet -->

    spring-ws
        
            org.springframework.ws.transport.http.MessageDispatcherServlet
        
        
            <!-- Transform the location attributes in WSDLs -->
            transformWsdlLocations
            true
         


<!-- Map all requests to this servlet -->

    spring-ws
    /services/*

applicationContext.xml

Configuration to get XMLObjects from XMLBeans unmarshalled at the endpoint.

<!-- EndPoint Mapping -->

    
	
                 
             
    


<!-- Payload Mapping -->

    
    <!-- XSD validation can be specified -->
    
	
                 
             
    


<!-- XSD validation -->

    <!-- Schemas repository folder -->
    
    
    


<!-- Unique endpoint -->

    <!-- XMLBeans marshalling (in &amp; out) -->
    

Endpoint Java Class

package foo.bar;

public class FCEEndPoint extends org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint {

    public FCEEndPoint(Marshaller marshaller) {
        super(marshaller);
    }

    protected Object invokeInternal(Object requestObject) throws Exception {

        XmlObject in = (XmlObject)requestObject;

        // Retrieve operation name from some point of the incoming XML
        String operationName = in.getDomNode().getFirstChild().getNodeValue();

        // Generic invoker based on Java reflection
        XmlObject out = OperationInvoker.invoke(operationName, in);

        return out;

    }
}

 

How it works?

In this way, new web services can be added by creating one XSD file and implementing its related business object. And clients only have to invoke the same URL for each request just only by using an appropiate XML.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s