3

How can I get the incoming XML payload as a String parameter in spring ws endpoint method? For e.g. I have the following code, notice that I get the XML as a JDOM Element, which I now need to convert to String manually. It would be nice to know how to get this automatically converted to String.

@PayloadRoot(namespace=HOLIDAY_NAMESPACE_URI, localPart="holidayRequest")
@ResponsePayload
public Element handleHolidayRequest(@RequestPayload Element holidayRequest)
//public Element handleHolidayRequest(@XPathParam("holidayRequest") String holidayRequest)
{
    System.out.println("In handleHolidayRequest method with payload: " + holidayRequest);
    return getHolidayResponse(HOLIDAY_NAMESPACE);
}

The commented out method signature, is just me trying out XPath, which also did not work in the way I expected.

Abe
  • 8,623
  • 10
  • 50
  • 74

1 Answers1

2

I was about to say that you should try to solve this by using an XPathParam annotation instead, but I see you've already tried that. Why didn't that work for you?

I'm not sure if you need the value of an element as a string or if you need the complete XML as a String. For the latter, you can try adding MessageContext to your method signature and use that to get the PayLoadSource as a string by using something like:

DOMSource source = (DOMSource) messageContext.getRequest().getPayloadSource();
evandongen
  • 1,995
  • 17
  • 19
  • 1
    I wanted the complete xml as String. With message context I get domsource, and to convert it to String I got the following link ->http://stackoverflow.com/questions/315517/is-there-a-more-elegant-way-to-convert-an-xml-document-to-a-string-in-java-than-t Is there a better way? – Abe Sep 26 '11 at 11:29
  • I'm actually using something similar to log the complete message. I don't know if there's a better way but I do know this works fine for me :) I've put that method in a superclass of my endpoints so I can use it easily in all endpoint classes. – evandongen Sep 26 '11 at 15:47
  • Oh ok. I used XMLOutputter of JDom to convert the Element to String. So it looks like direct conversion to String is not there. – Abe Sep 27 '11 at 08:12