You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Hongyu Zhang <ma...@hongyu.org> on 2012/01/13 02:27:10 UTC

Fw: Cannot catch the CXF exception

Hi there,



I am a newbie of CXF, and I just created a client using wsdl2java. It works fine until I started to test its exception feature. I shortened the timeout properties to extremely low (1 ms) to simulate the server time out scene. I did succeed in getting the timeout exception, but I couldn't catch the exception as exemplified in the code below

// start of code
try {
  myClient.queryServer(); // query web service
} catch (Exception e) {
  System.out.println("Caught exception"); // this has never been run so far for some reason
}
// end of code

In real life runs, my application always skips the catch section code completely. It did print out exception message to the standard output, something like:

WARNING: Interceptor for {http://mytestcom.com/}MyService#{http://mytesturl.com/}MyMethod has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
at $Proxy25.MyMethod(Unknown Source)
at com.mytestcom.service....myMethod(MyClient.java:69)
at MyTest.main(MyTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

It seems that the CXF library stores exception in a variable and didn't interrupt my code, and there was no exception to be caught by my own code.

My question is whether I can change this behavior to activate a real exception so my client code can handle it at my own will, e.g., displaying an elegant message to my user saying that the web server is too slow to respond.

Thanks!

Hongyu

Re: Fw: Cannot catch the CXF exception

Posted by bradyadams <j....@gmail.com>.
Hi all,

I am new to CXF, I need to handle the Timeout exception. I decreased the
timeout to 2 seconds and I am trying to handle the timeout exception.

First I was getting the fault message as below

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Could not send Message.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

I would need to add detail to it and I have added as below.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Could not send Message.</faultstring>
         <detail>
            <ns3:ServiceException xmlns:ns3="http://XXX/XXX">
               <messageId>SVC0001</messageId>
               <text>Server has timedout</text>
               <variables>ERR_0006</variables>
            </ns3:ServiceException>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

The above one I manipulated using the FaultOutInterceptor 

Element elementNs3 =
fault.getOrCreateDetail().getOwnerDocument().createElementNS("http://XXX/XXX",
"ns3:ServiceException");

        	Element messageElement =
fault.getDetail().getOwnerDocument().createElement("messageId");
        	messageElement.setTextContent("SVC0001");

        	Element textElement =
fault.getDetail().getOwnerDocument().createElement("text");
        	textElement.setTextContent("Server has timedout");

        	Element variableElement =
fault.getDetail().getOwnerDocument().createElement("variables");
        	variableElement.setTextContent("ERR_0006");

        
fault.getDetail().appendChild(elementNs3).appendChild(messageElement);
        	fault.getDetail().appendChild(elementNs3).appendChild(textElement);
        
fault.getDetail().appendChild(elementNs3).appendChild(variableElement);

But I need to add ns2 also in the xml as below (in bold) please can you help
me how to do that, or please can you let me know what is the standard way to
handle the Timeout exception I don't want to make the 0 (Zero) I need to
handle the exception and throw some meaningful message. Please can anyone
help me.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Could not send Message.</faultstring>
         <detail>
            <ns3:ServiceException xmlns:ns3="http://XXX/XXX"
<b>xmlns=ns2="http://YYY/YYY"*>
               <messageId>SVC0001</messageId>
               <text>Server has timedout</text>
               <variables>ERR_0006</variables>
            </ns3:ServiceException>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Thanks

Brady...



--
View this message in context: http://cxf.547215.n5.nabble.com/Fw-Cannot-catch-the-CXF-exception-tp5141485p5735811.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Cannot catch the CXF exception

Posted by Sven Zethelius <sv...@expedia.com>.
Note that timeout is handled different then an exception.  If memory serves, timeout is actually just a "return null", without even having an In Message having a Fault, unless something changed in 2.5.  The stack you have was probably generated after the client had already returned, so the conversion from Fault stored on the In Message back to a thrown exception never happened.

________________________________________
From: Hongyu Zhang [mail@hongyu.org]
Sent: Thursday, January 12, 2012 5:27 PM
To: users@cxf.apache.org
Subject: Fw: Cannot catch the CXF exception

Hi there,



I am a newbie of CXF, and I just created a client using wsdl2java. It works fine until I started to test its exception feature. I shortened the timeout properties to extremely low (1 ms) to simulate the server time out scene. I did succeed in getting the timeout exception, but I couldn't catch the exception as exemplified in the code below

// start of code
try {
  myClient.queryServer(); // query web service
} catch (Exception e) {
  System.out.println("Caught exception"); // this has never been run so far for some reason
}
// end of code

In real life runs, my application always skips the catch section code completely. It did print out exception message to the standard output, something like:

WARNING: Interceptor for {http://mytestcom.com/}MyService#{http://mytesturl.com/}MyMethod has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
at $Proxy25.MyMethod(Unknown Source)
at com.mytestcom.service....myMethod(MyClient.java:69)
at MyTest.main(MyTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

It seems that the CXF library stores exception in a variable and didn't interrupt my code, and there was no exception to be caught by my own code.

My question is whether I can change this behavior to activate a real exception so my client code can handle it at my own will, e.g., displaying an elegant message to my user saying that the web server is too slow to respond.

Thanks!

Hongyu

Re: Fw: Cannot catch the CXF exception

Posted by Hongyu Zhang <ma...@hongyu.org>.
Thanks, Daniel.

I realized what's was wrong now. CXF indeed throw an WebServiceException, which my code correctly caught and processed. But then, CXF still printed out the strack trace even though my exception handling code didn't intend to print anything. It somehow confused me to think that the exception was not caught by my code at all. 

Anyway, the main culprit to my confusion is the fact that the logging of CXF is separated from its exception handling.



________________________________
 From: Daniel Kulp <dk...@apache.org>
To: users@cxf.apache.org 
Cc: Hongyu Zhang <ma...@hongyu.org> 
Sent: Friday, January 13, 2012 8:46 AM
Subject: Re: Fw: Cannot catch the CXF exception
 

That should definitely be throwing an exception.   Any chance you can create a 
small testcase?   What version of CXF?   Also, what is the "caused by" 
exception?

Dan



On Thursday, January 12, 2012 5:27:10 PM Hongyu Zhang wrote:
> Hi there,
> 
> 
> 
> I am a newbie of CXF, and I just created a client using wsdl2java. It works
> fine until I started to test its exception feature. I shortened the timeout
> properties to extremely low (1 ms) to simulate the server time out scene. I
> did succeed in getting the timeout exception, but I couldn't catch the
> exception as exemplified in the code below
> 
> // start of code
> try {
>   myClient.queryServer(); // query web service
> } catch (Exception e) {
>   System.out.println("Caught exception"); // this has never been run so far
> for some reason }
> // end of code
> 
> In real life runs, my application always skips the catch section code
> completely. It did print out exception message to the standard output,
> something like:
> 
> WARNING: Interceptor for
> {http://mytestcom.com/}MyService#{http://mytesturl.com/}MyMethod has thrown
> exception, unwinding now org.apache.cxf.interceptor.Fault: Could not send
> Message.
> at
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInte
> rceptor.handleMessage(MessageSenderInterceptor.java:64) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:263) at
> org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
> at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
> at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
> at $Proxy25.MyMethod(Unknown Source)
> at com.mytestcom.service....myMethod(MyClient.java:69)
> at MyTest.main(MyTest.java:16)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
> 9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
> l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> 
> It seems that the CXF library stores exception in a variable and didn't
> interrupt my code, and there was no exception to be caught by my own code.
> 
> My question is whether I can change this behavior to activate a real
> exception so my client code can handle it at my own will, e.g., displaying
> an elegant message to my user saying that the web server is too slow to
> respond.
> 
> Thanks!
> 
> Hongyu
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Re: Fw: Cannot catch the CXF exception

Posted by Daniel Kulp <dk...@apache.org>.
That should definitely be throwing an exception.   Any chance you can create a 
small testcase?   What version of CXF?   Also, what is the "caused by" 
exception?

Dan



On Thursday, January 12, 2012 5:27:10 PM Hongyu Zhang wrote:
> Hi there,
> 
> 
> 
> I am a newbie of CXF, and I just created a client using wsdl2java. It works
> fine until I started to test its exception feature. I shortened the timeout
> properties to extremely low (1 ms) to simulate the server time out scene. I
> did succeed in getting the timeout exception, but I couldn't catch the
> exception as exemplified in the code below
> 
> // start of code
> try {
>   myClient.queryServer(); // query web service
> } catch (Exception e) {
>   System.out.println("Caught exception"); // this has never been run so far
> for some reason }
> // end of code
> 
> In real life runs, my application always skips the catch section code
> completely. It did print out exception message to the standard output,
> something like:
> 
> WARNING: Interceptor for
> {http://mytestcom.com/}MyService#{http://mytesturl.com/}MyMethod has thrown
> exception, unwinding now org.apache.cxf.interceptor.Fault: Could not send
> Message.
> at
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInte
> rceptor.handleMessage(MessageSenderInterceptor.java:64) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:263) at
> org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
> at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
> at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
> at $Proxy25.MyMethod(Unknown Source)
> at com.mytestcom.service....myMethod(MyClient.java:69)
> at MyTest.main(MyTest.java:16)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
> 9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
> l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> 
> It seems that the CXF library stores exception in a variable and didn't
> interrupt my code, and there was no exception to be caught by my own code.
> 
> My question is whether I can change this behavior to activate a real
> exception so my client code can handle it at my own will, e.g., displaying
> an elegant message to my user saying that the web server is too slow to
> respond.
> 
> Thanks!
> 
> Hongyu
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com