-
1. Re: Catching exceptions in the actions pipeline.
joe_boy12 Aug 23, 2011 4:24 PM (in response to mlog)I have a proof of concept of doing that.... here are the steps.. add jms-provider in jboss-esb.xml (technicall you dont need it - but my server goes in infinite loop if I use InVm transport). Add a starting action in your service. Add another service which is responsible to send the customized response back to client. Add the Action class which does that. Reproduce the error and see if you get the <Error>..... response.
<providers>
<jms-provider name="JBossMessaging" connection-factory="XAConnectionFactory">
<jms-bus busid="ErrorBus">
<jms-message-filter dest-type="QUEUE" dest-name="queue/ErrorQueue" transacted="true"/>
</jms-bus>
</jms-provider>
</providers><service category="serviceCategory" name="serviceName" description="" invmScope="GLOBAL">
<actions mep="RequestResponse" inXsd="request.xsd" outXsd="response.xsd">
<!-- new addition starts here -->
<action name="startAction" class="my.action.ErrorHandlingAction" process="process"/>
<!-- new addition ends here -->
<action name="transform-request" class="org.jboss.soa.esb.smooks.SmooksAction">
<property name="smooksConfig" value="transform-request.xml"/>
<property name="resultType" value="JAVA"/>
</action>
<action name="call-business-method" class="business.method.caller"/>
<action name="transform-responce" class="org.jboss.soa.esb.smooks.SmooksAction">
<property name="smooksConfig" value="transform-response.xml"/>
</action>
</actions>
</service><service category="Utility" name="ServeErrorService" description="">
<listeners>
<jms-listener name="error-channel" busidref="ErrorBus"/>
</listeners>
<actions mep="RequestResponse">
<action name="myAction" class="my.action.ErrorHandlingAction" process="processErrors"/>
</actions>
</service>add this action to your source code.
package my.action;
public class ErrorHandlingAction {@Process
public Message process(Message message) throws Exception
{
return message;
}
@Process
public Message processErrors(Message message) throws Exception
{
StringBuffer buffer = new StringBuffer();
buffer.append("<Errors><Error code=\"9999\">");
buffer.append(((Throwable)message.getBody().get("exceptionTrace")).getMessage());
buffer.append("</Error></Errors>");
message.getBody().add(buffer.toString());
return message;
}@OnSuccess
public void processSuccess(Message message)
{
}
@OnException
public void processException(Message message, Throwable t) throws ActionProcessingException
{
if( message != null )
{
message.getBody().add("exceptionTrace",t);
try {
Service errorService = new Service("Utility", "ServeErrorService");
ServiceInvoker si = new ServiceInvoker(errorService);
si.deliverSync(message, 1000);
} catch (Exception e) {
e.printStackTrace();
throw new ActionProcessingException(e.getMessage(), e);
}
}
}}
-
2. Re: Catching exceptions in the actions pipeline.
h.wolffenbuttel Aug 24, 2011 3:59 AM (in response to joe_boy12)Hi Joe,
Does JBossESB do anything with the 'Error code="9999" ' ? Or is this your own preferred implementation of the returned answer?
Regards,
Hans
-
3. Re: Catching exceptions in the actions pipeline.
mlog Aug 24, 2011 7:35 AM (in response to joe_boy12)Hi, Joe.
Thank you very much for your reply. It works, and it is exactly what I need!
By the way, in my environment (JBossESB 4.9 on JBossAS 5.1.0.GA) it works fine with InVM transport too.
Thank you again.
-
4. Re: Catching exceptions in the actions pipeline.
joe_boy12 Aug 24, 2011 2:53 PM (in response to mlog)mlog - I have the same set up but the moment I use
<service category="Utility" name="ServeErrorService" description="" invmScope="GLOBAL"> and remove JMS queue - I still get the correct response but my server goes in infinite loop.
@Hans - No this is just a PoC I tried to send my customized reply in case of Synch calls over HttpGateways - there is still lot to do. The 9999 is just static error code I am using for PoC - nothing to do with JBoss specifications.
Please share if you guys have better idea to implement this stuff - I would really appreciate that.
Joe
-
5. Re: Catching exceptions in the actions pipeline.
dulee Sep 4, 2012 7:04 AM (in response to joe_boy12)Hi All,
I'm using jboss esb 4.10.
When an action threw exception, I see that the method processException does not work. ESB does not call this method.
Who has met this problem before, please help me.
Thanks,
-
6. Re: Catching exceptions in the actions pipeline.
joe_boy12 Sep 4, 2012 8:30 PM (in response to dulee)can you post your Action code and jboss-esb.xml snippet?
-
7. Re: Catching exceptions in the actions pipeline.
dulee Sep 4, 2012 10:56 PM (in response to joe_boy12)Dear joe_boy,
Here is my action class:
public class MyAction extends AbstractActionLifecycle {
public MyAction(Config config) {
///set config
}
public Message process(Message msg) {
throw new Exception("aaaaaa");
}
@OnException
public void handleError(Message msg, Throwable t) {
/handle exception
}
}
Jboss-esb.xml is similar to your file. But it has only 1 action.
<service category="cat" name="testErrorHandler" description="" invmScope="GLOBAL">
<listeners>
<jms-listener name="mychannel" busidref="testErrorBus"/>
</listeners>
<actions mep="RequestResponse">
<action name="startAction" class="my.Myaction" process="process"/>
</actions>
</service>
But the method handleError is not called
-
8. Re: Catching exceptions in the actions pipeline.
joe_boy12 Sep 10, 2012 8:29 PM (in response to dulee)try extending to AbstractActionPipelineProcessor and override
processException, or dont extend anything and just use annotations.