spring web services - 如何在方法端点中获取字符串有效负载?
如何在 spring ws 端点方法中将传入的 XML 有效负载作为字符串参数获取? 例如,我有以下代码,请注意,我将 XML 作为 JDOM 元素获取,现在需要手动将其转换为字符串。很高兴知道如何将其自动转换为字符串。
@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);
}
注释掉的方法签名只是我在尝试 XPath,它也没有按我预期的方式工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本来想说您应该尝试使用 XPathParam 注释来解决这个问题,但我看到您已经尝试过。为什么这对你不起作用?
我不确定您是否需要字符串形式的元素值,或者是否需要字符串形式的完整 XML。对于后者,您可以尝试将 MessageContext 添加到方法签名中,并使用以下方法将 PayLoadSource 作为字符串获取:
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: