PDA

View Full Version : Exception/error handling queries



vikas_sm
Jan 31st, 2008, 12:27 PM
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

Mark Fisher
Jan 31st, 2008, 12:46 PM
Vikas,

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

Thanks,
Mark

vikas_sm
Jan 31st, 2008, 12:53 PM
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.


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

Mark Fisher
Jan 31st, 2008, 12:59 PM
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

Mark Fisher
Jan 31st, 2008, 01:21 PM
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/spring/docs/2.5.x/reference/jms.html#jms-destinations

Hope that helps,
Mark

vikas_sm
Jan 31st, 2008, 01:24 PM
Thanks for immediate repsonse.

I tried your changes. This works only if below line is not commented.

System.out.println(outputChannel.receive().getPayl oad());

Whenever i comment the above line, my error is not processed. Is it getting blocked for the outputChannel.
Please suggest.
Thanks/vikas

Mark Fisher
Jan 31st, 2008, 01:34 PM
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