WAS v8.5 > Develop applications > Develop web services - Notification (WS-Notification) > Develop applications that use WS-Notification

Example: Creating a Notification consumer web service skeleton

Use this example when creating a web service that implements the NotificationConsumer portType defined by the Web Services Base Notification specification. This task provides two code examples:

The article Writing JAX-WS applications for WS-Notification also includes an example of a consumer Web service.

If you are creating a Notification consumer web service skeleton, see the following code examples.


Example

The following example WSDL document describes a web service that implements the NotificationConsumer portType defined by the Web Services Base Notification specification:

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsn-bw="http://docs.oasis-open.org/wsn/bw-2"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="uri:example.wsn/consumer"
    targetNamespace="uri:example.wsn/consumer"> 
    <wsdl:import namespace="http://docs.oasis-open.org/wsn/bw-2"
                           location="http://docs.oasis-open.org/wsn/bw-2.wsdl" /> 
    <wsdl:binding name="NotificationConsumerBinding" type="wsn-bw:NotificationConsumer">         <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />         <wsdl:operation name="Notify">             <wsdlsoap:operation soapAction="" />             <wsdl:input>                 <wsdlsoap:body use="literal" />             </wsdl:input>         </wsdl:operation>     </wsdl:binding> 
    <wsdl:service name="NotificationConsumerService">         <wsdl:port name="NotificationConsumerPort" binding="tns:NotificationConsumerBinding">             <wsdlsoap:address location="http://myserver.mycom.com:9080/Consumer" />         </wsdl:port>     </wsdl:service> 
</wsdl:definitions>

The following example shows a basic implementation of the Service Endpoint Interface (SEI) generated from the preceding WSDL document using the WSDL2Java tool:

public class ConsumerExample implements NotificationConsumer {
        
    public void notify(NotificationMessage[] notificationMessage, SOAPElement[] any) 
                                                                    throws RemoteException {
        // Process each NotificationMessage
        for (int i=0; i<notificationMessage.length; i++) {                
            NotificationMessage message = notificationMessage[i];
                
            // Get the contents of the message             SOAPElement messageContent = message.getMessageContents();
                
            // Get the expression indicating which topic the message is associated with             TopicExpression topic = message.getTopic();                
                
            // Get a reference to the producer (this value is optional and so might be null)
            EndpointReference producerRef = message.getProducerReference();
                
            // Get a reference to the subscription (this value is optional and so might be null)
            EndpointReference subscriptionRef = message.getSubscriptionReference();
                
            // User defined processing ...                

        }
    }}


Related concepts:

WS-Notification
JAX-RPC


Related


Writing a WS-Notification application that exposes a web service endpoint
Writing a WS-Notification application that does not expose a web service endpoint
Filtering the message content of publications
Example: Subscribing a WS-Notification consumer
Example: Pausing a WS-Notification subscription
Example: Publishing a WS-Notification message
Example: Creating a WS-Notification pull point
Example: Getting messages from a WS-Notification pull point
Example: Registering a WS-Notification publisher
Use WS-Notification for publish and subscribe messaging for web services
Secure WS-Notification


Reference:

WS-Notification troubleshooting tips
WSDL2Java command for JAX-RPC applications

Writing JAX-WS applications for WS-Notification

WS-BaseNotification v1.3 OASIS Standard

XML Path Language (XPath) v1.0

XQuery 1.0 and XPath 2.0 Formal Semantics


+

Search Tips   |   Advanced Search