apache camel - Bundle与异常org.xml.sax.SAXParseException:内容不允许在



我已经在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请求之前抛出异常?有人能告诉我解决办法吗?

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

也检查:内容不允许在Prolog SAXParserException

相关内容

  • 没有找到相关文章

最新更新