Announcement Announcement Module
No announcement yet.
XPath parameter binding Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • XPath parameter binding

    Following my post, I tried to think of ways to make XPath easier. In Java, this is the way to evaluate an XPath expression.

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    XPathExpression expression =
    String result = expression.evaluate(document);
    Clearly, this is too much plumbing to do each an every time. So I tried to make it easier, by using annotations. The end result looks something like this:

    public class MyEndpoint {
      public void handleContact(
        @XpathParam("/Contacts/Contact/Name") String name) {
          // do something with name
    The idea is to tag any object with @Endpoint, tag methods with @SoapAction to indicate that handleContact should be called for incoming messages with the "" SOAPAction header. The parameters are bound to the result of the XPath expression. Besides String, other supported parameters types are boolean, double, Node, and NodeList (the supported types by XPath):

        public void supportedTypes(@XPathParam("/root/child")boolean param1,
                                   @XPathParam("/root/child/number")double param2,
                                   @XPathParam("/root/child")Node param3,
                                   @XPathParam("/root/*")NodeList param4,
                                   @XPathParam("/root/child/text")String param5) {
    This programming model is a Java 5 alternative for PayloadEndpoint and MethodEndpoint (and it's subclasses). Besides using @XPathParam, you can also use a Marshaller:

        public MarshalledType response(UnmarshalledType type) {
    This has not been submitted to SVN yet, because it requires a little more work. However, I would love to hear from your opinions on this feature. I like it, but I'm open for other or better thoughts .

  • #2
    I would really appreciate some feedback on this . If think I will push it into 1.0, if enough people like it.