【问题标题】:Apache CXF Endpoint validation with Interceptor使用拦截器的 Apache CXF 端点验证
【发布时间】:2014-08-09 07:57:39
【问题描述】:

我想做什么:

在 CXF 端点中使用架构验证实现从 CXF EndpointJMS queueCamel route

在 CXF 端点中启用了验证:

/* Set endpoint properties */
Map<String, Object> propertiesMap = new HashMap<String, Object>();
propertiesMap.put("schema-validation-enabled", "true");

/* Create endpoint */
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setWsdlURL("wsdl/input.wsdl");
cxfEndpoint.setDataFormat(DataFormat.CXF_MESSAGE);
cxfEndpoint.setProperties(propertiesMap);
cxfEndpoint.getInInterceptors().add(new FaultInterceptor());

骆驼路线:

from(cxfEndpoint)
.routeId("INPUT_ROUTE")
.to("jms:foo.bar");

CXF 拦截器:

public class FaultInterceptor extends AbstractSoapInterceptor {

  private static final Logger LOGGER = Logger.getLogger(FaultInterceptor.class);

  public FaultInterceptor() {
    super(Phase.UNMARSHAL);
  }

  public void handleMessage(SoapMessage message) throws Fault {
    LOGGER.info("handleMessage=" + message.getExchange().getInMessage());    
  }

  @Override
  public void handleFault(SoapMessage message) {
    Fault fault = (Fault) message.getContent(Exception.class);
    LOGGER.info("handleFault='" + fault + "'");   
    /* Add some header property that says the message is invalid */  
  }

}

问题:

如果我发送有效的 SOAP 消息,则工作正常。如果我发送无效的 SOAP 消息,handleFault 方法就会启动,记录错误,仅此而已。 对于无效的 SOAP 消息场景,我是否可以使用 handleFault 方法记录故障并仍然将无效消息路由到 JMS 队列? 这是我添加到端点的唯一拦截器。

我正在使用:

  • Apache ServiceMix 5.0.0
  • Apache Camel 2.12.3
  • Apache CXF 2.7.10

【问题讨论】:

    标签: web-services cxf apache-camel interceptor


    【解决方案1】:

    您不能执行 try/catch 语句,因为错误发生在“from”子句中。

    但是,您可以使用Dead Letter Channel

    errorHandler(deadLetterChannel("jms:foo.bar.invalid"));
    
    from(cxfEndpoint)
     .routeId("INPUT_ROUTE")
     .to("jms:foo.bar");
    

    【讨论】:

    • 我已经添加了 errorHandler 但没有任何改变,我仍然在 Karaf Caused by: org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: 'go' is not a valid value for 'integer'. 中收到错误,并且没有消息路由到无效队列。
    猜你喜欢
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2016-12-08
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多