Question

I have deployed a bundle in FuseESB which will log incoming soap request. I have used Java DSL as

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");

When I use method getParsedXPath here the Fuse ESB shows exception as org.xml.sax.SAXParseException: Content is not allowed in prolog.

I am using abovementioned method to get CDATA information. The method os as 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;
}

If I use some demo XML in code itself which is equivalent of real soap request, Fuse installs bundle without any exception.

How can Fuse throw exception prior to accepting the SOAP request? Can anyone tell me solution?

Was it helpful?

Solution

The exception says that there is content in prolog. It means that your DSL may write some byte before the xml document. Verify that nothing is present at the top of the stream.

Check also: Content is not allowed in Prolog SAXParserException

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top