SOAP 和 REST Web 服务在 Java EE 中具有一种实现
是否有可能(Java EE、JBoss 6)巧妙地注释 Java 代码以提供 RESTful 和 SOAP Web 服务,而无需实现两种方法?
我在想:
@Local
@Path("/service")
@WebService
public interface SomeService {
@GET @Path("somemethod")
@WebMethod
public String someMethod (@QueryParam("s") String someParam);
}
请注意两者@Path和@WebService注释(不幸的是,上面的示例不起作用)。
Is it possible (Java EE, JBoss 6) to cleverly annotate Java code to provide both RESTful and SOAP webservices without implementing two methods?
I'm thinking about:
@Local
@Path("/service")
@WebService
public interface SomeService {
@GET @Path("somemethod")
@WebMethod
public String someMethod (@QueryParam("s") String someParam);
}
Please notice both @Path and @WebService annotations (above example does not work unfortunately).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然 JAX-WS 和 JAX-RS 注释可以非常愉快地在相同的方法上共存,但我发现很难相信任何经过精心调整以与 JAX-RS 一起使用的接口都可能非常适合 JAX-WS,或者 < em>反之亦然。问题不是你不能做,而是你不应该做;他们对世界有不同的模型,对于良好界面的含义也有不同的概念。
但是,如果您只是做一些琐碎的事情,例如简单的查找,它确实可以工作:
不过,我喜欢在接口上放置尽可能多的东西(检查您的框架文档以了解如何使它们工作),因为这会减少上述 部分(!!)可能的注释集下降到更合理的级别。 (作为参考,当事情开始变得复杂并且您在不平凡的模式中应用多个方面时,您可以轻松地为每个方法获得超过 20 个注释,其中一些与您的实现相关,一些与一个或另一个相关界面的划分可以促进理智。)
While JAX-WS and JAX-RS annotations can quite happily cohabit on the same methods, I find it hard to believe that any interface that is well-tuned for use with JAX-RS could be a good fit for JAX-WS, or vice versa. The problem isn't that you can't do it, the problem is that you shouldn't; they have a different model of the world, a different concept of what it means to be a good interface.
But if you're just doing something trivial like a simple lookup, it can indeed work:
I like to put as much as I can on interfaces though (check your framework documentation for how to make them work) as that reduces the above partial (!!) set of possible annotations down to a more sensible level. (For reference, when things start to get complicated and you're applying multiple aspects in non-trivial patterns, you can easily get to over 20 annotations per method, some of which relate to your implementation and some of which relate to one or other of your interfaces; partitioning promotes sanity.)
我希望将 JAX/RS 注释应用于类而不是接口。
您可能还需要进行一些配置以将 JAX/RS servlet 实现添加到您的 Web 应用程序中。
我有一些更详细的解释这里,它是在 WebSphere 中而不是 JBoss 中,但它使用 Apache 开源实现,因此很可能是相关的。
从概念上讲,我不明白为什么同一个简单的方法不能同时作为 Web 服务和 RESTful 服务公开,但是,这两种方法的设计理念根本不同,当你遇到任何不平凡的事情时,我只是不这样做这将啮合。
I would expect to apply the JAX/RS annotations to a Class not an Interface.
You may also need to do some configuring to add the JAX/RS servlet implementation to your web app.
I've got some more detailed explanation here, it's in WebSphere not JBoss, but it's using an Apache open source implementation so may well be relevant.
In concept I don't see why the same simple method couldn't be exposed as both Web service and RESTful service, however, the design philosophies of the two approaches are fundamentally different, when you get to anything non-trivial I just don't this will mesh.