Java:使用端点将 webservice 发布到 tomcat 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2083500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: using endpoint to publish webservice to tomcat server
提问by Will
i am creating a simple SOAP web service. i am to ensure that it runs on a tomcat web service.
我正在创建一个简单的 SOAP Web 服务。我要确保它在 tomcat Web 服务上运行。
im trying to implement this with JAX-WS (see code)
我试图用 JAX-WS 实现这个(见代码)
my question is: does the Endpoint.publish use the tomcat server to host this or is it a mini glassfish kind of server?
我的问题是:Endpoint.publish 是使用 tomcat 服务器来托管它还是它是一种小型 glassfish 服务器?
should i be extending UnicastRemoveObject or something similiar instead?
我应该扩展 UnicastRemoveObject 或类似的东西吗?
ideally it would be able to be packaged into a .WAR and dropped in the directory and just work.
理想情况下,它可以打包成 .WAR 并放入目录中并正常工作。
It doesn't seem to work with my installed tomcat server as is because it says the port is already in use. I'm using Ubuntu karmic with the tomcat6 package installed, it could also be my user doesnt have permissions to publish to the running tomcat on 8080
它似乎不适用于我安装的 tomcat 服务器,因为它说端口已被使用。我正在使用安装了 tomcat6 软件包的 Ubuntu karmic,也可能是我的用户没有发布到 8080 上正在运行的 tomcat 的权限
i hope this question is clear enough
我希望这个问题足够清楚
sample code:
示例代码:
@WebService
public class UserAttributes {
public static void main(String[] args) {
UserAttributes instance = new UserAttributes();
Endpoint.publish("http://localhost:8082/WebServices/userattributes",
instance);
}
public string Hello() {
return "Hello World";
}
}
回答by Pascal Thivent
Does
Endpoint.publishuse the tomcat server to host this or is it a mini glassfish kind of server?
是
Endpoint.publish使用 tomcat 服务器来托管它还是它是一种小型 glassfish 服务器?
JAX-WS RI Endpoint.publishAPI uses by default a light-weight HTTP server implementationthat is included in Sun's Java SE 6. So no, it does notuse an embedded GlassFish nor an embedded Tomcat and even less your existing Tomcat install: it uses an embeddedcontainer i.e. something running inside the same JVM. Just FYI, it is however possible to plug other implementations as long as they provide a Service Provider Implementation(SPI). For example, Jetty 6 does so, see J2se6HttpServerSPI. But I'm not going to cover all the details here :)
JAX-WS RIEndpoint.publish默认API采用了重量轻,HTTP服务器实现包含在Sun的Java SE 6,所以,不,它并没有使用嵌入式GlassFish的,也不是一个嵌入式的Tomcat,甚至更少现有的Tomcat安装:它使用的是嵌入式容器,即在同一个 JVM 中运行的东西。仅供参考,但是可以插入其他实现,只要它们提供服务提供者实现(SPI)。例如,Jetty 6 这样做,请参阅J2se6HttpServerSPI。但我不会在这里涵盖所有细节:)
It doesn't seem to work with my installed tomcat server as is because it says the port is already in use.
它似乎不适用于我安装的 tomcat 服务器,因为它说端口已被使用。
As I said above, the Enpoint.publishAPI doesn't use your existing Tomcat install. It uses its own server and allows you to deploy your web service without having to package and deploy your app. It is especially useful during development (as it speeds up things). Actually, it's extremely handy.
正如我上面所说,Enpoint.publishAPI 不使用您现有的 Tomcat 安装。它使用自己的服务器,允许您部署 Web 服务而无需打包和部署您的应用程序。它在开发过程中特别有用(因为它可以加快速度)。实际上,它非常方便。
Now, if you have a Tomcat server running on port 8082 and if you try to publish your Endpointusing the same port, things won't work as you noticed. Use a different (and unused) port during development.
现在,如果您有一个 Tomcat 服务器在端口 8082 上运行,并且如果您尝试Endpoint使用相同的端口发布您的内容,事情将不会像您注意到的那样工作。在开发过程中使用不同的(和未使用的)端口。
And if you want to deploy your web services to your existing Tomcat install, then you'll have to package them in a war and to deploy this war on Tomcat. But this is totally different and doesn't have anything to do with using the Endpoint.publishAPI.
如果您想将您的 Web 服务部署到您现有的 Tomcat 安装中,那么您必须将它们打包到一个 war 中并在 Tomcat 上部署这个 war。但这完全不同,与使用Endpoint.publishAPI没有任何关系。
回答by Joseph
Very interesting. It seems to me that the embedded server also contains a soap engine to process the soap messages sent to that port. Is this also an embedded soap engine or is it using one of the popular soap engines (axis2,cxf,metro)
很有意思。在我看来,嵌入式服务器还包含一个soap 引擎来处理发送到该端口的soap 消息。这也是嵌入式soap引擎还是使用流行的soap引擎之一(axis2,cxf,metro)

