Forum Home » Fuse Distributions » Fuse Services Framework

Thread: Exception handling spring

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Feb 22, 2011 4:09 AM Last Post By: ffang
nohaapav

Posts: 27
Registered: 01/06/11
Exception handling spring
Posted: Feb 21, 2011 4:02 PM
 
  Click to reply to this thread Reply
Hi guys is somehow possible to get exception message from this doTry-doCatch block ?

My scenario :

<route id="services">
<from ref="activemqProjectServicesTopic" />
<doTry>
<unmarshal>
<jaxb id="services" prettyPrint="true" contextPath="com.schemas.xxx/>
</unmarshal>
<doCatch>
<exception>org.xml.sax.SAXParseException</exception>
<log message="${exception.message}"/>
</doCatch>
</doTry>
<log message="===Service test==="/>
<to uri="bean:Login?method=loginCaller"/>
<to uri="bean:Service?method=init"/>
<log message="================="/>
</route>

Exception is catched but i don't know how to get the message from that.

i was trying to make my own exception which was call like bean but doesnt work and also use something like <log message="${exception.message}"/> which i found somewhere on camel pages but result is the same.

Thanks for any help.

Pavol
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Exception handling spring
Posted: Feb 21, 2011 4:24 PM   in response to: nohaapav in response to: nohaapav
 
  Click to reply to this thread Reply
The caught exception is stored as a property on the Exchange. You can grab it using exchange.getProperty(Exchange.EXCEPTION_CAUGHT);

Chapter 5 in the Camel book covers error handling very detailed. You may find information reading the Dead Letter Channel EIP
http://fusesource.com/docs/router/2.5/eip/index.html

Or scattered information at the Camel wiki pages
http://camel.apache.org/error-handling-in-camel.html

The EXCEPTION_CAUGHT works with bean binding, so just invoke a bean in the doCatch block and put a (Exception cause) in the method signature.
nohaapav

Posts: 27
Registered: 01/06/11
Re: Exception handling spring
Posted: Feb 21, 2011 4:36 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Now i tried to use something like :

<doCatch>
<exception>org.xml.sax.SAXParseException</exception>
<to uri="bean:SAXException?method=unsupportedXmlSchema"/>
</doCatch>

<bean id="SAXException" class="com.tieto.pmtools.planviewexceptions.UnsupportedXmlSchema"/>

public class UnsupportedXmlSchema extends Exception {

public final static Logger logger = LoggerFactory.getLogger(UnsupportedXmlSchema.class);

public void unsupportedXmlSchema(Exception ex) {
logger.info(ex.getCause().toString());
}
}

and works perfect so sorry for spam .. i'm a little bit overloaded seems to be :)) .. and thanks of course ..
ffang

Posts: 1,320
Registered: 12/24/07
Re: Exception handling spring
Posted: Feb 22, 2011 4:09 AM   in response to: nohaapav in response to: nohaapav
 
  Click to reply to this thread Reply
Hi Pavol,

Just one note,
If I understand correctly, this question is FUSE Mediation Router(Apache Camel) related only, but not FUSE Services Framework(Apache Cxf) related, would you please post such questions to correct forum category later on, it's better for track.

Thanks
Freeman