spring web services - 如何在方法端点中获取字符串有效负载?

发布于 2024-12-01 01:43:04 字数 589 浏览 1 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2024-12-08 01:43:04

我本来想说您应该尝试使用 XPathParam 注释来解决这个问题,但我看到您已经尝试过。为什么这对你不起作用?

我不确定您是否需要字符串形式的元素值,或者是否需要字符串形式的完整 XML。对于后者,您可以尝试将 MessageContext 添加到方法签名中,并使用以下方法将 PayLoadSource 作为字符串获取:

DOMSource source = (DOMSource) messageContext.getRequest().getPayloadSource();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文