4

I have a spring integration application which uses HttpRequestHandlingMessagingGateway to accept json request sends it to transformer and then service activator, the message is then recieved by a PollableChannel and sent back

But I receive the response on alternate request's, I am running application logger on trace mode as suggested by @GaryRussell on other questions and getting the following stack trace

I am getting the following exception when removed output-channel from header-enricher :

    service activator . . .HolidaysAvailableResponse [holidayCodes=[HolidayCode [code=NEW-YEARS-DAY-ACTUAL, description=New Year's Day], HolidayCode [code=NEW-YEARS-DAY-OBSERVED, description=New Year's Day], HolidayCode [code=DAY-AFTER-NEW-YEARS-DAY, description=Day After New Year's Day (QC)], HolidayCode [code=EPIPHANY, description=Epiphany], HolidayCode [code=QUEBEC-FLAG-DAY, description=Quebec Flag Day], HolidayCode [code=GROUNDHOG-DAY, description=Groundhog Day], HolidayCode [code=VALENTINES-DAY, description=Valentine's Day], HolidayCode [code=FLAG-DAY, description=Flag Day], HolidayCode [code=ISLANDER-DAY, description=Islander Day (PE)], HolidayCode [code=HERITAGE-DAY-YT, description=Heritage Day (YT)], HolidayCode [code=LOUIS-RIEL-DAY, description=Louis Riel Day (MB)], HolidayCode [code=FAMILY-DAY, description=Family Day (AB, ON, SK)], HolidayCode [code=ST-PATRICKS-DAY-ACTUAL, description=St. Patrick's Day], HolidayCode [code=ST-PATRICKS-DAY-OBSERVED, description=St. Patrick's Day (NL)], HolidayCode [code=COMMONWEALTH-DAY, description=Commonwealth Day], HolidayCode [code=EASTER-ACTUAL, description=Easter Sunday], HolidayCode [code=EASTER-OBSERVED, description=Easter Monday], HolidayCode [code=GOOD-FRIDAY, description=Good Friday], HolidayCode [code=SHROVE-TUESDAY, description=Shrove Tuesday (Pancake Day)], HolidayCode [code=ASH-WEDNESDAY, description=Ash Wednesday], HolidayCode [code=PALM-SUNDAY, description=Palm Sunday], HolidayCode [code=MAUNDY-THURSDAY, description=Maundy Thursday], HolidayCode [code=VIMY-RIDGE-DAY, description=Vimy Ridge Day], HolidayCode [code=VICTORIA-DAY, description=Victoria Day], HolidayCode [code=NATIONAL-PATRIOTES-DAY, description=National Patriotes Day (QC)], HolidayCode [code=NATIONAL-ABORIGINAL-DAY-ACTUAL, description=National Aboriginal Day (NT)], HolidayCode [code=NATIONAL-ABORIGINAL-DAY-OBSERVED, description=National Aboriginal Day (NT)], HolidayCode [code=NATIONAL-DAY-ACTUAL, description=National Day (QC)], HolidayCode [code=NATIONAL-DAY-OBSERVED, description=National Day (QC)], HolidayCode [code=CANADA-DAY-ACTUAL, description=Canada Day], HolidayCode [code=CANADA-DAY-OBSERVED, description=Canada Day], HolidayCode [code=NUNAVUT-DAY-ACTUAL, description=Nunavut Day], HolidayCode [code=NUNAVUT-DAY-OBSERVED, description=Nunavut Day], HolidayCode [code=BRITISH-COLUMBIA-DAY, description=British Columbia Day (BC)], HolidayCode [code=HERITAGE-DAY-AB, description=Heritage Day (AB)], HolidayCode [code=CIVIC-HOLIDAY, description=Civic Holiday (MB, NT, ON, SK)], HolidayCode [code=NEW-BRUNSWICK-DAY, description=New Brunswick Day (NB)], HolidayCode [code=GOLD-CUP-PARADE-DAY, description=Gold Cup Parade (PE)], HolidayCode [code=LABOUR-DAY, description=Labour Day], HolidayCode [code=THANKSGIVING-DAY, description=Thanksgiving Day], HolidayCode [code=HALLOWEEN, description=Halloween], HolidayCode [code=REMEMBERANCE-DAY-ACTUAL, description=Rememberance Day], HolidayCode [code=REMEMBERANCE-DAY-OBSERVED, description=Rememberance Day], HolidayCode [code=CHRISTMAS-ACTUAL, description=Christmas], HolidayCode [code=CHRISTMAS-OBSERVED, description=Christmas], HolidayCode [code=BOXING-DAY-ACTUAL, description=Boxing Day], HolidayCode [code=BOXING-DAY-OBSERVED, description=Boxing Day], HolidayCode [code=NEW-YEARS-EVE, description=New Year's Eve]]]
DEBUG 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (AbstractMessageHandler.java:72) (handleMessage) - org.springframework.integration.transformer.MessageTransformingHandler#0 received message: GenericMessage [payload=HolidaysAvailableResponse [holidayCodes=[HolidayCode [code=NEW-YEARS-DAY-ACTUAL, description=New Year's Day], HolidayCode [code=NEW-YEARS-DAY-OBSERVED, description=New Year's Day], HolidayCode [code=DAY-AFTER-NEW-YEARS-DAY, description=Day After New Year's Day (QC)], HolidayCode [code=EPIPHANY, description=Epiphany], HolidayCode [code=QUEBEC-FLAG-DAY, description=Quebec Flag Day], HolidayCode [code=GROUNDHOG-DAY, description=Groundhog Day], HolidayCode [code=VALENTINES-DAY, description=Valentine's Day], HolidayCode [code=FLAG-DAY, description=Flag Day], HolidayCode [code=ISLANDER-DAY, description=Islander Day (PE)], HolidayCode [code=HERITAGE-DAY-YT, description=Heritage Day (YT)], HolidayCode [code=LOUIS-RIEL-DAY, description=Louis Riel Day (MB)], HolidayCode [code=FAMILY-DAY, description=Family Day (AB, ON, SK)], HolidayCode [code=ST-PATRICKS-DAY-ACTUAL, description=St. Patrick's Day], HolidayCode [code=ST-PATRICKS-DAY-OBSERVED, description=St. Patrick's Day (NL)], HolidayCode [code=COMMONWEALTH-DAY, description=Commonwealth Day], HolidayCode [code=EASTER-ACTUAL, description=Easter Sunday], HolidayCode [code=EASTER-OBSERVED, description=Easter Monday], HolidayCode [code=GOOD-FRIDAY, description=Good Friday], HolidayCode [code=SHROVE-TUESDAY, description=Shrove Tuesday (Pancake Day)], HolidayCode [code=ASH-WEDNESDAY, description=Ash Wednesday], HolidayCode [code=PALM-SUNDAY, description=Palm Sunday], HolidayCode [code=MAUNDY-THURSDAY, description=Maundy Thursday], HolidayCode [code=VIMY-RIDGE-DAY, description=Vimy Ridge Day], HolidayCode [code=VICTORIA-DAY, description=Victoria Day], HolidayCode [code=NATIONAL-PATRIOTES-DAY, description=National Patriotes Day (QC)], HolidayCode [code=NATIONAL-ABORIGINAL-DAY-ACTUAL, description=National Aboriginal Day (NT)], HolidayCode [code=NATIONAL-ABORIGINAL-DAY-OBSERVED, description=National Aboriginal Day (NT)], HolidayCode [code=NATIONAL-DAY-ACTUAL, description=National Day (QC)], HolidayCode [code=NATIONAL-DAY-OBSERVED, description=National Day (QC)], HolidayCode [code=CANADA-DAY-ACTUAL, description=Canada Day], HolidayCode [code=CANADA-DAY-OBSERVED, description=Canada Day], HolidayCode [code=NUNAVUT-DAY-ACTUAL, description=Nunavut Day], HolidayCode [code=NUNAVUT-DAY-OBSERVED, description=Nunavut Day], HolidayCode [code=BRITISH-COLUMBIA-DAY, description=British Columbia Day (BC)], HolidayCode [code=HERITAGE-DAY-AB, description=Heritage Day (AB)], HolidayCode [code=CIVIC-HOLIDAY, description=Civic Holiday (MB, NT, ON, SK)], HolidayCode [code=NEW-BRUNSWICK-DAY, description=New Brunswick Day (NB)], HolidayCode [code=GOLD-CUP-PARADE-DAY, description=Gold Cup Parade (PE)], HolidayCode [code=LABOUR-DAY, description=Labour Day], HolidayCode [code=THANKSGIVING-DAY, description=Thanksgiving Day], HolidayCode [code=HALLOWEEN, description=Halloween], HolidayCode [code=REMEMBERANCE-DAY-ACTUAL, description=Rememberance Day], HolidayCode [code=REMEMBERANCE-DAY-OBSERVED, description=Rememberance Day], HolidayCode [code=CHRISTMAS-ACTUAL, description=Christmas], HolidayCode [code=CHRISTMAS-OBSERVED, description=Christmas], HolidayCode [code=BOXING-DAY-ACTUAL, description=Boxing Day], HolidayCode [code=BOXING-DAY-OBSERVED, description=Boxing Day], HolidayCode [code=NEW-YEARS-EVE, description=New Year's Eve]]], headers={timestamp=1464704262960, id=b8e76d8a-97f7-c7a6-0c7a-a58d3c2ce440}]
DEBUG 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (MessagingGatewaySupport.java:365) (doSendAndReceive) - failure occurred in gateway sendAndReceive: ; nested exception is org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed.; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available. Multiple causes:
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
See below for the stacktrace of the first cause.
DEBUG 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (AbstractHandlerExceptionResolver.java:134) (resolveException) - Resolving exception from handler [httpGatewayPost]: org.springframework.messaging.MessageHandlingException: ; nested exception is org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed.; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available. Multiple causes:
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
See below for the stacktrace of the first cause.
DEBUG 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (AbstractHandlerExceptionResolver.java:134) (resolveException) - Resolving exception from handler [httpGatewayPost]: org.springframework.messaging.MessageHandlingException: ; nested exception is org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed.; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available. Multiple causes:
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
See below for the stacktrace of the first cause.
TRACE 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (FrameworkServlet.java:1058) (resetContextHolders) - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@4106a123
DEBUG 2016-05-31 19:47:42,976 [http-bio-8088-exec-4] (FrameworkServlet.java:989) (processRequest) - Could not complete request
org.springframework.messaging.MessageHandlingException: ; nested exception is org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed.; nested exception is org.springframework.messaging.MessagingException: ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available. Multiple causes:
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
    ; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
See below for the stacktrace of the first cause.
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:78)
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:71)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:277)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:150)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42)
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:357)
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:328)
    at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.actualDoHandleRequest(HttpRequestHandlingEndpointSupport.java:492)
    at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:389)
    at org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:103)
    at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Mohan Seth
  • 761
  • 2
  • 11
  • 20
  • I can't make any sense of your logs without seeing all the configuration. – Gary Russell May 30 '16 at 13:40
  • Hi Gary, Due to characters limitation, I have uploaded the project on git following is the URL, Kindly have a look: https://github.com/Mckenzie1989/spring-integration – Mohan Seth May 31 '16 at 07:41

