开发者

spring web services -how do I get the string payload in a method endpoint?

开发者 https://www.devze.com 2023-03-29 19:40 出处:网络
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

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消