You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by nikosdim <ni...@gmail.com> on 2014/01/15 11:57:50 UTC

handleFault() method not called when exception occurs in handleMessage()

Hi

I have an inbound interceptor that performs some actions before invoking my
webservice. In my interceptor I call method from classes that I instantiate
on runtime with Class.forName(cls);

I am currently testing what happens when I give invalid class name in the
cls variable and I noticed that despite the fact that ClassNotFoundException
occurs (which I am catching) the method handleFault() is never called. 

Why is that happening? I've read that handleFault() is called when the
process in the handleMessage is interrupted but what this exactly means?
Isn't an Exception an interruption?

My code:

public class ESMAPISecurityInterceptor extends
		AbstractPhaseInterceptor<Message> {

	public ESMAPISecurityInterceptor(String phase) {
		super(phase);
	}

	@Override
	public void handleMessage(Message message) throws Fault {
		try {
			Class<?> c = Class.forName("an.invalid.class.name");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void handleFault(Message message) {
		System.out.println("Prints from handleFault()");
	}
}

Thanks



--
View this message in context: http://cxf.547215.n5.nabble.com/handleFault-method-not-called-when-exception-occurs-in-handleMessage-tp5738573.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: handleFault() method not called when exception occurs in handleMessage()

Posted by Daniel Kulp <dk...@apache.org>.
You are catching the Exception and then just printing a stack trace.  You aren’t then throwing something from your handleMessage.   The handleFault method is called if and exception /fault is thrown from the handleMessage method.  If nothing is thrown from there, CXF assumes everything has processed normally and continues.

Dan


On Jan 15, 2014, at 5:57 AM, nikosdim <ni...@gmail.com> wrote:

> Hi
> 
> I have an inbound interceptor that performs some actions before invoking my
> webservice. In my interceptor I call method from classes that I instantiate
> on runtime with Class.forName(cls);
> 
> I am currently testing what happens when I give invalid class name in the
> cls variable and I noticed that despite the fact that ClassNotFoundException
> occurs (which I am catching) the method handleFault() is never called. 
> 
> Why is that happening? I've read that handleFault() is called when the
> process in the handleMessage is interrupted but what this exactly means?
> Isn't an Exception an interruption?
> 
> My code:
> 
> public class ESMAPISecurityInterceptor extends
> 		AbstractPhaseInterceptor<Message> {
> 
> 	public ESMAPISecurityInterceptor(String phase) {
> 		super(phase);
> 	}
> 
> 	@Override
> 	public void handleMessage(Message message) throws Fault {
> 		try {
> 			Class<?> c = Class.forName("an.invalid.class.name");
> 		} catch (ClassNotFoundException e) {
> 			e.printStackTrace();
> 		}
> 	}
> 
> 	@Override
> 	public void handleFault(Message message) {
> 		System.out.println("Prints from handleFault()");
> 	}
> }
> 
> Thanks
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/handleFault-method-not-called-when-exception-occurs-in-handleMessage-tp5738573.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com