2 Answers2

0

I don't see how this is possible:

DEBUG 2016-05-29 23:31:35,681 [http-bio-8080-exec-3] (AbstractMessageChannel.java:383) (postSend) - postSend (sent=true) on channel 'outputChannel', message: GenericMessage [payload=HolidaysAvailableResponse [holidayCodes=[HolidayCode [code=NEW-YEARS-DAY-ACTUAL. . .(POJO), headers={content-type=application/json, id=da43d6d2-2618-8581-4fcc-6aff7e79b6e1, timestamp=1464544895681}]
...
TRACE 2016-05-29 23:31:35,807 [http-bio-8080-exec-3] (AbstractMessageChannel.java:426) (postReceive) - postReceive on channel 'outputChannel', message is null

Unless there's another thread (that's not logging) that's consuming from outputChannel or somehow there are two "outputChannel" beans - which should be impossible.

That said, this code is rather odd...

@ServiceActivator(inputChannel = "requestChannel")
public Message<?> echo(Message<String> message)
{
    // log.info("request :: " + message.getPayload());

    jsonToObjectTransformerChannel.send(message);
    // inputChannel.send(message);

    Message<?> responseMessage = outputChannel.receive(100);

    System.out.println("final response recieved :: ");
    System.out.println(responseMessage);

    return responseMessage;
}

It's not really intended to send and receive messages with a service activator like that (although it shouldn't cause any problems).

I'd be interested to know what happens if you get rid of outputChannel remove the output-channel from this

<header-enricher input-channel="headerEnricherChannel">
    <header name="content-type" value="application/json" />
</header-enricher>

And simply wiring the requestChannel directly to the Json to object transformer.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • On removing the output-channel I am getting an exception that I have updated in the question, kindly have a look, your help is much appreciated – Mohan Seth May 31 '16 at 14:30
  • 1
    Hmmm - you are losing the headers somewhere - if you are manipulating `Message>` objects in a transformer, you are responsible for copying the inbound headers to the outbound. To be honest, your application is difficult to unravel, with configuration in lots of files. I suggest you go back to your other approach and use a debugger to see what's happening in `outputChannel`. As I said, I can't see how a successful send can result in a null receive. – Gary Russell May 31 '16 at 14:45
0

Finally solved the issue, posting answer for some one in need, thanks to this question: Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

Was having DispatcherServlet as well as ContextLoaderListener in my application, due to which all beans were getting loaded twice and causing the issue, simply removed

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/dispatcher-servlet.xml
    </param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

from web.xml and now my application works like a charm.

Community
  • 1
  • 1
Mohan Seth
  • 761
  • 2
  • 11
  • 20