因此,我有一个带有几个命名空间的Web服务,我想通过一个bean路由来执行一些用户凭证检查。自从我使用XPATH以来,它已经很长时间了,所以我可能只是有一个PICNIC(主席不在计算机时出现的问题)错误。Apache Camel Java和XPath
Web服务消息将始终具有以下结构/图案:
<Operation>
<header with the head name space where the user credentials are stored>
<record control>
<objXX>
</Operation>
下面是一个例子消息(SOAP UI):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:list="http://www.insol.irix.com.au/IRIX_V1/Debtors/List" xmlns:head="http://www.insol.irix.com.au/IRIX_V1/Headers" xmlns:rec="http://www.insol.irix.com.au/IRIX_V1/RecordControl">
<soapenv:Header/>
<soapenv:Body>
<list:ListDebtorReq>
<head:MsgReqHdr>
<head:MsgGUID>${=java.util.UUID.randomUUID()}</head:MsgGUID>
<head:MsgDateTime>${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}</head:MsgDateTime>
<head:ConsumerSystemIDInfo>
<head:ConsumerSystemID>ConsumerSystemID</head:ConsumerSystemID>
<head:ConsumerSystemUserID>AgentX</head:ConsumerSystemUserID>
</head:ConsumerSystemIDInfo>
<head:SecCredInfo>
<head:IRIXUserID>Some User ID</head:IRIXUserID>
<head:IRIXPassword>Some Password</head:IRIXPassword>
</head:SecCredInfo>
<head:CryptoInfo>
<head:DigitalSignatureInfo>
<head:DigitalSignatureValue>verrantque per auras</head:DigitalSignatureValue>
<head:DigitalSignatureAlgorithm>SHA-256</head:DigitalSignatureAlgorithm>
</head:DigitalSignatureInfo>
</head:CryptoInfo>
</head:MsgReqHdr>
<!--Optional:-->
<rec:RecCntrl>
<rec:StartRecordNumber>1</rec:StartRecordNumber>
<!--Optional:-->
<rec:NumberOfRecords>3</rec:NumberOfRecords>
</rec:RecCntrl>
</list:ListDebtorReq>
</soapenv:Body>
</soapenv:Envelope>
所以基本上我希望能够创造一个能够查询所有用户名和密码数据的MsgReq头的bean。为了简化事情,我只是试图查询MsgGUID并从那里开始工作。不过,我似乎无法得到正确的xpath。由于我使用了几个名称空间,为了确保它们可用,我将它们包含在骆驼上下文文件中。
这里是我的骆驼上下文:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<import resource="classpath:META-INF/spring/camel-cxf.xml" />
<bean id="SecurityCheckBean" class="au.com.irix.insol.Security.IRIXSecurity"/>
<camelContext xmlns="http://camel.apache.org/schema/spring"
xmlns:list="http://www.insol.irix.com.au/IRIX_V1/Debtors/List"
xmlns:head="http://www.insol.irix.com.au/IRIX_V1/Headers"
xmlns:rec="http://www.insol.irix.com.au/IRIX_V1/RecordControl">
<route>
<from uri="cxf:bean:DebtorsService?dataFormat=PAYLOAD"/>
<bean ref="SecurityCheckBean"/>
</route>
</camelContext>
</beans>
正如你可以看到我正在运行Web服务生产者的SecurityCheckBean的传入消息。我的SecurityCheckBean目前非常简单,请参阅下面的代码。
public class IRIXSecurity {
public void CheckCredentials(
@XPath("//head:MsgGUID") String msgGUID,
@Body String body){
System.out.println(body);
System.out.println("Check Credentials Invoked");
System.out.println(msgGUID);
}
}
然而,当我送送通过SOAP UI我得到下面的异常请求:
Invalid xpath: //head:MsgGUID. Reason: javax.xml.xpath.XPathExpressionException: net.sf.saxon.trans.XPathException: Prefix head has not been declared
那么,如何去获取这些信息?为什么即使我已经在我的camel-context.xml中声明了名称空间,它们被报告为失踪?
只是为了兴趣缘故,我已经试过了XPATH的几个变化,如:
@XPath("//MsgGUID")
@XPath("//MsgReqHdr/head:MsgGUID")
@XPath("//head:MsgReqHdr/head:MsgGUID")
每次我要么得到一个异常以上或NULL值作为上市...