捆绑有异常org.xml.sax.SAXParseException:prolog中不允许使用内容

时间:2013-01-08 22:30:44

标签: xml apache-camel jbossfuse apache-servicemix fuseesb

我在FuseESB中部署了一个捆绑包,它将记录传入的soap请求。 我使用Java DSL作为

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时,Fuse ESB将异常显示为org.xml.sax.SAXParseException: Content is not allowed in prolog.

我正在使用上述方法获取CDATA信息。 方法如下:

 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会毫无例外地安装bundle。

Fuse如何在接受SOAP请求之前抛出异常? 谁能告诉我解决方案?

1 个答案:

答案 0 :(得分:0)

例外情况说prolog中有内容。这意味着您的DSL可能会在xml文档之前写入一些字节。确认流顶部没有任何内容。

同时检查:Content is not allowed in Prolog SAXParserException