Announcement Announcement Module
Collapse
No announcement yet.
Issues with Service Activator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues with Service Activator

    I have established SI channels that send HTTP requests from a client to SI to a REST service and back through SI to the client. I would like the contents of the request to get sent off elsewhere to a service activator to do some unrelated auditing stuff. However, even though there are no exceptions and the logs look promising, I am not seeing any evidence of the service activator doing anything.

    Here is my configuration of the channels and endpoints:

    Code:
       <channel id="requestChannel">
            <interceptors>
                <wire-tap channel="auditChannel" />
            </interceptors>
        </channel>
    ...
       <channel id="auditChannel">
            <dispatcher task-executor="auditExecutor"/>
        </channel>
    ...
       <service-activator input-channel="auditChannel" ref="auditor" method="audit"/>
    Here is the activator:

    Code:
    @MessageEndpoint
    public class Auditor {
    
        @ServiceActivator
        public void audit(@Payload String payload,
                             @Header("header1") String header1,
                             @Header("header2") String header2) throws Exception {
            //Stuff
        }
    Finally, the logs:

    Code:
    18:40:31 DEBUG [o.s.i.c.ExecutorChannel.preSend] preSend on channel 'auditChannel', message: [Payload=[B@2ee73750][Headers={timestamp=1305744031561, id=4f2a6136-a82c-4d30-9a41-ea0c9781c620, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, content-type=application/json;charset=UTF-8, http_requestMethod=POST, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, accept=application/json, http_requestUrl=http://localhost:8080/myapp/documents/search}]
    18:40:31 DEBUG [o.s.i.c.ExecutorChannel.postSend] postSend (sent=true) on channel 'auditChannel', message: [Payload=[B@2ee73750][Headers={timestamp=1305744031561, id=4f2a6136-a82c-4d30-9a41-ea0c9781c620, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, content-type=application/json;charset=UTF-8, http_requestMethod=POST, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, accept=application/json, http_requestUrl=http://localhost:8080/myapp/documents/search}]
    18:40:31 DEBUG [o.s.i.h.ServiceActivatingHandler.handleMessage] ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@24c1f7dc] received message: [Payload=[B@2ee73750][Headers={timestamp=1305744031561, id=4f2a6136-a82c-4d30-9a41-ea0c9781c620, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, content-type=application/json;charset=UTF-8, http_requestMethod=POST, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@4de07d3e, accept=application/json, http_requestUrl=http://localhost:8080/myapp/documents/search}]
    There are two problems
    • The service activator isn't getting the message.
    • The custom headers "header1" and "header2," which are included as HTTP headers in the inbound request, aren't showing up in the logs of the messages.

    Any insight into where I have miscoded or misconfigured is appreciated.

    Thanks.

  • #2
    What about this:
    Code:
    18:40:31 DEBUG [o.s.i.h.ServiceActivatingHandler.handleMessage] ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProce

    Comment


    • #3
      I know...I saw that too. The thing is that I have some logging in that method that isn't happening. Also, the code in that method, which uses an API I didn't write, writes stuff to a JMS queue that isn't set up yet. Therefore, I expect an exception if the method actually is executed. I just ran things to see if everything is set up in my SI implementation correctly.

      So I am confused because the log says the ServiceActivator is handling the message but I have no evidence of it.

      Also, I am also unsure why those custom headers aren't showing up either.

      Thanks.

      Comment


      • #4
        Well, then look after the SA's log statement (you are not including it), because if headers could not be mapped then your POJO could not be invoked and you'd have an exception which since you are using async channel would go to the default 'errorChannel'.

        Comment


        • #5
          Here is the log right after the SA's log statement:

          Code:
          19:28:58 DEBUG [o.s.i.c.ExecutorChannel.postSend] postSend (sent=true) on channel 'auditChannel', message: [Payload=[B@57b33087][Headers={timestamp=1305746938753, id=4a8f63a7-6e0c-4ed7-8721-8b60cde5d38f, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@35371c0c, content-type=application/json;charset=UTF-8, http_requestMethod=POST, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@35371c0c, accept=application/json, http_requestUrl=http://localhost:8080/myapp/documents/search}]
          Then the rest are a bunch of logs for the "main" message path, which does work as expected. Here are some notable logs form that:

          Code:
          19:28:58 DEBUG [o.s.c.c.s.GenericConversionService.convert] Converting value 'header1' of java.lang.String to java.lang.String
          19:28:58 DEBUG [o.s.w.c.RestTemplate.createRequest] Created POST request for "http://localhost:8080/restservice/documents/search"
          19:28:58 DEBUG [o.s.c.c.s.GenericConversionService.convert] Converted to 'header1'
          So I guess this means that SI is seeing that header when generating the HTTP outbound call. However, I see no message on whether it gets mapped (it doesn't need to be as it is irrelevant to the main path).

          As for the errorChannel, I added the following configuration:

          Code:
          <service-activator input-channel="errorChannel" ref="errorPrinter" />
          and this code:

          Code:
          @MessageEndpoint
          public class ErrorPrinter {
          
              @ServiceActivator
              public void print(@Payload String payload)  {
                  org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
                  logger.debug("Found an error: " + payload);
              }
          }
          I don't see "Found an error:" anywhere.

          Sorry I can't provide more information. At least it is good to know I'm not missing something silly and obvious.

          Thanks.

          Comment


          • #6
            All that you show tells me that SA is getting executed and the fact that you don't see you log statement does not necessarily mean that its not being executed.May be there is an issue with you log configuration? May be temporary System.out.println or breakpoint would give you a better answer?

            Comment


            • #7
              I added a System.out.println and breakpoints in IntelliJ on the two service activators (the one I originally asked about and the error one) as well as a breakpoint on a class that executes the main path to generate the outbound HTTP request.

              I only hit the last breakpoint.

              So I am still wondering why SI is reporting success getting to the activator without the code actually executing.

              I appreciate your help with this puzzling issue. Please let me know if you have any other ideas.

              Thanks.

              Comment


              • #8
                I removed the temp and work directories from Tomcat, and I can now see the service activator taking action. I am having other issues, but those are for another thread. Thanks for your help, Oleg.

                Comment

                Working...
                X