Announcement Announcement Module
Collapse
No announcement yet.
Exception/error handling queries Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception/error handling queries

    Hi All,

    We are using spring integration in our project.
    Following are the observations which need some clarifications :-
    1)I have configured the errorchannel but i am not getting any exception/errors on the channel.I tried to throw an NPE(NullPointerException) in my endpoint class (HelloService).

    My Program waits and then terminates after some time.

    2)jms:listener never gives error if the destination queue is non-exisiting.

    Any information on this will be appreciated.

    Thank you
    Vikas

  • #2
    Vikas,

    Can you provide some excerpts from your configuration for each of these?

    Thanks,
    Mark

    Comment


    • #3
      Please find configuration/code excerpts below
      Error channel configurations



      <channel id="errorChannel" publish-subscribe="true" capacity="500"/>

      <endpoint input-channel="errorChannel"
      default-output-channel="outputChannel"
      handler-ref="helloService"
      handler-method="sayHello1"/>
      I have modified the sayHello method of HelloService to throw NPE.
      Code:
                   public String sayHello(String name) {
      		name= null;
      		System.out.println("Inside sayHello");
      		name.length();
      		return "Hello " + name;
      	}
      Listener configuration

      <jms:listener-container connection-factory="connectionFactoryWMQ">

      <jms:listener destination="test.client1.REPLY" ref="messageListener" />

      </jms:listener-container>
      Let me know if you need any other information.
      Thanks/Vikas

      Comment


      • #4
        Regarding #1, the endpoint in this case is receiving messages FROM the errorChannel. You might want to experiment with the following:

        1) create a new channel, e.g. "testChannel" - then change the input-channel of your helloService to be "testChannel".

        2) create a new endpoint that just logs to stderr and set its input-channel to be "errorChannel"

        3) send a StringMessage to "testChannel" - and then you should see the resulting NPE logged to stderr.

        Let me know if that helps. I'll follow up with the jms:listener in a separate message.

        -Mark

        Comment


        • #5
          Regarding #2 (JMS destination-name not failing), this is to be expected since Spring's DynamicDestinationResolver (the default implementation) will ultimately call 'session.createQueue(destinationName)' or 'session.createTopic(destinationName)'

          For more detail, read the 2nd paragraph of section 19.2.3 "Destintation Management" from the Spring reference documentation: http://static.springframework.org/sp...s-destinations

          Hope that helps,
          Mark

          Comment


          • #6
            Thanks for immediate repsonse.

            I tried your changes. This works only if below line is not commented.
            Code:
            System.out.println(outputChannel.receive().getPayload());
            Whenever i comment the above line, my error is not processed. Is it getting blocked for the outputChannel.
            Please suggest.
            Thanks/vikas

            Comment


            • #7
              Vikas,

              Yes, I see what you mean, and I'll try to explain what is happening here... Since the exception occurs in the endpoint's handler, no reply Message is being sent to the outputChannel. The receive() method without any timeout is a blocking call (it will wait forever - or until the thread is interrupted - for a Message on that channel). Rather than commenting it out, you can specify a timeout value there instead - in milliseconds (e.g. receive(3000))... then it will return null if the timeout elapses without any message being available. Also, keep in mind that the receive calls will usually be happening internally within the dispatcher (in a thread pool managed by the message bus). In other words, your code would not normally be calling the receive() method directly. In any case, using a timeout value is definitely recommended (and by the way, the default receiveTimeout for dispatchers is 1 second).

              -Mark

              Comment

              Working...
              X