2
votes

i try to develop a SpringBoot Rest Server with Spring Integration HTTP -> inboundGateway.

I've an Controller, annotated with "@Controller" and "@RequestMapping" and try to create following flow:

GET Request "/" -> Channel: httpRequestChannel -> Run IndexController -> Channel: httpReplyChannel -> back to Browser

But it's not working.

My Integration Xml:

<int:channel id="httpRequestChannel">
  <int:interceptors>
    <int:wire-tap channel="logHttpRequestChannel" />
  </int:interceptors>
</int:channel>

<int:channel id="httpReplyChannel">
  <int:interceptors>
    <int:wire-tap channel="logHttpReplyChannel" />
  </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logHttpRequestChannel" level="INFO" logger-name="httpRequestChannel" log-full-message="true" />

<int:logging-channel-adapter id="logHttpReplyChannel" level="INFO" logger-name="httpReplyChannel" log-full-message="true" />

<int-http:inbound-gateway id="inboundGateway"
    request-channel="httpRequestChannel" reply-channel="httpReplyChannel"
    auto-startup="true" supported-methods="GET" path="/">
    <int-http:request-mapping produces="application/json" />
</int-http:inbound-gateway>

The error is:

Dispatcher has no subscribers

But in my opinion, the controller should be an subscriber via the RequestMapping Annotation...

I upload a sample github project: https://github.com/marcelalburg/spring-boot-integration-rest-server

Thanks for you help Marcel

UPDATE

Hello,

i see something in the documentation:

The parsing of the HTTP Inbound Gateway or the HTTP Inbound Channel Adapter registers an integrationRequestMappingHandlerMapping bean of type IntegrationRequestMappingHandlerMapping, in case there is none registered, yet. This particular implementation of the HandlerMapping delegates its logic to the RequestMappingInfoHandlerMapping. The implementation provides similar functionality as the one provided by the org.springframework.web.bind.annotation.RequestMapping annotation in Spring MVC.

So, i changed following:

    <int-http:inbound-gateway id="indexGateway"
    request-channel="httpRequestChannel" reply-channel="httpReplyChannel"
    auto-startup="true" supported-methods="GET" path="/, /test" reply-timeout="100" />

and my controller

@ServiceActivator( inputChannel = "httpRequestChannel", outputChannel = "httpReplyChannel" )
@RequestMapping( value = "/", method = RequestMethod.GET, produces = "application/json" )
public String testGateway( LinkedMultiValueMap payload, @Headers Map<String, Object> headerMap )
{
    // IntegrationRequestMappingHandlerMapping

    System.out.println( "Starting process the message [reciveing]" );

    return "{HelloMessage: \"Hello\"}";
}

@ServiceActivator( inputChannel = "httpRequestChannel", outputChannel = "httpReplyChannel" )
@RequestMapping( value = "/test", method = RequestMethod.GET, produces = "application/json" )
public String testGateway2( LinkedMultiValueMap payload, @Headers Map<String, Object> headerMap )
{
    // IntegrationRequestMappingHandlerMapping

    System.out.println( "Starting process the message [reciveing]" );

    return "{HelloMessage: \"Test\"}";
}

now, i get an response but it returns randomized "Test" and "Hello" ...

Thanks

1
or has anybody a working spring integration http project without web.xml (maybe with spring boot) wich one is working as REST Server?Marcel Alburg
And it's not feasible to create a channel for every rest methodMarcel Alburg

1 Answers

3
votes

No; you seem to have a basic misunderstanding.

With Spring Integration, the inbound-gateway replaces the@Controller, and sends the inbound (possibly converted) object as the payload of a message to the requestChannel.

Some other component (not a controller) subscribes to that channel to receive the message.

So, instead of configuring an @Controller you can either configure your POJO as a <service-activator input-channel="httpRequestChannel" .../> or annotate the method as a @ServiceActivator.

It will then consume the message and, optionally, send the reply to the output channel (omitting the output channel will cause it to be routed back to the gateway).

See the http sample for an example.