【问题标题】:Bundle with exception org.xml.sax.SAXParseException: Content is not allowed in prolog带有异常 org.xml.sax.SAXParseException 的捆绑包:prolog 中不允许内容
【发布时间】:2012-12-22 21:47:16
【问题描述】:

我在 FuseESB 中部署了一个包,它将记录传入的肥皂请求。 我使用 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 信息。 方法os如下:

 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,这相当于真正的肥皂请求,Fuse 会毫无例外地安装包。

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

【问题讨论】:

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


    【解决方案1】:

    异常说prolog中有内容。这意味着您的 DSL 可能会在 xml 文档之前写入一些字节。验证流的顶部没有任何内容。

    另请查看:Content is not allowed in Prolog SAXParserException

    【讨论】:

    • R. Vigginao,我发现了 XML 中的错误。我正在将 Base64 编码的文件作为 XML 中的字符串处理,其中包含字符“”。由于这些字符,解析器失败了。再次感谢...
    猜你喜欢
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 2011-06-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多