spring web services -how do I get the string payload in a method endpoint?
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 conv开发者_如何学运维erted 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.
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();
精彩评论