title: Problems with smooks
body: <p>I am currently evaluating smooks (www.smooks.org). It looks just like what we need but I am having problems getting a simple example to work.</p>
  
  <p>I've got an ant script which downloads me all the dependencies including the mapping and binding jars for EDIFACT messages.</p>
  
  <p>I am trying to convert a simple EDIFACT APERAK message to Java using their EJC (I am using JavaSE for this little test).
  The conversion fails with an exception that some block wasn't expected (see below). So I am wondering whether I am missing some configuration (notice the first few lines in the log output).</p>
  
  <p>Has anyone worked with Smooks' EJC? How can I get more info about what line it is complaining?</p>
  
  <p>So this is the code:</p>
  
  <pre><code>    D00BInterchangeFactory factory = D00BInterchangeFactory.getInstance();
      File file = new File("aperak.edi");
      BufferedInputStream ediSource = new BufferedInputStream(new FileInputStream(file));
      StreamResult xmlStream = new StreamResult();
      StringWriter xmlWriter = new StringWriter();
      xmlStream.setWriter(xmlWriter);
      UNEdifactInterchange interchange = factory.fromUNEdifact(ediSource);
      //System.err.println("MEssage "+xmlWriter.toString());
      if(interchange instanceof UNEdifactInterchange41){
          UNEdifactInterchange41 interchange41 = (UNEdifactInterchange41)interchange;
          for(UNEdifactMessage41 message: interchange41.getMessages()){
          Object messageObj = message.getMessage();
              System.err.println("Ref Num "+message.getMessageHeader().getMessageRefNum());
          if(messageObj instanceof Aperak){
              Aperak aperak = (Aperak)message.getMessage();
              System.err.println("Aperak "+aperak);
              }
          }
      }
  </code></pre>
  
  <p>When I run it I get this exception</p>
  
  <pre><code>02-Nov-2011 15:58:09 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
  WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
  02-Nov-2011 15:58:10 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
  WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
  Exception in thread "main" org.milyn.SmooksException: Failed to filter source.
      at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
      at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:61)
      at org.milyn.Smooks._filter(Smooks.java:516)
      at org.milyn.Smooks.filterSource(Smooks.java:475)
      at org.milyn.Smooks.filterSource(Smooks.java:449)
      at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:58)
      at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:40)
      at EDITestReader.readFile(EDITestReader.java:37)
      at EDITestReader.main(EDITestReader.java:59)
  Caused by: org.xml.sax.SAXException: Unknown/Unexpected UN/EDIFACT control block segment code '
  UN'.
      at org.milyn.edisax.unedifact.handlers.r41.UNEdifact41ControlBlockHandlerFactory.getControlBlockHandler(UNEdifact41ControlBlockHandlerFactory.java:53)
      at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:95)
      at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
      at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
      at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:75)
      ... 8 more
      enter code here
  </code></pre>
  
  <p>The actual EDIFACT message is fairly simple:</p>
  
  <pre><code>UNA:+.? '
  UNB+UNOC:3+IMP+XXX+20110902:1024+44090560'
  UNH+440905601+APERAK:D:00B:UN:IMP10'
  BGM+313++9+RE'
  RFF+ACW:XXXXXXXXX1109020'
  DTM+182:201109021018:203'
  RFF+BM:XXXXXXXXX'
  RFF+AGO:XXXXXXX1109020'
  RFF+EQ:XXXXXXXX'
  NAD+MS+IMP'
  CTA+MS+:EDI'
  COM+XXXXXXXXXXX:TE'
  COM+support@XXXXX.XX:EM'
  ERC+200:IMP02:DAK'
  FTX+AAO+++ERR4045?: Gest.datum ist mehr als 90 Tage kleiner als das Tagesdatum+DE'
  UNT+14+440905601'
  UNZ+1+44090560'
  </code></pre>
  
  <p>When I remove the leading UNA and UNB segment it comes up with this exception: ([APERAK][D:00B:UN].  Must be a minimum of 1 instances of segment [BGM]). There is a BGM segment so I am not sure why it is complaining.</p>
  
  <pre><code>Caused by: org.milyn.edisax.EDIParseException: EDI message processing failed [APERAK][D:00B:UN].  Must be a minimum of 1 instances of segment [BGM].  Currently at segment number 2.
      at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:460)
      at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:411)
      at org.milyn.edisax.EDIParser.parse(EDIParser.java:387)
      at org.milyn.edisax.EDIParser.parse(EDIParser.java:371)
      at org.milyn.edisax.unedifact.handlers.r41.UNHHandler.process(UNHHandler.java:80)
      at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:98)
      at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
      at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  When I remove the carriage returns from the message </p>
  
  <pre><code>UNH+440905601+APERAK:D:00B:UN:IMP10'BGM+313++9+RE'RFF+ACW:XXXXXXXXX1109020'DTM+182:201109021018:203'
  </code></pre>
  
  <p>it works fine. But how do I get smooks to accept carriage returns and whitespaces and the two leading UNA/UNB segments? I probably skipped some part of message processing smooks normally does.     </p>
  
  <p><strong>UPDATE 2:</strong>
  Figured out UNA/UNB segments are supported (my mistake) but I am still having problems with the carriage returns.
  Renat suggested to use a 'ignoreNewLines' option on the EDIParser. I've tried that but it doesn't seem to make a difference. I've also tried to configure smooks with this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;smooks-resource-list 
      xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" 
      xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.4.xsd"&gt;
          &lt;edi:reader mappingModel="/org/milyn/smooks/edi/xsd14/edi-to-xml-mapping.xml" ignoreNewLines="true" /&gt;
      &lt;/smooks-resource-list&gt;
  </code></pre>
  
  <p>Again with no success. </p>
  
  <p>I have the feeling that the D00AInterchangeFactory (or what every version you use) configures its EDIParser differently and ignoreNewLines is ignored.</p>
  
  <p>Is there a way to get the EDIParser the InterchangeFactory is using?  </p>