Last modified: 6/16/2005
The WAR Contents
Typically, one creates the WAR file with a GUI development tool or with the ant
war
task from the generated artifacts from wsimport,
wsgen, or
apt
tools.
For example, a sample WAR file starting from a WSDL file:
WEB-INF/classes/hello/HelloIF.class SEI
WEB-INF/classes/hello/HelloImpl.class Endpoint
WEB-INF/sun-jaxws.xml JAX-WS RI deployment descriptor
WEB-INF/web.xml Web deployment descriptor
WEB-INF/wsdl/HelloService.wsdl WSDL
WEB-INF/wsdl/schema.xsd WSDL imports this Schema
The sun-jaxws.xml
File
The <endpoints>
element contain one or more <endpoint>
elements. Each endpoint represents a port in the WSDL and it contains all information about implementation class, servlet url-pattern, binding, WSDL, service, port QNames. The following shows a sun-jaxws.xml
file for a simple HelloWorld
service. sun-jaxws.xml is the schema instance of sun-jaxws.xsd.
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="MyHello"implementation="hello.HelloImpl"
url-pattern="/hello"/>
</endpoints>
-
endpoint can have the following attributes
-
Attribute Optional
Use
name
N
Name of the endpoint
wsdl
Y
Primary wsdl file location in the WAR file. For e.g. WEB-INF/wsdl/HelloService.wsdl. If this isn't specified, JAX-WS will create and publish a new WSDL. When the service is developed from Java, it is recommended to omit this attribute.
service
Y
QName of WSDL service. For e.g. {http://example.org/}HelloService. When the service is developed from java, it is recommended to omit this attribute. port
Y
QName of WSDL port. For e.g. {http://example.org/}HelloPort. When the service is developed from Java, it is recommended to omit this attribute. implementation
N
Endpoint implementation class name. For e.g: hello.HelloImpl. The class should have @WebService annotation. Provider based implementation class doesn't have to have this annotation.
url-pattern
N
Should match <url-pattern> in web.xml
binding
Y
Binding id defined in the JAX-WS API. The possible values are:
"http://schemas.xmlsoap.org/wsdl/soap/http",
If omitted, it is considered SOAP1.1 binding.
"http://www.w3.org/2003/05/soap/bindings/HTTP/"
enable-mtom
Y
Enables MTOM optimization. true or false. Default is false.
- endpoint can have a optional handler-chain element
<?xml version="1.0" encoding="UTF-8"?>
<endpoints ...">
<endpoint ...>
<handler-chain>
<handler-chain-name>somename</handler-chain-name>
<handler>
<handler-name>MyHandler</handler-name>
<handler-class>hello.MyHandler</handler-class>
</handler>
</handler-chain></endpoint>
</endpoints>
The web.xml
File
The following shows a web.xml
file for a simple HelloWorld
service. It specifies JAX-WS RI specific listener, servlet classes. These classes are com.sun.ws.transport.http.servlet.JAXRPCContextListener, and com.sun.xml.ws.transport.http.servlet.JAXRPCServlet is servlet
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.JAXRPCContextListener</listener-class>
</listener>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.JAXRPCServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
Remember these requirements when building a WAR:
- WSDL and auxiliary WSDL, Schema files should be packaged under WEB-INF/wsdl dir. It is recommended that they need not be packaged when the service is started from Java
- WebService implementation class should contain @WebService annotation. Provider based endpoints need not have @WebService annotation.
- wsdl, service, port attributes for endpoint element are mandatory for Provider based endpoints.