1

アイデアは、ファイル システムから edi ファイルを読み取り、それを XML に転送することです。smooks からダウンロードしたサンプルを試してみましたが、うまくいきました。しかし、Camel Processor から同じコード (および edi ファイル) を使用し始めると、nullpointer が発生します。

コード

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/) で利用できる Web サイトがあり、edi メッセージを解析して xml に変換できます。

于 2012-02-14T01:33:51.730 に答える