Petals-BC-SOAP

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (3)

View Page History
h2. Subscribe to WS-N producer

todo
In order to receive WS-Notifications, the consumers MUST subscribe to these notifications to the WS-N producer.

To subscribe to WS notification, the notification consumer must send a specific SOAP message to the notification producer. In the SOAP BC, subscription URL is {{http://HOST:PORT/wsn/producer}} where :
* HOST is the host you have installed the SOAP BC
* PORT is the port where the SOAP BC listens to incoming SOAP messages

An example of a SOAP subscribe message is :
{code:lang=xml}
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">
http://localhost:8084/wsn-consumer/services/consumer
</wsa:To>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">
http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest
</wsa:Action>
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">
uuid:9888fa43-281f-ea0f-ec21-09e9119366c6
</wsa:MessageID>
<wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Address>http://www.w3.org/2005/08/addressing/role/anonymous</wsa:Address>
</wsa:From>
</soap:Header>
<soap:Body>
<wsnt:Subscribe xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2">
<wsnt:ConsumerReference>
<wsa:Address xmlns:wsa="http://www.w3.org/2005/08/addressing">
http://127.0.0.1:8084/wsn-consumer/services/consumer 1
</wsa:Address>
</wsnt:ConsumerReference>
<wsnt:Filter>
<wsnt:TopicExpression Dialect="xsd:anyURI">TopicSample</wsnt:TopicExpression> 2
</wsnt:Filter>
</wsnt:Subscribe>
</soap:Body>
</soap:Envelope>
{code}
# The address to send notifications messages to. This can be simply a Web Service endpoint which can handle notification message
# The name of the topic to subscribe to

\\
Subscribers can use the PEtALS WS-N client API to subscribe to topics. It can be done like this :
{code}
package org.ow2.petals.binding.soap.wsn;

import java.net.URI;
import javax.xml.namespace.QName;
import org.ow2.petals.ws.addressing.EndpointReference;
import org.ow2.petals.ws.client.SubscriptionClient;
import org.ow2.petals.ws.client.WsnProducerClient;
import org.ow2.petals.ws.fault.WsnFault;
import org.ow2.petals.ws.notification.TopicExpressionFilter;

/**
* Web service notification subscription.
*
*/
public class SubscribeClient {

/**
* @param args
*/
public static void main(String[] args) {
EndpointReference sourceEPR = new EndpointReference(URI.create("http://localhost:9090/wsn-consumer/"));
EndpointReference destinationEPR = new EndpointReference(URI.create("http://localhost:9090/wsn-consumer/service/consumer"));
WsnProducerClient client = new WsnProducerClient(sourceEPR,
destinationEPR);
TopicExpressionFilter filter = null;
try {
filter = new TopicExpressionFilter(new QName("topicSample"));
} catch (WsnFault e1) {
e1.printStackTrace();
}
SubscriptionClient subsClient = null;
try {
subsClient = client.subscribe(sourceEPR, filter, null);
} catch (WsnFault e) {
e.printStackTrace();
}
}
}
{code}

\\
{info:title=Note}
All the subscriptions are persisted in the component work folder to be able to reload subscriptions on componentrestart.
{info}

\\
{info:title=Note}
If there are N subscriptions for the same notification consumer, the notification message will be sent N times. The first unsubscribe call will remove all the subscriptions for this consumer.
{info}

h2. Send a WS notification from a JBI message