本文整理汇总了Java中org.apache.camel.Message.isFault方法的典型用法代码示例。如果您正苦于以下问题:Java Message.isFault方法的具体用法?Java Message.isFault怎么用?Java Message.isFault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.Message
的用法示例。
在下文中一共展示了Message.isFault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFault
import org.apache.camel.Message; //导入方法依赖的package包/类
/**
* Handles the fault message by converting it to an Exception
*/
protected void handleFault(Exchange exchange) {
// Take the fault message out before we keep on going
Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
if (msg.isFault()) {
final Object faultBody = msg.getBody();
if (faultBody != null && exchange.getException() == null) {
// remove fault as we are converting it to an exception
if (exchange.hasOut()) {
exchange.setOut(null);
} else {
exchange.setIn(null);
}
if (faultBody instanceof Throwable) {
exchange.setException((Throwable) faultBody);
} else {
// wrap it in an exception
String data = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, faultBody);
exchange.setException(new CamelException(data));
}
}
}
}
示例2: faultBodyExpression
import org.apache.camel.Message; //导入方法依赖的package包/类
/**
* Returns the expression for the fault messages body
*/
public static Expression faultBodyExpression() {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
return msg.isFault() ? msg.getBody() : null;
}
@Override
public String toString() {
return "faultBody";
}
};
}
示例3: hasFaultMessage
import org.apache.camel.Message; //导入方法依赖的package包/类
/**
* Tests whether the exchange has a fault message set and that its not null.
*
* @param exchange the exchange
* @return <tt>true</tt> if fault message exists
*/
public static boolean hasFaultMessage(Exchange exchange) {
Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
return msg.isFault() && msg.getBody() != null;
}