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请求之前抛出异常? 任何人都可以告诉我解决方案吗?
R. Vigginao, 我发现这是在XML错误。 我正在处理Base64编码文件为XML格式的字符串,其中包含字符“”。 由于这些字符解析器失败。 再次感谢... –