JAX-WS 2.1.1 | Users Guide | Tools | JAXWS RI Extensions | Samples | JAXWS Community |
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
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 should have @WebServiceProvider 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. |
enable-mtom |
Y
|
Enables MTOM optimization. true or false. Default is false.
|
<?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>
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.WSServletContextListener, and com.sun.xml.ws.transport.http.servlet.WSServlet 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.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</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: