You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Diefenbach Anne <Di...@fgan.de> on 2009/06/19 15:28:37 UTC
How to use the WSN Broker exposed by wsn-cxf-binding example
Hi everyone,
having finally won (well, more or less) the fight to get my notification consumer up and running, I hope to be able to shorten the route for others attempting to do the same. So here's my HowTo:
1) Create a WSDL for your consumer service. For example: NotificationConsumer.wsdl (this WSDL was snagged from an IBM WebSphere tutorial)
<?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="http://http://example.com/wsn-consumer"
targetNamespace="http://example.com/wsn-consumer">
<wsdl:import namespace="http://docs.oasis-open.org/wsn/bw-2"
location="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://localhost:9080/WSNConsumer" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
2) Proxy your consumer service with the CXF BC. For this purpose, add to xbean.xml in wsn-cxf-binding-su the namespace xmlns:wsnc="http://example.com/wsn-consumer" and
<cxfbc:provider wsdl="classpath:NotificationConsumer.wsdl"
service="wsnc:NotificationConsumerService"
endpoint="NotificationConsumerPort"
interfaceName="wsn:NotificationConsumer"
locationURI="http://localhost:9080/WSNConsumer"
useJBIWrapper="false"
useSOAPEnvelope="false"
>
<cxfbc:outInterceptors>
<bean class="org.apache.servicemix.cxfbc.interceptors.JbiAddressingInterceptor"/>
<bean class="org.apache.cxf.ws.addressing.soap.MAPCodec"/>
</cxfbc:outInterceptors>
</cxfbc:provider>
I had a horrible fight with SMX about the location of NotificationConsumer.wsdl which it insisted on retrieving from the wsn-cxf-binding directory instead of the wsn-cxf-binding-su directory, where it uncomplainingly found broker.wsdl. I finally caved and placed a copy in wsn-cxf-binding.
3) Run wsdl2java for broker.wsdl and NotificationConsumer.wsdl and modify the code for your needs. Don't forget to add the object factory for your message (here: exampleMessage) to interfaces org.oasis_open.docs.wsn.bw_2.NotificationConsumer and org.oasis_open.docs.wsn.brw_2.NotificationBroker (one more entry for @XmlSeeAlso).
I used Fuse Services Framework to build both notification consumer and producer, so the following code examples are specific for that.
3a) Create a subscription for your consumer (you may need to do some of this in a method, I had problems with non-static references in the static main method):
ObjectFactory objectFactory = new ObjectFactory();
W3CEndpointReference epr = null;
InputStream is = org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_Server.class.getResourceAsStream("wsa_infoset.xml");
StreamSource src;
NotificationBroker ss = new NotificationBroker(wsdlURL, SERVICE_NAME); // org.servicemix.wsnotification.NotificationBroker
org.oasis_open.docs.wsn.brw_2.NotificationBroker port = ss.getCxfBinding();
src = new StreamSource(is);
epr = new W3CEndpointReference(src);
org.oasis_open.docs.wsn.b_2.Subscribe _subscribe_subscribeRequest = new org.oasis_open.docs.wsn.b_2.Subscribe();
TopicExpressionType topicExpression = new TopicExpressionType();
topicExpression.setDialect("http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple");
topicExpression.getContent().add("ExampleTopic");
_subscribe_subscribeRequest.setFilter(new FilterType());
JAXBElement<TopicExpressionType> elem = objectFactory.createTopicExpression(topicExpression);
_subscribe_subscribeRequest.getFilter().getAny().add(elem);
_subscribe_subscribeRequest.setConsumerReference(epr);
org.oasis_open.docs.wsn.b_2.SubscribeResponse _subscribe__return = port.subscribe(_subscribe_subscribeRequest);
System.out.println("subscribe.result=" + _subscribe__return);
wsa_infoset.xml is a file containing the following:
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Address>endpoint:http://example.com/wsn-consumer/NotificationConsumerService/NotificationConsumerPort</wsa:Address>
<wsa:ReferenceProperties></wsa:ReferenceProperties>
<wsa:ReferenceParameters>
</wsa:ReferenceParameters>
<wsa:Metadata
xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance"
xmlns:wsaw="http://www.w3.org/2005/02/addressing/wsdl"
xmlns:ns="http://example.com/wsn-consumer">
<wsaw:ServiceName EndpointName="NotificationConsumerPort">ns:NotificationConsumerService</wsaw:ServiceName>
</wsa:Metadata>
</wsa:EndpointReference>
Note that the address needs to correspond to the declarations in xbean.xml: endpoint:{namespace}/{service}/{endpoint}
3b) To publish a notification:
org.oasis_open.docs.wsn.b_2.Notify _notify_notify = new org.oasis_open.docs.wsn.b_2.Notify();
List<NotificationMessageHolderType> msgList = _notify_notify.getNotificationMessage();
NotificationMessageHolderType msg = new NotificationMessageHolderType();
msg.setTopic(new TopicExpressionType());
msg.getTopic().setDialect("http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple");
msg.getTopic().getContent().add("ExampleTopic");
msg.setMessage(new NotificationMessageHolderType.Message());
msg.getMessage().setAny(exampleMessage);
msgList.add(msg);
port.notify(_notify_notify);
I hope this will help someone.
Regards,
Anne Diefenbach
- FKIE-KOM -
*************************************************
Forschungsgesellschaft für
Angewandte Naturwissenschaften e. V. (FGAN)
Neuenahrer Str. 20, 53343 Wachtberg, Germany
E-Mail: diefenbach@fgan.de
Web: www.fgan.de
************************************************
Re: How to use the WSN Broker exposed by wsn-cxf-binding example
Posted by Freeman Fang <fr...@gmail.com>.
Thanks Anne, that's absolutely very helpful.
Best Regards
Freeman
Diefenbach Anne wrote:
> Hi everyone,
>
> having finally won (well, more or less) the fight to get my notification consumer up and running, I hope to be able to shorten the route for others attempting to do the same. So here's my HowTo:
>
> 1) Create a WSDL for your consumer service. For example: NotificationConsumer.wsdl (this WSDL was snagged from an IBM WebSphere tutorial)
>
> <?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="http://http://example.com/wsn-consumer"
> targetNamespace="http://example.com/wsn-consumer">
>
> <wsdl:import namespace="http://docs.oasis-open.org/wsn/bw-2"
> location="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://localhost:9080/WSNConsumer" />
> </wsdl:port>
> </wsdl:service>
>
> </wsdl:definitions>
>
> 2) Proxy your consumer service with the CXF BC. For this purpose, add to xbean.xml in wsn-cxf-binding-su the namespace xmlns:wsnc="http://example.com/wsn-consumer" and
>
> <cxfbc:provider wsdl="classpath:NotificationConsumer.wsdl"
> service="wsnc:NotificationConsumerService"
> endpoint="NotificationConsumerPort"
> interfaceName="wsn:NotificationConsumer"
> locationURI="http://localhost:9080/WSNConsumer"
> useJBIWrapper="false"
> useSOAPEnvelope="false"
> >
> <cxfbc:outInterceptors>
> <bean class="org.apache.servicemix.cxfbc.interceptors.JbiAddressingInterceptor"/>
> <bean class="org.apache.cxf.ws.addressing.soap.MAPCodec"/>
> </cxfbc:outInterceptors>
> </cxfbc:provider>
>
> I had a horrible fight with SMX about the location of NotificationConsumer.wsdl which it insisted on retrieving from the wsn-cxf-binding directory instead of the wsn-cxf-binding-su directory, where it uncomplainingly found broker.wsdl. I finally caved and placed a copy in wsn-cxf-binding.
>
> 3) Run wsdl2java for broker.wsdl and NotificationConsumer.wsdl and modify the code for your needs. Don't forget to add the object factory for your message (here: exampleMessage) to interfaces org.oasis_open.docs.wsn.bw_2.NotificationConsumer and org.oasis_open.docs.wsn.brw_2.NotificationBroker (one more entry for @XmlSeeAlso).
>
> I used Fuse Services Framework to build both notification consumer and producer, so the following code examples are specific for that.
>
> 3a) Create a subscription for your consumer (you may need to do some of this in a method, I had problems with non-static references in the static main method):
>
> ObjectFactory objectFactory = new ObjectFactory();
> W3CEndpointReference epr = null;
> InputStream is = org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_Server.class.getResourceAsStream("wsa_infoset.xml");
> StreamSource src;
>
> NotificationBroker ss = new NotificationBroker(wsdlURL, SERVICE_NAME); // org.servicemix.wsnotification.NotificationBroker
> org.oasis_open.docs.wsn.brw_2.NotificationBroker port = ss.getCxfBinding();
>
> src = new StreamSource(is);
> epr = new W3CEndpointReference(src);
>
> org.oasis_open.docs.wsn.b_2.Subscribe _subscribe_subscribeRequest = new org.oasis_open.docs.wsn.b_2.Subscribe();
> TopicExpressionType topicExpression = new TopicExpressionType();
> topicExpression.setDialect("http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple");
> topicExpression.getContent().add("ExampleTopic");
> _subscribe_subscribeRequest.setFilter(new FilterType());
> JAXBElement<TopicExpressionType> elem = objectFactory.createTopicExpression(topicExpression);
> _subscribe_subscribeRequest.getFilter().getAny().add(elem);
> _subscribe_subscribeRequest.setConsumerReference(epr);
>
> org.oasis_open.docs.wsn.b_2.SubscribeResponse _subscribe__return = port.subscribe(_subscribe_subscribeRequest);
> System.out.println("subscribe.result=" + _subscribe__return);
>
> wsa_infoset.xml is a file containing the following:
>
> <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
> <wsa:Address>endpoint:http://example.com/wsn-consumer/NotificationConsumerService/NotificationConsumerPort</wsa:Address>
> <wsa:ReferenceProperties></wsa:ReferenceProperties>
> <wsa:ReferenceParameters>
> </wsa:ReferenceParameters>
> <wsa:Metadata
> xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance"
> xmlns:wsaw="http://www.w3.org/2005/02/addressing/wsdl"
> xmlns:ns="http://example.com/wsn-consumer">
> <wsaw:ServiceName EndpointName="NotificationConsumerPort">ns:NotificationConsumerService</wsaw:ServiceName>
> </wsa:Metadata>
> </wsa:EndpointReference>
>
> Note that the address needs to correspond to the declarations in xbean.xml: endpoint:{namespace}/{service}/{endpoint}
>
> 3b) To publish a notification:
>
> org.oasis_open.docs.wsn.b_2.Notify _notify_notify = new org.oasis_open.docs.wsn.b_2.Notify();
> List<NotificationMessageHolderType> msgList = _notify_notify.getNotificationMessage();
> NotificationMessageHolderType msg = new NotificationMessageHolderType();
> msg.setTopic(new TopicExpressionType());
> msg.getTopic().setDialect("http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple");
> msg.getTopic().getContent().add("ExampleTopic");
> msg.setMessage(new NotificationMessageHolderType.Message());
> msg.getMessage().setAny(exampleMessage);
> msgList.add(msg);
> port.notify(_notify_notify);
>
> I hope this will help someone.
>
> Regards,
>
> Anne Diefenbach
> - FKIE-KOM -
> *************************************************
> Forschungsgesellschaft für
> Angewandte Naturwissenschaften e. V. (FGAN)
> Neuenahrer Str. 20, 53343 Wachtberg, Germany
> E-Mail: diefenbach@fgan.de
> Web: www.fgan.de
> ************************************************
>
>
>
>
--
Freeman Fang
------------------------
Open Source SOA: http://fusesource.com