Wednesday, April 25, 2012

Spring Integration Generic Request Routing

On a project I was on recently, I needed to create a test harness where a lot of requests would come in through a single URL and need to be handled appropriately. Spring Integration provides a very easy way to make this happen. First you need to make use of the generic marshaller I discussed in a previous blog. Next you need to define the payloadRootAnnotationMethodEndpointMapping Spring bean, this will enable Spring to route incoming requests based on their payload root method, based on annotations placed in the endpoint classes, which I will discuss more in a minute.


    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />

    <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="marshaller"/>
    </bean>


It is amazingly simple with spring integration to use the endpoint annotations.

@Endpoint
public class MyExposedEndpoint {
    @PayloadRoot(localPart="MyEndpointMethod", namespace="http://www.company.com/mynamespace")
    public void processMyMethod(MyRequest myRequest) {
         // Insert code to process the request here.
    }
}

That's really all there is to it. The web.xml is set up the same as the first blog in this series.

1 comment:

zahidal said...

Hi Jeff,

Is it possible to use PayloadRootAnnotationMethodEndpointMapping with ws:inbound-gateway? My full requirement is explained here: http://forum.springsource.org/showthread.php?128956-Transforming-spring-ws-implementation-to-spring-integration-ws-implementation

Could you please share your experience?