简体   繁体   English

Servlets + JAX-WS

[英]Servlets + JAX-WS

I'm trying to expose a web service method via JAX-WS annotations. 我正在尝试通过JAX-WS注释公开Web服务方法。 Many examples I've seen reference the EndPoint.publish() method to quickly stand up the service in a standalone app (ex from Java Web Services: Up and Running, 1st Edition): 我见过的许多示例都引用了EndPoint.publish()方法,以便在独立应用程序中快速启动服务(来自Java Web Services:Up and Running,1st Edition):

public class TimeServerPublisher {
public static void main(String[ ] args) {
  // 1st argument is the publication URL
  // 2nd argument is an SIB instance
  Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());
}

} }

One thing that I'm missing is how to accomplish essentially the same thing but in an existing app. 我缺少的一件事是如何在现有应用程序中完成基本相同的事情。 Would I make a servlet to handle this? 我会制作一个servlet来处理这个问题吗? What is the proper way to publish this service in an existing WAR file? 在现有WAR文件中发布此服务的正确方法是什么?

In a container you don't have to publish like this. 在容器中,您不必像这样发布。 The container will do the publish. 容器将进行发布。 If you plan to use it in JBoss server try JBossWS otherwise for Tomcat or any other server Axis2 may be the better choice. 如果您计划在JBoss服务器中使用它,请尝试JBossWS,否则对于Tomcat或任何其他服务器,Axis2可能是更好的选择。

Read more from the following links. 阅读以下链接中的更多内容。

http://jbossws.jboss.org/mediawiki/index.php?title=JBossWS http://jbossws.jboss.org/mediawiki/index.php?title=JBossWS

http://ws.apache.org/axis2/ http://ws.apache.org/axis2/

This depends on what WS stack you are using. 这取决于您使用的WS堆栈。

If you are using Java 6 then that includes the JAX-WS reference implementation , then you can consult the documentation about JAX-WS RI WAR contents . 如果您使用的是Java 6,那么它包含JAX-WS参考实现 ,那么您可以查阅有关JAX-WS RI WAR内容文档

As @Jerrish and @andri coments, there are different aproaches and solutions, depending on your concerns. 正如@Jerrish和@andri所说,根据您的顾虑,有不同的方法和解决方案。

The idea behind is that you don't need to set the configuration (port, etc) when will be published your web service. 背后的想法是,您将不需要在发布Web服务时设置配置(端口等)。 The best approach could be to set this via configuration files (XML, properties, etc) or using @Annotations. 最好的方法是通过配置文件(XML,属性等)或使用@Annotations来设置它。

For example, if you're accustomed to use frameworks like Guice or Spring, you know that is possible/recommended to start the context of your application publishing or initializing some objects, factories, datasources, etc and publishing webservices is another task that can be done in this time, because will be available when you will start your application, isn't?. 例如,如果您习惯使用像Guice或Spring这样的框架,那么您就知道可以/建议启动应用程序发布的上下文或初始化某些对象,工厂,数据源等,并且发布Web服务是另一项任务。在这个时间完成,因为当你开始申请时可以使用,不是吗?

By the way, I've good experiences with CXF and another solution could be Spring Web Services another powerful solution for creating web services. 顺便说一句,我有很好的CXF经验,另一个解决方案可能是Spring Web Services另一个创建Web服务的强大解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM