Library Link To Toggle Frames Print Feedback

Deploying to a Servlet Container

In order to deploy a service to a servlet container, it is necessary to package all of the relevant files into a Web archive (WAR) file. The WAR file is a standard format for packaging Web applications.

.war file

The helloworld.war contains the following files and directories:

META-INF/
        Manifest.mf
WEB-INF/
        wsdl/
                hello_world.wsdl
        classes/
                *.class
        web.xml
        cxf-servlet.xml

WSDL contract

The WSDL contract, hello_world.wsdl, is included in the Web archive. The contract specifies a SOAP binding and a HTTP port, but the address in the HTTP port is ignored. A URL constructed from the servlet configuration is used instead of the address in the contract—see URL for Greeter service .

Class files

The Web archive includes the class files for the server implementation and the WSDL stub code under the WEB-INF/classes directory.

web.xml file

The web.xml file instructs Tomcat to load the org.apache.cxf.jaxws.servlet.CXFServlet class. This servlet plays the role of a service adapter, enabling you to deploy the Greeter service into the Tomcat Web server.

You do not normally need to edit the contents of the web.xml file. For reference, a copy of the standard web.xml file is stored in the CeltixInstallDir/etc directory.

cxf-servlet.xml file

The cxf-servlet.xml file is used to configure the endpoints that plug in to the CXF servlet. When the CXF servlet starts up, it reads the list of endpoint elements in this file and initializes a service endpoint for each one.

In the current example, the cxf-servlet.xml file contains just a single endpoint element to configure the Greeter service endpoint, as follows:

<endpoints>

    <endpoint
        name="hello_world"
        interface="org.apache.hello_world_soap_http.Greeter"
        implementation="demo.hw.server.GreeterImpl"
        wsdl="WEB-INF/wsdl/hello_world.wsdl"
        service="{http://apache.org/hello_world_soap_http}SOAPService"
        port="{http://apache.org/hello_world_soap_http}SOAPPort"
        url-pattern="/hello_world" />

</endpoints>

URL for Greeter service

When you deploy the Greeter service into a servlet container, the original address specified in the WSDL contract is ignored and a specially constructed servlet URL is used instead. The constructed URL has the following general form:

http://Hostname:Port/Context/CXFServletPat/EndpointPat

Where Hostname and Port are the host name and IP port where the Web server listens for incoming HTTP messages (typically, you can use localhost and 8080 for these values). The servlet Context is normally equal to the name of the .war file. For example, the helloworld.war file has a context equal to helloworld. The CXFServletPat pattern is specified by the url-pattern element in the web.xml file—by default, services. The EndpointPat is determined by the url-pattern attribute in the cxf-servlet.xml file—by default, hello_world.

Using the typical values and defaults, you get the following URL:

http://localhost:8080/helloworld/services/hello_world

WSDL query URL

Associated with each service endpoint is a query URL that is used to download the service’s WSDL contract. To obtain the query URL, simply append ?wsdl to the endpoint URL.

For example, the default query URL for the Greeter service is as follows:

http://localhost:8080/helloworld/services/hello_world?wsdl

Clients can use the query URL to download an up-to-date copy of a service’s WSDL contract. Downloading the WSDL contract is typically necessary, if the server makes dynamic changes to the WSDL contract.