2013-01-08 59 views
0

我在FuseESB中部署了一個包,用於記錄傳入的soap請求。 我已經使用的Java DSL作爲包含異常org.xml.sax.SAXParseException的包:在prolog中不允許包含內容

from("cxf:bean:comprovaWS?dataFormat=MESSAGE").setHeader("SOAPAction", new ConstantExpression("http://www.about.com")).streamCaching() 
      .choice() 
      .when(xPathBuilder).log("Request is:"+getParsedXPath(simple("${body}").getText().trim(),"//item[2]/stringValue/text()", false)) 
      .to("callService") 
      .otherwise().log("Error"); 

當我使用方法getParsedXPath這裏的保險絲ESB顯示異常,因爲org.xml.sax.SAXParseException: Content is not allowed in prolog.

我使用上述方法來獲得CDATA信息。 的方法操作系統爲folows:

public String getParsedXPath(String xmlStringToParse, String xPathExpression, boolean isNamespaceAware) { 

    String parsedXMLPath=""; 
    try { 
     DocumentBuilderFactory xmlFact = 
       DocumentBuilderFactory.newInstance(); 

     DocumentBuilder builder = xmlFact.newDocumentBuilder(); 
     Document doc = builder.parse(new java.io.ByteArrayInputStream(xmlStringToParse.getBytes())); 


     XPath xpath = XPathFactory.newInstance().newXPath(); 

     xmlFact.setNamespaceAware(isNamespaceAware); 

     if(isNamespaceAware){ 

     xpath.setNamespaceContext(new NamespaceContext() { 
    public String getNamespaceURI(String prefix) { 
    // we know there's only one namespace uri, just return it! 
    return "http://www.about.com"; 
    } 

    // this is not used by XPath 
    public String getPrefix(String namespaceURI) { 
    System.out.println("getPrefix: " + namespaceURI); 
    return null; 
    } 

    // this is not used by XPath 
    public Iterator getPrefixes(String namespaceURI) { 
    System.out.println("getPrefixes: " + namespaceURI); 
    return null; 
    } 
}); 
     } 



     NodeList nodes = (NodeList) xpath.evaluate(xPathExpression, doc, XPathConstants.NODESET); 
    if (nodes.getLength() == 0) { 
    parsedXMLPath="<error>Wrong xPath value: "+xPathExpression+"</error>"; 
    } 
    else { 

      parsedXMLPath = nodes.item(0).getNodeValue(); 
    } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return parsedXMLPath; 
} 

如果我使用的代碼本身的一些演示XML這相當於真正的SOAP請求,熔斷器安裝包,沒有任何例外。

Fuse如何在接受SOAP請求之前拋出異常? 任何人都可以告訴我解決方案嗎?

回答

0

例外說prolog中有內容。這意味着你的DSL可能會在xml文檔之前寫入一些字節。確認流的頂部沒有任何內容。

檢查也:Content is not allowed in Prolog SAXParserException

+0

R. Vigginao, 我發現這是在XML錯誤。 我正在處理Base64編碼文件爲XML格式的字符串,其中包含字符「