katakam
katakam

Reputation: 51

Query parameters reading spring integration

I am new to Spring Integration, I just started looking into the specification. My requirement is to get the HTTP request (example : http://localhost:8080/LoginCheck?name=xyz&dob=zyz).

Can anybody guide me, how to proceed as i googled and found some information that we can use inbound gateway to read the parameters, my requirement like get the Http client data and do some process and finally respond to client in XML format.

I got stucked in reading the input data only.

Upvotes: 1

Views: 1427

Answers (1)

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

You have to get the payload of the received message. There should be a Map with the request parameters.

I have made a simple SI DSL application that does just that

@SpringBootApplication
public class JmsResponderApplication {

    public static void main(String[] args) {
        SpringApplication.run(JmsResponderApplication.class, args);
    }

    @Bean
    public HttpRequestHandlingMessagingGateway httpGate() {
        HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
        RequestMapping requestMapping = new RequestMapping();
        requestMapping.setMethods(HttpMethod.GET);
        requestMapping.setPathPatterns("/foo");
        gateway.setRequestMapping(requestMapping);
        gateway.setRequestChannel(requestChannel());
        return gateway;
    }

    @Bean
    public DirectChannel requestChannel() {
        return MessageChannels.direct().get();
    }

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from(requestChannel())
                .handle(new MessageHandler() {

                    @Override
                    public void handleMessage(Message<?> m) throws MessagingException {
                        Object payload = m.getPayload();
                        System.out.println(payload); // the payload is a Map that holds the params
                        System.out.println(m);
                    }
                })
                .get();
    }
}

It's a simple Spring boot starter project with this dependencies:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-java-dsl</artifactId>
            <version>1.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

Source - here

Upvotes: 1

Related Questions