apache servicemix 中的异常处理

exception handling in apache servicemix

我是 ServiceMix 的新手,正在尝试在 ServiceMix 中进行异常处理。

当我尝试打印异常时,它还包含请求的正文。有什么方法可以只提取异常中的错误吗?

<from uri="activemq:topic://topic1"/>
            <!-- Schema validationm for the request received from Biblio -->
            <doTry>
                <to uri="validator:http://localhost/employee.xsd"/>
                <doCatch>                                           
                    <exception>java.lang.Exception</exception>  
                    <log message="${exception.message}"/>           
                </doCatch>                  
            </doTry>

下面是记录的异常:

org.apache.xerces.jaxp.validation.SimpleXMLSchema@a0059b5
errors: [
org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: 'asd' is not a valid value for 'integer'., Line : -1, Column : -1
org.xml.sax.SAXParseException: cvc-type.3.1.3: The value 'asd' of element 'empnumber' is not valid., Line : -1, Column : -1
]. Exchange[ID-GBSMIXDEV01-uk-oup-com-46713-1511957485149-83-2][Message: <empRecord>         
         <employee>
            <empnumber>asd</empnumber>            
            <surname>PM</surname>            
            <firstname>Abhinay</firstname>
         </employee>
      </empRecord>]

我得到了正确的异常,但我不希望异常中包含以下部分。

有什么方法可以从异常消息中删除这些内容吗?

Exchange[ID-GBSMIXDEV01-uk-oup-com-46713-1511957485149-83-2][Message: <empRecord>         
         <employee>
            <empnumber>asd</empnumber>            
            <surname>PM</surname>            
            <firstname>Abhinay</firstname>
         </employee>
      </empRecord>]

该消息来自异常,因此您可以在 Processor.

中操作字符串

写一个简单的class来做到这一点:

private static final Logger logger_ = LoggerFactory
        .getLogger(ExceptionMsgProcessor.class);

public void process(Exchange exchange) {
    Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
    String msg = e.getMessage();
    // manipulate the string here
    log.info("Exception message: {}", msg);
}

然后将异常发送给这个bean

<doTry>
    <to uri="validator:http://localhost/employee.xsd"/>
    <doCatch>                                           
        <exception>java.lang.Exception</exception>
        <to uri="bean:exceptionMsgProcessor" />
    </doCatch>                  
</doTry>