Catching exceptions twice in the actions pipeline.
fancn21th Jul 23, 2013 3:52 AMHi,
Our intention is that catching the exceptions in ESB End Point Web Service and response in specified format and content. After refering to the soution at https://community.jboss.org/message/622789#622789. I have tried myself and it works except that the error handler service will be invoked twice. Pls help on this.
P.S. MyAction3 is where exception thrown. MyAction is where the exception is captured and redirected by ServiceInvoker. MyAction2 is where the exception is processed and acutal response content generated. The log is at very below.
Runtime Env. JBoss ESB 4.11 JDK 1.7.0_25
- ESB
<?xml version="1.0"?>
<jbossesb parameterReloadSecs="5"
xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.1.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.1.xsd">
<providers>
<jms-provider connection-factory="XAConnectionFactory"
name="KripWebServicesMQ">
<jms-bus busid="KripWebServicesChannel">
<jms-message-filter dest-name="kripWebservices_Request_esb"
dest-type="QUEUE" transacted="true" />
</jms-bus>
</jms-provider>
</providers>
<services>
<service category="KripWebServices" description="Krip WebServices"
name="KripWebServicesTest" invmScope="GLOBAL">
<actions inXsd="BookServiceRequest.xsd" mep="RequestResponse"
outXsd="BookServiceResponse.xsd">
<action class="org.krip.soa.esb.webservices.MyAction" name="customaction">
<property name="exceptionMethod" value="processException" />
</action>
<action class="org.krip.soa.esb.webservices.MyAction3" name="customaction2">
<property name="exceptionMethod" value="processException" />
</action>
</actions>
</service>
<service category="KripWebServices" description="Krip WebServices"
name="KripWebServicesTest2" invmScope="GLOBAL">
<actions mep="RequestResponse">
<action class="org.krip.soa.esb.webservices.MyAction2" name="customaction" />
</actions>
</service>
</services>
</jbossesb>
- MyAction
public class MyAction extends AbstractActionLifecycle {
protected ConfigTree _config;
public MyAction(ConfigTree config) {
_config = config;
}
public Message process(Message message) throws Exception {
System.out.println("Common Process Starts &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ");
System.out.println("Body:" + message.getBody().get());
System.out.println("From: " + message.getHeader().getCall().getFrom());
System.out.println("To: " + message.getHeader().getCall().getTo());
System.out.println("MessageID: " + message.getHeader().getCall().getMessageID());
System.out.println("Action: " + message.getHeader().getCall().getAction());
System.out.println("FaultTo: " + message.getHeader().getCall().getFaultTo());
System.out.println("RelatesTo: " + message.getHeader().getCall().getRelatesTo());
System.out.println("ReplyTo: " + message.getHeader().getCall().getReplyTo());
System.out.println("Common Process Ends &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ");
System.out.println("About to cause an exception");
throw new ActionProcessingException("BAD STUFF HAPPENED");
}
public void processException(final Message message, final Throwable th) {
System.out.println("Something happened: " + th.getMessage());
try {
final ServiceInvoker invoker = new ServiceInvoker("KripWebServices", "KripWebServicesTest2") ;
invoker.deliverSync(message, 2000) ;
} catch (Exception e) {
e.printStackTrace();
}
}
}
- MyAction2
public class MyAction2 extends AbstractActionLifecycle {
protected ConfigTree _config;
public MyAction2(ConfigTree config) {
_config = config;
}
public Message process(Message message) throws Exception {
System.out.println("Exception Starts &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ");
System.out.println("Body:" + message.getBody().get());
System.out.println("From: " + message.getHeader().getCall().getFrom());
System.out.println("To: " + message.getHeader().getCall().getTo());
System.out.println("MessageID: " + message.getHeader().getCall().getMessageID());
System.out.println("Action: " + message.getHeader().getCall().getAction());
System.out.println("FaultTo: " + message.getHeader().getCall().getFaultTo());
System.out.println("RelatesTo: " + message.getHeader().getCall().getRelatesTo());
System.out.println("ReplyTo: " + message.getHeader().getCall().getReplyTo());
System.out.println("Exception Ends &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ");
StringBuffer resp = new StringBuffer();
resp.append("<get:getOrdersResponse xmlns:get=\"http://www.hp.com/krip/BookOrderData/getOrderRS\">");
resp.append("<get:responseStatus>FAILED</get:responseStatus>");
resp.append("<get:getMasterDataResponseError>");
resp.append("<get:errorCode>");
resp.append("9999</get:errorCode>");
resp.append("<get:errorMessage>Error</get:errorMessage>");
resp.append("</get:getMasterDataResponseError>");
resp.append("</get:getOrdersResponse>");
message.getBody().add(resp.toString());
return message;
}
}
- MyAction3
public class MyAction3 extends AbstractActionLifecycle {
protected ConfigTree _config;
public MyAction3(ConfigTree config) {
_config = config;
}
public Message process(Message message) throws Exception {
System.out.println("About to cause an exception");
throw new ActionProcessingException("BAD STUFF HAPPENED");
}
public void processException(final Message message, final Throwable th) {
}
}
- Log
15:32:10,231 INFO [STDOUT] Common Process Starts &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
15:32:10,232 INFO [STDOUT] Body:<chap:getAuthors xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:chap="http://chapter8.samples.esb.soa.jboss.org/" />
15:32:10,232 INFO [STDOUT] From: null
15:32:10,233 INFO [STDOUT] To: InVMEpr [ PortReference < <wsa:Address invm://4b72697057656253657276696365732424242424242424242424244b726970576562536572766963657354657374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ]
15:32:10,233 INFO [STDOUT] MessageID: e28b8da8-f696-4b06-9c06-ace449ef58ce
15:32:10,233 INFO [STDOUT] Action: null
15:32:10,233 INFO [STDOUT] FaultTo: null
15:32:10,233 INFO [STDOUT] RelatesTo: null
15:32:10,233 INFO [STDOUT] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-133-1/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ]
15:32:10,233 INFO [STDOUT] Common Process Ends &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
15:32:10,233 INFO [STDOUT] About to cause an exception
15:32:10,234 INFO [STDOUT] Something happened: BAD STUFF HAPPENED
15:32:10,243 INFO [STDOUT] Exception Starts &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
15:32:10,244 INFO [STDOUT] Body:<chap:getAuthors xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:chap="http://chapter8.samples.esb.soa.jboss.org/" />
15:32:10,244 INFO [STDOUT] From: null
15:32:10,244 INFO [STDOUT] To: InVMEpr [ PortReference < <wsa:Address invm://4b72697057656253657276696365732424242424242424242424244b72697057656253657276696365735465737432/false?false#10000/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ]
15:32:10,244 INFO [STDOUT] MessageID: e28b8da8-f696-4b06-9c06-ace449ef58ce
15:32:10,244 INFO [STDOUT] Action: null
15:32:10,244 INFO [STDOUT] FaultTo: null
15:32:10,244 INFO [STDOUT] RelatesTo: null
15:32:10,245 INFO [STDOUT] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-133-1/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ]
15:32:10,245 INFO [STDOUT] Exception Ends &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
15:32:12,243 INFO [ServiceInvoker] Unresponsive EPR: InVMEpr [ PortReference < <wsa:Address invm://4b72697057656253657276696365732424242424242424242424244b72697057656253657276696365735465737432/false?false#10000/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] for message: header: [ To: InVMEpr [ PortReference < <wsa:Address invm://4b72697057656253657276696365732424242424242424242424244b726970576562536572766963657354657374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-133-1/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ] MessageID: e28b8da8-f696-4b06-9c06-ace449ef58ce ]
15:32:12,256 INFO [STDOUT] Exception Starts &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
15:32:12,256 INFO [STDOUT] Body:<get:getOrdersResponse xmlns:get="http://www.hp.com/krip/BookOrderData/getOrderRS"><get:responseStatus>FAILED</get:responseStatus><get:getMasterDataResponseError><get:errorCode>9999</get:errorCode><get:errorMessage>Error</get:errorMessage></get:getMasterDataResponseError></get:getOrdersResponse>
15:32:12,256 INFO [STDOUT] From: null
15:32:12,256 INFO [STDOUT] To: InVMEpr [ PortReference < <wsa:Address invm://4b72697057656253657276696365732424242424242424242424244b72697057656253657276696365735465737432/false?false#10000/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ]
15:32:12,256 INFO [STDOUT] MessageID: e28b8da8-f696-4b06-9c06-ace449ef58ce
15:32:12,256 INFO [STDOUT] Action: null
15:32:12,257 INFO [STDOUT] FaultTo: null
15:32:12,257 INFO [STDOUT] RelatesTo: null
15:32:12,257 INFO [STDOUT] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-133-1/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/invm/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ]
15:32:12,257 INFO [STDOUT] Exception Ends &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&