1

想法是从文件系统读取edi文件并将其传输到XML。我尝试了从 smooks 下载的示例,它工作正常。但是当我开始使用来自 Camel 处理器的相同代码(和 edi 文件)时,我得到了一个空指针。

代码

public class MyRouteBuilder extends RouteBuilder
{
    @Override
    public void configure()
    {
        from("file://C:/Users/Owner/Desktop/BPMN").process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception
            {
                System.err.println("We just downloaded: " + exchange.getIn().getHeader("CamelFileName"));
                Locale defaultLocale = Locale.getDefault();
                Locale.setDefault(new Locale("en", "IE"));
                // Instantiate Smooks with the config...
                Smooks smooks = new Smooks("smooks-config.xml");
                // smooks.setReaderConfig(new
                // UNEdifactReaderConfigurator("urn:org.milyn.edi.unedifact:d03b-mapping:v1.4"));
                System.err.println("Loaded smooks cfg");
                try
                {
                    // Create an exec context - no profiles....
                    ExecutionContext executionContext = smooks.createExecutionContext();
                    System.err.println("created execution context");
                    DOMResult domResult = new DOMResult();

                    // Configure the execution context to generate a report...
                    // executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html"));

                    // Filter the input message to the outputWriter, using the execution context...
                    byte[] body = exchange.getIn().getBody(String.class).getBytes();
                    System.err.println("Retrieved the body " + new String(body));
                    smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(body)), domResult);
                    Locale.setDefault(defaultLocale);
                    System.err.println(domResult.getNode());
                    // System.err.println
                    System.err.println(XmlUtil.serialize(domResult.getNode().getChildNodes(), true));
                }
                finally
                {
                    smooks.close();
                }
            }
        }).to("file:C:/ws-juno");
    }
}

日志

[                      Thread-1] FakeFtpServer                  INFO  Starting the server on port 0
[                      Thread-1] FakeFtpServer                  INFO  Actual server port is 49852
[                          main] MainSupport                    INFO  Apache Camel 2.9.0 starting
[                          main] DefaultCamelContext            INFO  Apache Camel 2.9.0 (CamelContext: camel-1) is starting
[                          main] ManagementStrategyFactory      INFO  JMX enabled. Using ManagedManagementStrategy.
[                          main] ultManagementLifecycleStrategy INFO  StatisticsLevel at All so enabling load performance statistics
[                          main] AnnotationTypeConverterLoader  INFO  Found 3 packages with 15 @Converter classes to load
[                          main] DefaultTypeConverter           INFO  Loaded 168 core type converters (total 168 type converters)
[                          main] DefaultTypeConverter           INFO  Loaded additional 0 type converters (total 168 type converters) in 0.004 seconds
[                          main] rFileExclusiveReadLockStrategy WARN  Deleting orphaned lock file: C:\Users\Owner\Desktop\BPMN\input-message.edi.camelLock
[                          main] DefaultCamelContext            INFO  Route: route1 started and consuming from: Endpoint[file://C:/Users/Owner/Desktop/BPMN]
[                          main] DefaultCamelContext            INFO  Total 1 routes, of which 1 is started.
[                          main] DefaultCamelContext            INFO  Apache Camel 2.9.0 (CamelContext: camel-1) started in 4.508 seconds
We just downloaded: input-message.edi
Loaded smooks cfg
created execution context
Retrieved the body HDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006
CUS*user1*Harry^Fletcher*SD
ORD*1*1*364*The 40-Year-Old Virgin*29.98
ORD*2*1*299*Pulp Fiction*29.99

null
[://C:/Users/Owner/Desktop/BPMN] DefaultErrorHandler            ERROR Failed delivery for exchangeId: ID-Owner-PC-49853-1329098945139-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
java.lang.NullPointerException
    at com.xcg.routes.MyRouteBuilder$1.process(MyRouteBuilder.java:69)[file:/C:/ws-juno/routes/target/classes/:]
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:322)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:213)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:352)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:175)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:136)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:140)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[camel-core-2.9.0.jar:2.9.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)[:1.6.0_26]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)[:1.6.0_26]
    at java.lang.Thread.run(Unknown Source)[:1.6.0_26]
4

1 回答 1

1

为了他人的利益回答我自己的问题。

我发布的代码的问题是我(实际上骆驼默认只记录最外面的异常)正在吞下异常。一旦我发现异常并打印堆栈跟踪,我发现根本原因是 Smook 的 edi-message-mapping xml 中的映射不正确。

此外,Smooks 在 GAE (http://edi-to-xml.appspot.com/) 上有一个网站,允许您解析 edi 消息并将其转换为 xml。

于 2012-02-14T01:33:51.730 回答