2012-02-13 5 views
1

파일 시스템에서 edi 파일을 읽고 XML로 전송하는 것이 좋습니다. 내가 smooks에서 다운로드 한 예제를 시도하고 잘 작동합니다. 그러나 Camel Processor에서 동일한 코드 (및 edi 파일)를 사용하기 시작할 때 nullpointer를 얻습니다.Camel에서 Smooks 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] 

답변

1

다른 사람의 이익을 위해 내 자신의 질문에 대답.

게시 된 코드의 문제점은 (실제로 낙타는 가장 바깥 쪽 예외 만 기록하는 것입니다)을 삼키는 입니다. 예외를 잡아서 스택 트레이스를 인쇄하면 Smook의 edi-message-mapping xml에서 잘못된 매핑이 근본 원인이라는 것을 알았습니다.

또한 Smooks에는 edi 메시지를 구문 분석하고 xml로 변환 할 수있는 GAE (http://edi-to-xml.appspot.com/)에서 사용할 수있는 웹 사이트가 있습니다.