Throwing exceptions from actions
viniciuscarvalho Jan 7, 2008 1:18 PMHello there. At the programmers guide page 38 states that
"As mentioned earlier, a Fault Message may be returned
within an ActionProcessingFaultException",
but on at page 36
"Callback method for failure in each element: If an Exception
occurs then the exceptionMethod notification will be called on all
handlers from the current (faili ng) handler back to the initial handler.
At present time, if no exceptionMethod was specified, the only output
will be the logged error"
This led me to a very confusing idea of how to handle exceptions inside my action pipeline.
My first attempt was:
public Message process(Message message) throws ActionProcessingFaultException { XMLValidator validator = new XMLValidator("CSM.xsd"); Source xmlInput = new StreamSource(new StringReader(String.valueOf(message.getBody().get()))); boolean valid = validator.validate(xmlInput); if(!valid){ message.getBody().add(CSMConstants.BODY_ERROR_ENTRY,validator.getErrorList()); throw new ActionProcessingFaultException(message,"Erro de validacao do conteudo da mensagem"); } return message; }
But this, as said on page 36 of the manual, only prints an error:
15:11:33,137 WARN [ActionProcessingPipeline] Unexpected exception caught while processing the action pipeline: header: [ To: JMSEpr [ PortReference < <wsa:Address jms://localhost/queue/ESBChannel/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : 1/> > ] ReplyTo: JMSEpr [ PortReference < <wsa:Address jms://localhost/ESBChannel_reply/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : 1/> > ] FaultTo: JMSEpr [ PortReference < <wsa:Address jms://localhost/ESBFaultChannel/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : 1/> > ] MessageID: ID:JBM-33285 RelatesTo: jms:correlationID#ID:JBM-34816 ] org.jboss.soa.esb.actions.ActionProcessingFaultException: Erro de validacao do conteudo da mensagem at com.synos.csm.business.actions.CSMValidateAction.process(CSMValidateAction.java:33) 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:585) at org.jboss.soa.esb.listeners.message.ActionProcessorMethodInfo.processMethods(ActionProcessorMethodInfo.java:102) at org.jboss.soa.esb.listeners.message.OverriddenActionLifecycleProcessor.process(OverriddenActionLifecycleProcessor.java:74) at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:316) at org.jboss.soa.esb.listeners.message.MessageAwareListener$1.run(MessageAwareListener.java:303) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) at java.lang.Thread.run(Thread.java:595)
I was expecting it to be redirected to the FaultTo EPR. Sorry but I really did not understand the programmers guide, if the ESB will redirect to FaultTo EPR on an exception or not.
If it does not, what should be correct way to handle this?
Best regards