我在 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 请求之前抛出异常?谁能告诉我解决方案?