Last Modified: 11/3/05
Web Service endpoints may choose to work at the XML message level
by implementing the Provider
interface. This is achieved
by implementing either Provider<Source>
or Provider<SOAPMessage>
.
The endpoint accesses the message or message payload using this
low-level, generic API. The @ServiceMode
annontation is
used to convey whether the endpoint wants to access the message (Service.Mode.MESSAGE
)
or payload (Service.Mode.PAYLOAD
). If there is no @ServiceMode
annotation on the endpoint, payload is the default value. The endpoint
communicates with handlers using the property bag Map<String,
Object>
parameter. All the provider endpoints start from a
WSDL file and <provider>
WSDL customization can be
used to mark a port as a provider.
Provider<Source>
and PAYLOAD
An endpoint can access only the payload of a request using Service.Mode.PAYLOAD
in the @ServiceMode
annotation. This is the default
behaviour, if the annotation is missing.
For example:
public class ProviderImpl implements Provider<Source> {
public Source invoke(Source source, Map<String, Object> context) throws RemoteException {
// do request processing
Source response = ...;
return response;
}
}
Provider<SOAPMessage>
and MESSAGE
An endpoint can access an entire SOAP request as a SOAPMessage
.
Service.Mode.MESSAGE
in the @ServiceMode
annotation is used to convey the intent.
For example:
@ServiceMode(value=Service.Mode.MESSAGE)
public class ProviderImpl implements Provider<SOAPMessage> {
public SOAPMessage invoke(SOAPMessage msg, Map<String, Object> ctxt) throws RemoteException {
// do request processing
SOAPMessage response = ...;
return response;
}
}
Provider<Source>
and MESSAGE
An endpoint can access a request as a Source
. If the
request is a SOAPMessage
, only the SOAPPart
(no attachments) of the message is passed as Source
to
the invoke
method. If the returned response is null, it
is considered a one way MEP.
For example:
@ServiceMode(value=Service.Mode.MESSAGE)
public class ProviderImpl implements Provider<Source> {
public Source invoke(Source source, Map<String, Object> context) throws RemoteException {
// Use JAXRPCContext to access properties set by handler
String foo = (String)context.getProperty("foo");
// do request processing using source
// return null to indicate oneway
return null;
}
}
The provider endpoint starts with a WSDL file. A port can be
customized to a provider endpoint using the <provider>
customization. wsimport won't generate any artifacts for that port.
For example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bindings
...
wsdlLocation="AddNumbers.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<bindings node="wsdl:definitions" >
<package name="provider.server"/>
<provider>true</provider>
</bindings>
sun-jaxws.xml
fileFor example:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name='AddNumbers'
implementation='provider.server.AddNumbersImpl'
wsdl='WEB-INF/wsdl/AddNumbers.wsdl'
service='{http://duke.org}AddNumbersService'
port='{http://duke.org}AddNumbersPort'
url-pattern='/addnumbers'/>
</endpoints>
Provider and HandlersFor example:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name='AddNumbers'
implementation='provider.server.AddNumbersImpl'
wsdl='WEB-INF/wsdl/AddNumbers.wsdl'
service='{http://duke.org}AddNumbersService'
port='{http://duke.org}AddNumbersPort'
url-pattern='/addnumbers'/>
<handler-chain>
<handler-chain-name>my handler</handler-chain-name>
<handler>
<handler-name>MyHandler</handler-name>
<handler-class>provider.server.MyHandler</handler-class>
</handler>
</handler-chain>
</endpoints>
Copyright © 2005 Sun Microsystems, Inc. All rights reserved.