交换期间发生CamelExecutionException

时间:2019-04-02 15:27:10

标签: java apache-camel

我使用多播过滤重复项。 我创建了AggregationStrategy

package model;

import org.apache.camel.Exchange;
import org.apache.camel.processor.aggregate.AggregationStrategy;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;

public class CentersAggregationStrategy implements AggregationStrategy {

    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        try  {
            if (oldExchange != null)  {
                return null;
            }

            Centers centers;
            if (newExchange.getIn().getBody(Centers.class) != null)  {
                centers = newExchange.getIn().getBody(Centers.class);
            } else {
                centers = unemarshalCenters(newExchange.getIn().getBody(String.class));
            }
            newExchange.getIn().setBody(centers);
            return newExchange;
        } catch (JAXBException ex) {
            ex.printStackTrace();
            return newExchange;
        }
    }

    private Centers unemarshalCenters(String source) throws JAXBException {
        return (Centers) JAXBContext.newInstance(Centers.class)
                .createUnmarshaller().unmarshal(new StreamSource(new StringReader(source)));
    }
}

我在多播中使用它:

RouteBuilder routeBuilder = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:aggregate")
                        .setHeader(Exchange.HTTP_PATH, simple("animals"))
                        .multicast(new CentersAggregationStrategy())
                        .parallelProcessing()
                        .enrich(SERVICE_URL + FIRST_PORT)
                        .enrich(SERVICE_URL + SECOND_PORT)
                        .enrich(SERVICE_URL + THIRD_PORT)
                        .end()
                        .to("direct:aggregate-file");

                from("direct:aggregate-file")
                        .to("file:aggregate-output");

            }
        };

这是我的问题:当我尝试运行此代码时,它将引发此错误:

Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-inf-50-7-1554218530628-0-1]
    at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1846)
    at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:713)
    at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515)
    at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:168)
    at eip.AgregateProducerConsumer.main(AgregateProducerConsumer.java:61)
Caused by: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: aggregate-output/ID-inf-50-7-1554218530628-0-5
    at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:354)
    at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:305)
    at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:169)
    at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)

但是当我只用日志替换.to(“ direct:aggregate-file”)时,它就可以完美工作... 所以我正在寻找一种将结果写入文件的方法

0 个答案:

没有答案