【发布时间】:2017-12-07 12:45:33
【问题描述】:
我对使用 SOAP 和蓝图(就像 Spring)相当陌生。 不管怎样,我只是想学习基本的atm,到目前为止做得很好。
我在使用 Java 类从 XML 文件中检索特定节点值时遇到了一个小问题。这在我作为独立运行应用程序时有效,但是当我使用 Soap 获取请求时,值“lastName”返回 null。
public static void main(String[] args) throws XPathExpressionException {
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = builderFactory.newDocumentBuilder();
} catch (ParserConfigurationException p) {
p.printStackTrace();
}
try {
Document document = builder.parse(new FileInputStream("d:\\input11.xml"));
XPath xP = XPathFactory.newInstance().newXPath();
String expression ="/people/person/lastName";
NodeList nodeList = (NodeList) xP.compile(expression).evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
lastName += nodeList.item(i).getFirstChild().getNodeValue() + " ";
}
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException s) {
s.printStackTrace();
}
System.out.println(lastName);
}
public static String returnLastName(String input){
System.out.println(lastName);
return "LastName: "+lastName +"\n";
}
}
这是我的 blueprint.xml 代码:
<bean id="lastNameBean" class="com.*****.camelBlueprintTest.XMLCamel" />
<route id="lastName">
<from uri="cxf:bean:returnLName" />
<bean ref="lastNameBean" method="returnLastName" />
<log message="The message contains ${body}" />
<to uri="mock:result" />
</route>
所以当我运行 Java 应用程序时它确实返回了姓氏,但在 SOAP 请求中我得到“LastName: null”。
【问题讨论】:
标签: spring web-services soap cxf blueprint