Can I create a servicemix-bean component and write something like this in the
xbean.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
xmlns:esb="http://esbinaction.com/errorhandling">
<bean:endpoint service="esb:errorComponent"
endpoint="errorEndpoint"
bean="#errorBean"/>
<bean id="errorBean" class="errorhandling.ExceptionListenerService"
/>
</beans>
Then the code that you have written can I use like this. I am not sure about
configuring your code like this, that is putting it in a bean. would it work
if I write something like this. Here the code I have copied from yours only
but I am not sure where to put it.
package errorhandling;
import javax.jbi.messaging.MessageExchange;
import org.apache.servicemix.jbi.event.ExchangeEvent;
import org.apache.servicemix.jbi.event.ExchangeListener;
/**
* An [EMAIL PROTECTED] org.apache.servicemix.jbi.event.ExchangeListener}
implementation
* to handle exception customization.
*
* @org.apache.xbean.XBean element="exceptionListenerService"
* @version $Revision$
* @author bsnyder
*/
public class ExceptionListenerService implements ExchangeListener {
public void exchangeAccepted(ExchangeEvent event) {
// TODO Auto-generated method stub
}
public void exchangeSent(ExchangeEvent event) {
MessageExchange me = event.getExchange();
Exception exception = null;
if (me.getError() != null) {
exception = analyzeException(me);
}
me.setError(exception);
}
/**
* This method abstracts any special exception handling behavior.
*
* @TODO Abstract this further using pluggable strategies to hold the
* custom functionality. Then we just stuff the strategies that are
* named in the servicemix.xml config into an array and just walk the
* array, invoking the execute method on each strategy.
*
* @param error The exception that was thrown
* @param endpointName The name of the endpoint that threw the exception
* @return
*/
private Exception analyzeException(MessageExchange me) {
Exception error = me.getError();
String serviceName = me.getEndpoint().getServiceName().toString();
String endpointName = me.getEndpoint().getEndpointName();
String errorMessage = error.getMessage();
// Add calls to custom processing here
StringBuilder newErrorMessage =
new StringBuilder("The following error was caused by service:
[");
newErrorMessage.append(serviceName != null ? serviceName : "null");
newErrorMessage.append("] and endpoint: [");
newErrorMessage.append(endpointName != null ? endpointName :
"null");
newErrorMessage.append("] ");
newErrorMessage.append("Original error: ");
newErrorMessage.append(errorMessage);
return new Exception(newErrorMessage.toString(), error);
}
}
I don't use servicemix.xml file to start my application on bus. I create a
zip file of application and put it inside SMX-HOME/hotdeploy. Please........
Help me to use your solution.
Thanks,
Pratibha
--
View this message in context:
http://www.nabble.com/Does-Servicemix-provides-any-error-handling-mechanism--tp17271816p17356960.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.