Results 1 to 7 of 7

Thread: Exception/error handling queries

  1. #1
    Join Date
    Jan 2008
    Posts
    16

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Vikas,

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

    Thanks,
    Mark

  3. #3
    Join Date
    Jan 2008
    Posts
    16

    Default

    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

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  5. #5
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  6. #6
    Join Date
    Jan 2008
    Posts
    16

    Default

    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

  7. #7
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •