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="" />

    <bean class="">
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="marshaller"/>

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

public class MyExposedEndpoint {
    @PayloadRoot(localPart="MyEndpointMethod", namespace="")
    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:

Could you please share your experience?