简体   繁体   English

Java Web服务容器

[英]Java Web Services Container

I have just started learning Java Web Services ( JAX-WS ) and have one question. 我刚刚开始学习Java Web服务(JAX-WS),并且有一个问题。 The reference documentation always talks about Web Services container. 参考文档总是谈论Web服务容器。 My question is : What is a Web Services container and why do we need it. 我的问题是:什么是Web服务容器,为什么我们需要它。 I saw a simple example of JAX-WS in book "java web services up and running" where the web service is published using: 我在“ Java Web服务启动并运行”一书中看到了一个JAX-WS的简单示例,其中使用以下内容发布了Web服务:

Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());

This example did not require me to host a web service in a Web Server / App Server or any container. 此示例不需要我在Web Server / App Server或任何容器中托管Web服务。

and I was also able to access this web service. 而且我还能够访问该Web服务。

So what is a container, why do we need it for web services? 那么什么是容器,为什么我们需要它用于Web服务?

Basically you just need something that can run Java servlets. 基本上,您只需要可以运行Java servlet的东西。 Typical examples are Tomcat, Glassfish, JBoss, Jetty and many others. 典型示例是Tomcat,Glassfish,JBoss,Jetty等。

Of these Tomcat is the lightest weight as it is "only" a servlet container (JBoss and Glassfish are J2EE application servers) and is the reference implementation for the servlets specification. 其中的Tomcat重量最轻,因为它“仅”是一个servlet容器(JBoss和Glassfish是J2EE应用服务器),并且是servlet规范的参考实现。 You'll find lots of IDE integration and tutorials that use it too. 您会发现很多IDE集成以及也使用它的教程。

The web service specification implementation by the various vendors( Websphere,Weblogic, JBoss) are through a servlet and you would need a servelet container to support this servlet. 各个供应商(Websphere,Weblogic,JBoss)的Web服务规范实现都是通过Servlet实现的,您将需要一个servelet容器来支持该Servlet。 This servlet is specifically designed to handle SOAP based traffic (HTTP traffic with SOAP headers and body) rather than plain HTTP based POST/GET that you send from browsers. 该servlet专为处理基于SOAP的流量(带有SOAP标头和主体的HTTP流量)而设计,而不是处理从浏览器发送的基于HTTP的普通POST / GET。

The web service that you created is running in a container, which in this case is the server. 您创建的Web服务在容器(在本例中为服务器)中运行。 The server can run multiple applications, each having their own container. 服务器可以运行多个应用程序,每个应用程序都有自己的容器。 The container is necessary as it provides a standalone environment for the execution of the Java that is contained in the source. 容器是必需的,因为它为执行源中包含的Java提供了独立的环境。

The containers provide security, so if one application crashes due to a problem the other applications do not crash. 容器提供了安全性,因此,如果一个应用程序由于问题而崩溃,则其他应用程序也不会崩溃。 Depending on the implementation each container can run in its own VM or can run across multiple VMs. 根据实现方式,每个容器可以在其自己的VM中运行,也可以在多个VM之间运行。 Basically they are there to run the code in a separate environment from other code. 基本上,它们是在与其他代码分开的环境中运行代码的。

Here is some older(ish) documentation on the idea of containers. 是有关容器概念的一些较旧的文档。 Basically they can be run in different safe containers, much like running multiple applications at the same time in Java, that are controlled via a single application (web server). 基本上,它们可以在不同的安全容器中运行,就像在Java中同时运行多个应用程序一样,这些容器是由单个应用程序(Web服务器)控制的。

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

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