here's a bit of code that I introduced in my test case.
public Element 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()+"!"); // this is your string only message
event.setReporter(reporter);
event.setSource(source);
event.setSituation(situation);
event.addExtendedElement(MessageExtension()); // this is where
you can put your XML, the standard allows for a xml extension
try{
runtimeNotification.publish(_TOPIC_NAME, event); // the actual
request to send the notification
}catch (Throwable error){
error.printStackTrace();
}
return event.toXML();
}
/////// an example that should give the rough idea of how to build a
wsn-producer
//
// MyCapability.java
// Thu Apr 05 11:59:12 BST 2007
// Generated by the Apache Muse Code Generation Tool
//
import javax.xml.namespace.QName;
import org.apache.muse.core.Resource;
import org.apache.muse.core.ResourceManager;
import org.apache.muse.util.xml.XmlUtils;
import org.apache.muse.ws.addressing.EndpointReference;
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.Element;
public class MyCapability extends AbstractWsResourceCapability
implements IMyCapability
{
private NotificationProducer runtimeNotification;
private static final QName _TOPIC_NAME = new QName(NAMESPACE_URI,
"RuntimeEvent", PREFIX);
/**
* Only internal objects are guarentied to be instantiated, do not
depend on objects/Capabilities outside this Capability
*/
public void initialize() throws SoapFault
{
super.initialize();
}
/**
* External capabilities are instantiated and can be used
*/
public void initializeCompleted()throws SoapFault{
super.initializeCompleted();
runtimeNotification =
(NotificationProducer
)getResource().getCapability(WsnConstants.PRODUCER_URI);
// add list of Topics if needed
runtimeNotification.addTopic(_TOPIC_NAME);
}
/**
* External capabilities are instantiated and can be used (last chance)
*/
public void prepareShutdown() throws SoapFault{
super.prepareShutdown();
}
/**
* Only internal objects are guaranteed to be instantiated, do not
depend on objects/Capabilities outside this Capability
*/
public void shutdown() throws SoapFault{
super.shutdown();
}
private static final QName[] _PROPERTIES = new QName[]
{
new QName(NAMESPACE_URI, "ServerName", PREFIX),
new QName(NAMESPACE_URI, "TestProperty", PREFIX),
new QName(NAMESPACE_URI, "MessageInterval", PREFIX)
};
public QName[] getPropertyNames()
{
return _PROPERTIES;
}
private String _ServerName = "WsSomething";
private String[] _TestProperty;
private int _MessageInterval = 0;
public String getServerName()
{
return _ServerName;
}
public void setServerName(String param0)
{
_ServerName = param0;
}
public String[] getTestProperty()
{
return _TestProperty;
}
public void setTestProperty(String[] param0)
{
_TestProperty = param0;
}
public int getMessageInterval()
{
return _MessageInterval;
}
public void setMessageInterval(int param0)
{
_MessageInterval = param0;
}
public Element 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());
try{
getLog().info("Sending message to consumers...");
runtimeNotification.publish(_TOPIC_NAME, event);
}catch (Throwable error){
error.printStackTrace();
}
return event.toXML();
}
private Element MessageExtension(){
// create your XML message
}
}
/Lenni
On May 20, 2009, at 10:47 GMT+02:00, ciel wrote:
Hello,sir,
I want to Transport my own data types form wsn-producer to wsn-
consumer,
such as follows:
package org.apache.ws.muse.test.wsrf;
class WsnTestDateType {
WsnTestDateType (){};
WsnTestDateType (int ID, String name){
this.ID = ID;
this.name = name;
}
public int getID() {
return ID;
}
public void setID(int id) {
ID = id;
}
public String getName() {
return name;
}
public void setName(String name) {
WsnTestDateType.name = name;
}
private static int ID;
private static String name;
}
If I have done this
WsnTestDateType studentMessage = new WsnTestDateType (int ID, String
name)(int ID, String name);
How could I use wsn.publish(_TOPIC_NAME, payload) to set
studentMessage to
wsn-consumer and receive it? Any examples?
Besides, if I replace WsnTestDateType with a xml document as
follows, how
should I do?
//stuService.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns:stuInfo
xmlns:ns="http://localhost:8080/stuService.xsd"><ns:shipmentID>1</
ns:shipmentID>
<ns:stuID>25</ns:stuID>
<ns:stuName>Joe</ns:stuName>
</ns:stuInfo>
//stuService.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://localhost:8080/stuService.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://localhost:8080/stuService.xsd"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="stuInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="stuID" type="xsd:int"/>
<xsd:element name="stuName" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Thanks very much. I am looking forward to your reply.
--
View this message in context:
http://www.nabble.com/Transport-my-own-data-types--form-wsn-producer-to-wsn-consumer-tp23631392p23631392.html
Sent from the Muse User mailing list archive at Nabble.com.