>
> I have not solved the problem yet.
> my MyCapability's is as follows and I didn't change wsn-consumer' code
>
> package org.apache.ws.muse.test.wsrf;
>
> import java.io.File;
> import java.io.IOException;
>
> import javax.xml.namespace.QName;
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.ParserConfigurationException;
>
> import org.apache.muse.ws.addressing.soap.SoapFault;
> import org.apache.muse.ws.dm.muws.events.Component;
> import org.apache.muse.ws.dm.muws.events.ComponentAddress;
> import org.apache.muse.ws.dm.muws.events.ManagementEvent;
> import org.apache.muse.ws.dm.muws.events.Situation;
> import org.apache.muse.ws.dm.muws.events.WefConstants;
> import org.apache.muse.ws.dm.muws.events.WefFactory;
> import org.apache.muse.ws.dm.muws.events.impl.SimpleWefFactory;
> import org.apache.muse.ws.notification.NotificationProducer;
> import org.apache.muse.ws.notification.WsnConstants;
> import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> import org.xml.sax.SAXException;
>
> public class MyCapabilityImpl extends AbstractWsResourceCapability
> implements MyCapability
> {
> private static final QName[] _PROPERTIES = new QName[] {
> new QName(NAMESPACE_URI, "MessageInterval", PREFIX),
> new QName(NAMESPACE_URI, "ServerName", PREFIX)
> };
>
> private static final QName _TOPIC_NAME = new QName(NAMESPACE_URI,
> "MyTopic", PREFIX);
>
> public QName[] getPropertyNames()
> {
> return _PROPERTIES;
> }
>
> private int _MessageInterval = 10;
>
> private String _ServerName = "muse-test.apache.org";
>
> public int getMessageInterval()
> {
> return _MessageInterval;
> }
>
> public void setMessageInterval(int param0)
> {
> _MessageInterval = param0;
> }
>
> public String getServerName()
> {
> return _ServerName;
> }
>
> public void setServerName(String param0)
> {
> _ServerName = param0;
> }
>
> public void initializeCompleted()
> throws SoapFault
> {
> super.initializeCompleted();
>
> //
> // access resource's WSN capability and create a new topic
> //
> final NotificationProducer wsn =
> (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
> wsn.addTopic(_TOPIC_NAME);
>
> Thread producer = new Thread() {
> public void run()
> {
> //
> // for this example, reuse one payload for every
> notification
> //
> QName messageName = new QName(NAMESPACE_URI, "MyMessage",
> PREFIX);
> try
> {
> payload = runtimeEventOperation();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
>
> while (true)
> {
> try
> {
> //
> // read current value - property is mutable
> //
> int currentInterval = getMessageInterval();
> // System.out.println(payload);
>
> getLog().info("Waiting " + currentInterval + "
> seconds before sending message...");
> Thread.currentThread().sleep(currentInterval *
> 1000);
>
> //
> // use WSN capability to send message to any
> subscribers
> //
> getLog().info("Sending message to consumers...");
> wsn.publish(_TOPIC_NAME, payload);
> }
>
> catch (Throwable error)
> {
> error.printStackTrace();
> }
> }
> }
> };
> producer.start();
> }
> private static ManagementEvent payload;
> public ManagementEvent runtimeEventOperation() throws Exception{
> WefFactory factory = new SimpleWefFactory();
> ManagementEvent event = factory.createEvent();
>
> Component reporter = factory.createComponent();
> ComponentAddress reporterAddress =
> factory.createComponentAddress(getResource().getEndpointReference().toXML());
> reporter.setAddress(reporterAddress);
> reporter.setName(WefConstants.REPORTER_COMP_QNAME);
>
> Component source = factory.createComponent();
> ComponentAddress sourceAddress =
> factory.createComponentAddress(getResource().getEndpointReference().toXML());
> source.setAddress(sourceAddress);
> source.setName(WefConstants.SOURCE_COMP_QNAME);
>
> Situation situation = factory.createSituation();
>
> situation.setCategoryType(WefConstants.AVAILABILITY_SITUATION_QNAME);
> situation.setPriority(Situation.HIGH_PRIORITY);
> situation.setMessage("Something important has happened in the
> "+getServerName()+"!");
> event.setReporter(reporter);
> event.setSource(source);
> event.setSituation(situation);
>
> event.addExtendedElement(MessageExtension());
> return event;
> // try{
> // getLog().info("Sending message to consumers...");
> // runtimeNotification.publish(_TOPIC_NAME, event);
> // }
> // catch (Throwable error){
> // error.printStackTrace();
> // }
> // return event.toXML();
> }
>
> private Element MessageExtension()throws
> ParserConfigurationException, SAXException, IOException{
> // create your XML message
>
> File file = new
> File("E:/Awork/java/jakarta-tomcat-5.0.28/temp","test.xml");
> DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder db = dbf.newDocumentBuilder();
> Document doc = db.parse(file);
> doc.normalize();
> Element root = doc.getDocumentElement();
> return root;
> }
> }
>
> --
> View this message in context:
http://www.nabble.com/Transport-my-own-data-types--form-wsn-producer-to-wsn-consumer-tp23631392p23700618.html> Sent from the Muse User mailing list archive at Nabble.com.
>
>