2017-08-01 177 views
0

我是EDI的新手。我只是使用smooks API將ORDERS edi文件轉換爲XML。在下面的例子中,一些ORDER示例文件工作正常。但是當我運行下面的edi文件時,我得到了以下異常。我堅持這一點。這是我的榜樣,EDI數據EDI必須是至少1個細分市場[UNS]

package example; 

import org.json.JSONObject; 
import org.json.XML; 
import org.milyn.Smooks; 
import org.milyn.SmooksException; 
import org.milyn.io.StreamUtils; 
import org.milyn.smooks.edi.unedifact.UNEdifactReaderConfigurator; 
import org.xml.sax.SAXException; 

import javax.xml.transform.stream.StreamResult; 
import javax.xml.transform.stream.StreamSource; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.StringWriter; 

public class Main { 
public static int PRETTY_PRINT_INDENT_FACTOR = 4; 
protected static String runSmooksTransform() throws IOException, SAXException, SmooksException { 
    Smooks smooks = new Smooks(); 
    smooks.setReaderConfig(new UNEdifactReaderConfigurator("urn:org.milyn.edi.unedifact:d93a-mapping:*")); 
    try { 
     StringWriter writer = new StringWriter(); 

     smooks.filterSource(new StreamSource(new FileInputStream("EDI.edi")), new StreamResult(writer)); 

     return writer.toString(); 
    } finally { 
     smooks.close(); 
    } 
} 

public static void main(String[] args) throws IOException, SAXException, SmooksException { 

    System.out.println("\n\n==============Message In=============="); 
    System.out.println(readInputMessage()); 
    System.out.println("======================================\n"); 

    String messageOut = Main.runSmooksTransform(); 

    System.out.println("==============Message Out============="); 
    System.out.println(messageOut); 
    System.out.println("======================================\n\n"); 

    JSONObject xmlJSONObj = XML.toJSONObject(messageOut); 
    String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR); 
    System.out.println(jsonPrettyPrintString); 
} 

private static String readInputMessage() throws IOException { 
    return StreamUtils.readStreamAsString(new FileInputStream("EDI.edi")); 
} 
} 

並與樣品EDI數據異常

Exception in thread "main" org.milyn.SmooksException: Failed to filter source. 
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97) 
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64) 
at org.milyn.Smooks._filter(Smooks.java:526) 
at org.milyn.Smooks.filterSource(Smooks.java:482) 
at org.milyn.Smooks.filterSource(Smooks.java:456) 
at example.Main.runSmooksTransform(Main.java:49) 
at example.Main.main(Main.java:63) 
Caused by: org.milyn.edisax.EDIParseException: EDI message processing failed [ORDERS][D:93A:UN]. Must be a minimum of 1 instances of segment [UNS]. Currently at segment number 9. 
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:499) 
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:450) 
at org.milyn.edisax.EDIParser.parse(EDIParser.java:426) 
at org.milyn.edisax.EDIParser.parse(EDIParser.java:410) 
at org.milyn.edisax.unedifact.handlers.UNHHandler.process(UNHHandler.java:97) 
at org.milyn.edisax.unedifact.handlers.UNBHandler.process(UNBHandler.java:75) 
at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:113) 
at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:75) 
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76) 
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86) 
... 6 more 
+1

它看起來像smooks正在尋找一個不在您的數據中的UNS細分市場。根據D.93A標準,該部分控制是強制性的。由於您沒有發佈您的EDI文件,我不知道這是否屬實 - EDI文件可能存在其他問題。 – Andrew

+0

安德魯。你是對的。 EDI文件有未知的標準代碼。所以我得到了例外。現在,它刪除未知的代碼後工作正常。 –

回答

1

壞源數據將導致此。

它看起來像smooks正在尋找一個不在您的數據的UNS細分市場。根據D.93A標準,該部分控制是強制性的。

相關問題