使用 jax.ws 提供静态文件
我正在构建一个 Web 前端来监视 SOAP 服务的状态。
有没有办法用 jax.ws 提供静态文件?例如 Endpoint.publish("/static", new SomeStaticFileHandler())
任何对 /static 的请求都只提供我的文件夹中相应的静态文件?在静态文件中,我想查询状态并使用 AJAX 调用更新页面。
谢谢!
I'm building a web front end to monitor the state of a SOAP service.
Is there any way to serve static files with jax.ws? For example Endpoint.publish("/static", new SomeStaticFileHandler())
where any requests to /static just serve the corresponding static file in my folder? Inside the static file I would like to query the state and update the page with AJAX calls.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提供静态文件的正确方法是将自定义 servlet 添加到 web.xml 。
至于您想尝试的黑客:提供任何文件类型、任何内容类型?我相信这是行不通的。也许您可以提供 XML 文件(如果它们遵循预定义的模式)—— JAX-WS 实现类返回对象,而不是字符串或流。使用架构和绑定将这些对象序列化为 SOAP/XML。您需要将文件解析为对象,然后返回到 JAX-WS 运行时...并且您将获得包含文件内容的 SOAP 信封。
这对我来说听起来不像一个静态文件。这是一种服务 XML 或 JSON 的动态方法。最简单的答案仍然是 servlet。
JAX-RS(RESTful Java API)是一个可行的替代方案也。
The correct way to serve static files is to add a custom servlet to the web.xml.
As for the hack you want to try: serve any file type, with any content-type? It will not work, I believe. Perhaps you can serve XML files if they follow a predefined schema -- JAX-WS implementation classes return objects, not strings or streams. These objects are serialized to SOAP/XML using the schema and binding. You'd need to parse the files into objects and then return to JAX-WS runtime... and you'll get a SOAP envelope over the file content anyway.
This doesn't sound like a static file to me. This is a dynamic method serving XML or JSON. The simplest answer is still a servlet.
JAX-RS (RESTful Java API) is a viable alternative too.