Hi I have a little problem. I want to invoke spring controller manually but I have an exception. Firstly, let me show you some integration flow and controller:
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(
Amqp.inboundAdapter(rabbitMqConfig.connectionFactory(), queue)
.acknowledgeMode(AcknowledgeMode.MANUAL)
.errorChannel("errorChannel")
.concurrentConsumers(2)
.maxConcurrentConsumers(3))
.transform(Transformers.fromJson(Event.class))
.transform(new EventToRequestTransformer())
.handle(Request.class, (request, headers) -> controller.trigger(request))
.<ResponseEntity, HttpStatus>transform(ResponseEntity::getStatusCode)
.routeToRecipients(some routing)
.get();
}
@Controller
public class SomeController {
@RequestMapping(value = "/trigger", method = RequestMethod.POST)
public ResponseEntity<Response> trigger(@RequestBody Request request)
{
//some logic
}
}
When I'm running my app and sending an event I am getting exception on line:
.handle(Request.class, (request, headers) -> controller.trigger(request))
Exception:
nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet
Could someone please tell me what is wrong and how to fix that? I thought I can just invoke controller method like it was coming from simple POJO.