您的位置:首页 > 其它

IBM WebSphere Sensor Events -GATEWAY

2011-11-16 23:35 465 查看
WebSphere® Sensor Events provides a gateway Web services interface for you to write and send events.

To avoid overloading, two methods for the gateway Web service are provided:
public int publish (string sensoreventXML);
public int sensoreventpublish (string eventType , string eventTopic ,string sensoreventXML);


Return codes:
0: success
-1: failure
-2: deadletter


Web service endpoint: http://localhost:port/ibmse/services/EventPublish

Web service WSDL: http://localhost:port//ibmse/services/EventPublish?wsdl


Example of the gateway Web service WSDL

/**********************************************************************************
* Licensed Materials - Property of IBM
* 5724-Y62 WebSphere Sensor Events
* (c) Copyright IBM Corp. 2008, 2009  All rights reserved.
*
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
*
* DISCLAIMER OF WARRANTIES.  The following code is sample code created by
* IBM Corporation.  This sample code is part of the WebSphere Sensor Events
* and is warranted to perform its intended function only if used un-modified.
* If you modify this code then it is considered provided "AS IS", without
* warranty of any kind.  Notwithstanding the foregoing, IBM shall not be liable
* for any damages arising out of your use of the sample code, even if they have
* been advised of the possibility of such damages.
***********************************************************************************/
package com.ibm.sensorevent.ws.simulator;

import java.io.Serializable;

import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Call;
import javax.xml.rpc.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

import com.ibm.sensorevent.model.IBMSensorEvent;
import com.ibm.sensorevent.model.ISensorEvent;
import com.ibm.sensorevent.model.converter.CBEConverter;
import com.ibm.sensorevent.model.payload.PortalReportPayload;

public class publishClient  implements Serializable {
private static final long serialVersionUID = 0L;
public static String wsdlURL="http://localhost:9080/ibmse/services/EventPublish?wsdl";
public static String endpoint="http://localhost:9080/ibmse/services/EventPublish";

public publishClient(){
super();
}

public String createSensorEvent() {
String xml = null;
try {
ISensorEvent ise = IBMSensorEvent.getPortalReportInstance("EDDR/report/portal");
ise.getHeader().setSourceId("P2");

PortalReportPayload payload = (PortalReportPayload) ise.getPayload();
payload.setValue("ON");

System.out.println(ise);
System.out.println();
CBEConverter converter = CBEConverter.getInstance();
xml = converter.toXMLString(ise);
} catch (Exception e) {
e.printStackTrace();
}

return xml;

}

public void DIIPublish(String xml) {
try{
// publish to sensor event web service
// Define the service.

QName serviceName = new QName("http://gateway.sensorevent.ibm.com","EventPublishService");
Service service = ServiceFactory.newInstance().createService(serviceName);
Call call = (Call) service.createCall();
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
call.setProperty(Call.OPERATION_STYLE_PROPERTY, "wrapped");
call.setTargetEndpointAddress(endpoint);
call.removeAllParameters();
QName portName = new QName("http://gateway.sensorevent.ibm.com","EventPublish");
call.setPortTypeName(portName);
QName operationName = new QName("http://gateway.sensorevent.ibm.com", "publish");
call.setOperationName(operationName);
call.addParameter(
"sensoreventXML",   // parameter name
XMLType.XSD_STRING, // parameter XML type QName
String.class,       // parameter Java type class
ParameterMode.IN);  // parameter mode
call.setReturnType(XMLType.XSD_STRING);
Object[] args = { xml };
System.out.println("response = " + (String) call.invoke(args));
catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
publishClient client = new publishClient();
String eventxml = client.createSensorEvent();
client.DIIPublish(eventxml);
}
}



Example of a Java™ client using the gateway Web service

/**********************************************************************************
* Licensed Materials - Property of IBM
* 5724-Y62 WebSphere Sensor Events
* (c) Copyright IBM Corp. 2008, 2009  All rights reserved.
*
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
*
* DISCLAIMER OF WARRANTIES.  The following code is sample code created by
* IBM Corporation.  This sample code is part of the WebSphere Sensor Events
* and is warranted to perform its intended function only if used un-modified.
* If you modify this code then it is considered provided "AS IS", without
* warranty of any kind.  Notwithstanding the foregoing, IBM shall not be liable
* for any damages arising out of your use of the sample code, even if they have
* been advised of the possibility of such damages.
***********************************************************************************/
package com.ibm.sensorevent.ws.simulator;

import java.io.Serializable;

import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Call;
import javax.xml.rpc.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

import com.ibm.sensorevent.model.IBMSensorEvent;
import com.ibm.sensorevent.model.ISensorEvent;
import com.ibm.sensorevent.model.converter.CBEConverter;
import com.ibm.sensorevent.model.payload.PortalReportPayload;

public class publishClient  implements Serializable {

private static final long serialVersionUID = 0L;
public static String wsdlURL="http://localhost:9082/ibmse/services/EventPublish?wsdl";
public static String endpoint="http://localhost:9082/ibmse/services/EventPublish";
/**
* @param args
*/
public publishClient(){
super();
}

public String createSensorEvent (){
String xml = null;
try{
ISensorEvent ise = IBMSensorEvent.getPortalReportInstance("EDDR/report/portal");

ise.getHeader().setAssetId("ASSED_ID_VALUE");
//ise.getHeader().setEventType("EDDR/report/portal");
ise.getHeader().setGeoLocation("GEO_LOCATION_VALUE");
ise.getHeader().setOriginatingEventId("ORIGINATING_EVENT_ID_VALUE");
ise.getHeader().setPriority((short) 75);
ise.getHeader().setSourceId("P2");
//ise.getHeader().setTargetId("PremisesServer");
ise.getHeader().setDateTime(System.currentTimeMillis());

PortalReportPayload payload = (PortalReportPayload) ise.getPayload();
payload.setValue("ON");

System.out.println(ise);
System.out.println();
CBEConverter converter = CBEConverter.getInstance();
xml = converter.toXMLString(ise);
//System.out.println(xml);
} catch ( Exception e){
//System.out.println("exception = " + e.getMessage());
e.printStackTrace();
}

return xml;

}

public void DIIPublish(String xml){
try{
// publish to sensor event web service
// Define the service.

QName serviceName = new QName("http://gateway.sensorevent.ibm.com","EventPublishService");
Service service = ServiceFactory.newInstance().createService(serviceName);
Call call = (Call) service.createCall();
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
call.setProperty(Call.OPERATION_STYLE_PROPERTY, "wrapped");
call.setTargetEndpointAddress(endpoint);
call.removeAllParameters();
QName portName = new QName("http://gateway.sensorevent.ibm.com","EventPublish");
call.setPortTypeName(portName);
QName operationName = new QName("http://gateway.sensorevent.ibm.com", "publish");
call.setOperationName(operationName);
call.addParameter(
"sensoreventXML",   // parameter name
XMLType.XSD_STRING, // parameter XML type QName
String.class,       // parameter Java type class
ParameterMode.IN);  // parameter mode
call.setReturnType(XMLType.XSD_STRING);
Object[] args = { xml };
System.out.println("response = " + (String) call.invoke(args));

} catch ( Exception e){
//System.out.println("exception = " + e.getMessage());
e.printStackTrace();
}

}

public static void main(String[] args) {
publishClient client = new publishClient();
String eventxml = client.createSensorEvent();
client.DIIPublish(eventxml);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: