骆驼春季DSL重新交付

时间:2020-02-21 16:13:24

标签: exception apache-camel

HI创建了一个简单的Camel Spring应用程序来使用XSL文件。 我的骆驼上下文文件如下所示,路由由InitProcessor,ExcelProcessor和FinalProcessor组成。 骆驼路线进展顺利,但是在最终处理器上,我调用了Web服务并获得了Soap Fault,然后骆驼永远重新传递有效载荷,为什么? 它与onException声明无关,也没有对我的自定义异常处理器(processorEx)的调用,为什么?

谢谢

camel-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:annotation-config/>
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:config/conf.properties</value>

            </list>
        </property>
    </bean>

    <camelContext id="camel"  trace="true" xmlns="http://camel.apache.org/schema/spring" >

        <onException>
                <exception>org.savino.hb.dataprovider.DataProviderException</exception>
            <!--
                <handled>
                    <constant>true</constant>
                </handled>
                -->
                <!--log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" /--> 
                <!--to uri="log:org.savino.hb.dataprovider?level=DEBUG"/-->
                <to uri="processorEx"/>
                <to uri="file:C:/Users/Administrator/Desktop/HB_DATA/mov_fail?fileName=${header.X_UID}"/>
                <process ref="processorEx"/>
            </onException>


        <route>
            <from uri="file:C:/Users/Administrator/Desktop/HB_DATA/mov?delay=1000&amp;move=../mov_done&amp;moveFailed=../mov_fail"/>
            <process ref="processor"/>
            <log message="Header: $simple{in.headers[X_FILENAME]}" loggingLevel="INFO" logName="header-test" />
             <to uri="log:com.mycompany.order?level=DEBUG"/>
            <choice>
                <when>
                    <simple>${in.header.X_CARD} == true</simple>
                    <to uri="bean:excelCard"/>
                </when>
                <otherwise>
                    <to uri="bean:excelMov"/>
                </otherwise>
            </choice>
            <to uri="bean:finalProcessor"/>

            <!--process ref="processor"/-->


        </route>

    </camelContext>
    <bean name="dataProcessor" class="org.savino.hb.dataprovider.ws.WSDataProcessor"/>
    <bean name="excelMov" class="org.savino.hb.dataprovider.ExcelTransformer">
        <constructor-arg index="0" value="9"/>
        <constructor-arg index="1" value="1"/>
        <constructor-arg index="2" value="2"/>
        <constructor-arg index="3" value="3"/>
        <constructor-arg index="4" value="4"/>
        <constructor-arg index="5" value="5"/>
        <constructor-arg index="6" value="6"/>
    </bean>
    <bean name="excelCard" class="org.savino.hb.dataprovider.ExcelTransformer">
        <constructor-arg index="0" value="8"/>
        <constructor-arg index="1" value="1"/>
        <constructor-arg index="2" value="2"/>
        <constructor-arg index="3" value="0"/>
        <constructor-arg index="4" value="6"/>
        <constructor-arg index="5" value="3"/>
        <constructor-arg index="6" value="0"/>
    </bean>
    <bean name="processor" class="org.savino.hb.dataprovider.Processor"/>
    <bean name="finalProcessor" class="org.savino.hb.dataprovider.FinalProcessor"/>
    <bean name="processorEx" class="org.savino.hb.dataprovider.ProcessorEx"/>

</beans>

当FinalProcessor异常时要执行的ProcessorEx

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.savino.hb.dataprovider;


import org.apache.camel.Exchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;




/**
 *
 * @author f.savino
 */
public class ProcessorEx implements org.apache.camel.Processor{
    private static final Logger logger =LoggerFactory.getLogger(ProcessorEx.class);

    @Override
    public void process(Exchange exchange) throws Exception {
        Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        String uid = exchange.getIn().getHeader("X_UID").toString();
        if (ex== null)
            logger.warn(uid+"::Exception NULL");
        else if (ex instanceof DataProviderException)
            logger.error(uid+"::"+ex.toString(),ex);
        else 
            logger.error(uid+"::Exception",ex);
    }

}

FinalProcessor

public class FinalProcessor implements org.apache.camel.Processor{

    @Autowired
    DataProcessor dataProcessor;

    @Override
    public void process(Exchange exchange) throws Exception {
        List<Item> m = (List<Item>) exchange.getIn().getBody();
        String cc = exchange.getIn().getHeader("X_CC").toString();
        String periodo = exchange.getIn().getHeader("X_PERIODO").toString();
        boolean card = Boolean.valueOf(exchange.getIn().getHeader("X_CARD").toString());
        DataContainer data = new DataContainer();

        data.setCc(cc);
        data.setCard(card);
        data.setPeriodo(periodo);
        data.setItems(m);

            ReplyContainer reply = dataProcessor.processMov(data);

    }

}

1 个答案:

答案 0 :(得分:0)

您可以尝试通过将onException块更新到下面来尝试捕获所有异常,而不是捕获该特定异常,

<onException redeliveryPolicyRef="myRedelivery">
    <exception>java.lang.Exception</exception>

,您可以将myRedelivery声明为

<redeliveryPolicyProfile id="myRedelivery" redeliveryDelay="{{redeliverydelayvalue}}" maximumRedeliveries="{{maxredeliveryvalue}}"/>