You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Florian Rosenberg <fl...@infosys.tuwien.ac.at> on 2008/04/09 11:14:18 UTC

interceptors and faults

hi all,

I'm writing a automated system for monitoring certain quality of service 
properties (e.g., response time, etc) from a client-side perspective. 
this works quite well as long as no fault occur on the service provider 
that i'm trying to invoke. I use a couple of interceptors in the IN and 
OUT chains to achieve it.

in case of a fault that occurs on the server, I need to be aware of this 
fault at the client side (e.g., I need to log the fault message etc into 
a database).

the problem I'm struggling with it the following: if a fault occurs on 
the server my incoming interceptor chain at the client side is not 
processed to the latest phase where I have my interceptor that stores 
all the stuff into the database. the interceptor chain stops after the 
READ phase on my client (thats what I could see in the debugger).

I've experimented a bit with a simple interceptor that just dumps a 
message to the console upon calling handleMessage() and handleFault(). 
I've added to every phase in the IN and FAULT chain, nevertheless 
handleFault() is never called upon receiving a fault message from the 
server.

could someone please clarify how faults from the server can be handled 
in the client-side interceptor chains (i'm using cxf v2.05)?

thanks,
-Florian


Re: interceptors and faults

Posted by Florian Rosenberg <fl...@infosys.tuwien.ac.at>.
Florian Rosenberg wrote:
>[...]
> 
> public static void main(String[] args) {
>   ClientProxyFactoryBean factory = new JaxWsProxyFactoryBean();
>   factory.setAddress("http://localhost:10000/ErrorService");
>   factory.setServiceClass(ErrorService.class);
>   ErrorService ess = (ErrorService)factory.create();
>        
>   Client c = ClientProxy.getClient(ess);
>   List<Interceptor> infault =  c.getInFaultInterceptors();
>   infault.add(new SimpleInterceptor(Phase.RECEIVE));
>   infault.add(new SimpleInterceptor(Phase.PRE_STREAM));
>   infault.add(new SimpleInterceptor(Phase.PRE_PROTOCOL));
>   infault.add(new SimpleInterceptor(Phase.UNMARSHAL));
>   infault.add(new SimpleInterceptor(Phase.PRE_LOGICAL));
>   infault.add(new SimpleInterceptor(Phase.PRE_INVOKE));
>        
>   List<Interceptor> in  = c.getInInterceptors();
>   in.add(new SimpleInterceptor(Phase.RECEIVE));
>   in.add(new SimpleInterceptor(Phase.PRE_STREAM));
>   in.add(new SimpleInterceptor(Phase.PRE_PROTOCOL));
>   in.add(new SimpleInterceptor(Phase.UNMARSHAL));
>   in.add(new SimpleInterceptor(Phase.PRE_LOGICAL));
>   in.add(new SimpleInterceptor(Phase.PRE_INVOKE));
>        
>   try {
>    ess.buggyOperation("something wrong");
>   } catch (DummyException_Exception e) {
>     e.printStackTrace();
>   }
> }


found the problem, very subtile: you need to invoke 
factory.getClientFactoryBean().get[In|Out|InFault|OutFault]Interceptors();
on the client factory bean not directly on the factory, then it works.

Is this desired behavior? Besides that, I still do not really unterstand 
when handleFault() is called in an interceptor and what are the 
consequences....

Thanks,
-Florian




Re: interceptors and faults

Posted by Florian Rosenberg <fl...@infosys.tuwien.ac.at>.
Daniel Kulp wrote:
> On Wednesday 09 April 2008, Florian Rosenberg wrote:
>> hi glen,
>>
>> Glen Mazza wrote:
>>> Server faults go into separate interceptor chains (second paragraph
>>> of [1])--I have not done this before, but you should be able to
>>> reuse the interceptors you have on your normal non-error chains for
>>> the error situations.
>> so you mean the FAULT chain? i've added my interceptor everywhere but
>> AFAIR the fault chain interceptors are not invoked and all
>> interceptors in the IN chain stop after the READ phase (in case of the
>> server fault)
> 
> This is slightly changing in 2.0.6/2.1 as it may go a little bit furthur 
> into the IN chain, but it won't go all the way.   Basically, when a 
> message comes in, it starts out on the IN chain.   At some point along 
> the chain (always was in the ReadHeadersInterceptor in 2.0.5, but will 
> be furthur along in 2.0.6/2.1 in order to get ws-security to fully 
> digest the whole body), it checks if the soap:body child is a 
> soap:fault.  If so, it stops the In chain and re-dispatches on the IN 
> FAULT chain.   Keep in mind, there are two fault chains.   There is an 
> OUT fault chain on the server and an IN fault chain on the client.  Make 
> sure you add to the right chain.

As I said, I've added my DummyInterceptor to every phase in every chain 
(IN, OUT, IN-FAULT, OUT-FAULT) but a service side exception does not go 
further than the IN_READ phase (where the handleMessage methods is 
invoked) then it stops processing the chains and I see an error from my 
JaxWsProxyFactoryBean in the client.

Any advise why the fault chain is not invoked? Below you find an sample 
main method that invokes an ErrorService with a buggyOperation() that 
always throws a custom exception (DummyException) and its output. The 
SimpleInterceptor just dumps each invocation of "handleMessage" and 
"handleFault" to the console.

I don't understand why the fault chain is never invoked in this case.
Any advise would be helpful how to configure/code this stuff correctly. 
I'm using the CXF 2.1 SNAPSHOT

-Florian


public static void main(String[] args) {
   ClientProxyFactoryBean factory = new JaxWsProxyFactoryBean();
   factory.setAddress("http://localhost:10000/ErrorService");
   factory.setServiceClass(ErrorService.class);
   ErrorService ess = (ErrorService)factory.create();
		
   Client c = ClientProxy.getClient(ess);
   List<Interceptor> infault =  c.getInFaultInterceptors();
   infault.add(new SimpleInterceptor(Phase.RECEIVE));
   infault.add(new SimpleInterceptor(Phase.PRE_STREAM));
   infault.add(new SimpleInterceptor(Phase.PRE_PROTOCOL));
   infault.add(new SimpleInterceptor(Phase.UNMARSHAL));
   infault.add(new SimpleInterceptor(Phase.PRE_LOGICAL));
   infault.add(new SimpleInterceptor(Phase.PRE_INVOKE));
		
   List<Interceptor> in  = c.getInInterceptors();
   in.add(new SimpleInterceptor(Phase.RECEIVE));
   in.add(new SimpleInterceptor(Phase.PRE_STREAM));
   in.add(new SimpleInterceptor(Phase.PRE_PROTOCOL));
   in.add(new SimpleInterceptor(Phase.UNMARSHAL));
   in.add(new SimpleInterceptor(Phase.PRE_LOGICAL));
   in.add(new SimpleInterceptor(Phase.PRE_INVOKE));
		
   try {
    ess.buggyOperation("something wrong");
   } catch (DummyException_Exception e) {
     e.printStackTrace();
   }
}

Output:
----------------------------------
Apr 16, 2008 2:17:31 PM org.apache.cxf.bus.spring.BusApplicationContext 
getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
Apr 16, 2008 2:17:32 PM 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean 
buildServiceFromClass
INFO: Creating Service {http://services.quatsch/}ErrorServiceService 
from class quatsch.services.ErrorService
SimpleInterceptor::handleMessage() invoked in phase 'receive' invoked
SimpleInterceptor::handleMessage() invoked in phase 'pre-stream' invoked
SimpleInterceptor::handleMessage() invoked in phase 'pre-protocol' invoked
quatsch.services.DummyException_Exception: Error occured: something wrong
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:184)
	at $Proxy37.buggyOperation(Unknown Source)
	at cxf.test.ErrorServiceClient.main(ErrorServiceClient.java:41)

Re: interceptors and faults

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 09 April 2008, Florian Rosenberg wrote:
> hi glen,
>
> Glen Mazza wrote:
> > Server faults go into separate interceptor chains (second paragraph
> > of [1])--I have not done this before, but you should be able to
> > reuse the interceptors you have on your normal non-error chains for
> > the error situations.
>
> so you mean the FAULT chain? i've added my interceptor everywhere but
> AFAIR the fault chain interceptors are not invoked and all
> interceptors in the IN chain stop after the READ phase (in case of the
> server fault)

This is slightly changing in 2.0.6/2.1 as it may go a little bit furthur 
into the IN chain, but it won't go all the way.   Basically, when a 
message comes in, it starts out on the IN chain.   At some point along 
the chain (always was in the ReadHeadersInterceptor in 2.0.5, but will 
be furthur along in 2.0.6/2.1 in order to get ws-security to fully 
digest the whole body), it checks if the soap:body child is a 
soap:fault.  If so, it stops the In chain and re-dispatches on the IN 
FAULT chain.   Keep in mind, there are two fault chains.   There is an 
OUT fault chain on the server and an IN fault chain on the client.  Make 
sure you add to the right chain.

Dan



>
> -Florian
>
> > [1] http://cwiki.apache.org/CXF20DOC/interceptors.html
> >
> > Am Mittwoch, den 09.04.2008, 11:14 +0200 schrieb Florian Rosenberg:
> >> hi all,
> >>
> >> I'm writing a automated system for monitoring certain quality of
> >> service properties (e.g., response time, etc) from a client-side
> >> perspective. this works quite well as long as no fault occur on the
> >> service provider that i'm trying to invoke. I use a couple of
> >> interceptors in the IN and OUT chains to achieve it.
> >>
> >> in case of a fault that occurs on the server, I need to be aware of
> >> this fault at the client side (e.g., I need to log the fault
> >> message etc into a database).
> >>
> >> the problem I'm struggling with it the following: if a fault occurs
> >> on the server my incoming interceptor chain at the client side is
> >> not processed to the latest phase where I have my interceptor that
> >> stores all the stuff into the database. the interceptor chain stops
> >> after the READ phase on my client (thats what I could see in the
> >> debugger).
> >>
> >> I've experimented a bit with a simple interceptor that just dumps a
> >> message to the console upon calling handleMessage() and
> >> handleFault(). I've added to every phase in the IN and FAULT chain,
> >> nevertheless handleFault() is never called upon receiving a fault
> >> message from the server.
> >>
> >> could someone please clarify how faults from the server can be
> >> handled in the client-side interceptor chains (i'm using cxf
> >> v2.05)?
> >>
> >> thanks,
> >> -Florian



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: interceptors and faults

Posted by Florian Rosenberg <fl...@infosys.tuwien.ac.at>.
hi glen,

Glen Mazza wrote:
> Server faults go into separate interceptor chains (second paragraph of
> [1])--I have not done this before, but you should be able to reuse the
> interceptors you have on your normal non-error chains for the error
> situations.

so you mean the FAULT chain? i've added my interceptor everywhere but 
AFAIR the fault chain interceptors are not invoked and all interceptors 
in the IN chain stop after the READ phase (in case of the server fault)

-Florian

> [1] http://cwiki.apache.org/CXF20DOC/interceptors.html

> Am Mittwoch, den 09.04.2008, 11:14 +0200 schrieb Florian Rosenberg:
>> hi all,
>>
>> I'm writing a automated system for monitoring certain quality of service 
>> properties (e.g., response time, etc) from a client-side perspective. 
>> this works quite well as long as no fault occur on the service provider 
>> that i'm trying to invoke. I use a couple of interceptors in the IN and 
>> OUT chains to achieve it.
>>
>> in case of a fault that occurs on the server, I need to be aware of this 
>> fault at the client side (e.g., I need to log the fault message etc into 
>> a database).
>>
>> the problem I'm struggling with it the following: if a fault occurs on 
>> the server my incoming interceptor chain at the client side is not 
>> processed to the latest phase where I have my interceptor that stores 
>> all the stuff into the database. the interceptor chain stops after the 
>> READ phase on my client (thats what I could see in the debugger).
>>
>> I've experimented a bit with a simple interceptor that just dumps a 
>> message to the console upon calling handleMessage() and handleFault(). 
>> I've added to every phase in the IN and FAULT chain, nevertheless 
>> handleFault() is never called upon receiving a fault message from the 
>> server.
>>
>> could someone please clarify how faults from the server can be handled 
>> in the client-side interceptor chains (i'm using cxf v2.05)?
>>
>> thanks,
>> -Florian
>>


-- 
Florian Rosenberg
Research Assistant
Distributed Systems Group
Technical University Vienna, Austria
tel: +43 1 58801 18418
fax: +43 1 58801 18491
www.florianrosenberg.com

"keep in mind that my knowledge of the issues is very limited, 
fragmented and quite possibly completely wrong"  A.S.

Re: interceptors and faults

Posted by Glen Mazza <gl...@verizon.net>.
Server faults go into separate interceptor chains (second paragraph of
[1])--I have not done this before, but you should be able to reuse the
interceptors you have on your normal non-error chains for the error
situations.

HTH,
Glen

[1] http://cwiki.apache.org/CXF20DOC/interceptors.html


Am Mittwoch, den 09.04.2008, 11:14 +0200 schrieb Florian Rosenberg:
> hi all,
> 
> I'm writing a automated system for monitoring certain quality of service 
> properties (e.g., response time, etc) from a client-side perspective. 
> this works quite well as long as no fault occur on the service provider 
> that i'm trying to invoke. I use a couple of interceptors in the IN and 
> OUT chains to achieve it.
> 
> in case of a fault that occurs on the server, I need to be aware of this 
> fault at the client side (e.g., I need to log the fault message etc into 
> a database).
> 
> the problem I'm struggling with it the following: if a fault occurs on 
> the server my incoming interceptor chain at the client side is not 
> processed to the latest phase where I have my interceptor that stores 
> all the stuff into the database. the interceptor chain stops after the 
> READ phase on my client (thats what I could see in the debugger).
> 
> I've experimented a bit with a simple interceptor that just dumps a 
> message to the console upon calling handleMessage() and handleFault(). 
> I've added to every phase in the IN and FAULT chain, nevertheless 
> handleFault() is never called upon receiving a fault message from the 
> server.
> 
> could someone please clarify how faults from the server can be handled 
> in the client-side interceptor chains (i'm using cxf v2.05)?
> 
> thanks,
> -Florian
>