如何将很长的字符串/文件传递到 RESTWebservice JAX-RS Jersey

发布于 2024-08-24 16:10:57 字数 325 浏览 3 评论 0原文

我使用 JAX-RS API 编写了一个 RESTful Web 服务,它返回一个 XML 字符串。

我正在尝试编写另一个 RESTful Web 服务,它接受这个 XML 字符串,使用 DOM 解析它并提取我想要的特定内容。 XML 字符串恰好很长,因此我不想将其作为 @QueryParam 或 @PathParam 传递。

假设如果我将该 XML 字符串写入一个文件,我该如何编写该服务来接收该文件、提取我想要的内容并返回结果。我实际上正在尝试提取一些字符串,因此我的网络服务最终应该返回一个包含所有这些字符串的数组。

有人可以告诉我我应该如何做这件事吗?

提前致谢

I wrote a RESTful webservice using JAX-RS API, that returns an XML string.

I am trying to write another RESTful webservice that takes in this XML string, does parsing of it using DOM and extract particular things I want. The XML string happens to be very long so I do not want to pass it as a @QueryParam or @PathParam.

Say If I write that XML string into a file, How do I go about writing this service that takes in this file, extracts whatever I want and return the results. I am actually trying to extract some number of strings, so my webservice should finally return an array with all those strings.

Could somebody please shed some light on how I should go about doing this.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

川水往事 2024-08-31 16:10:57

Sashikiran,

不确定我是否正确理解这一点,但您可以实现对 HTTP 输出和输入流的流式访问。您无需立即阅读或写出整篇文章。

因此,当您从服务 A 读取流时,您可以提取所需内容并通过 POST 请求将其写出到服务 B。

为什么要对 XML 进行 DOM 解析? SAX 或 StAX 解析器似乎更适合 XML 确实非常长。

Sashikiran,

not sure I understand this correctly, but you can implement streaming access to the HTTP output and input streams. You need not read or write the whole thing at once.

So, while your read the stream from service A you can extract what you need and write that out to service B via a POST request.

Why are you DOM-parsing the XML? A SAX or StAX parser seems more suitable of the XML is indeed very long.

Jan

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