WebSphere brand IBM WebSphere Premises Server, Version 6.1.x

Event gateway servlet

The event gateway servlet is only for sensor events upstream to WebSphere® Premises Server.

If you want to send events downstream to Data Capture and Delivery, use the WebSphere Premises Server application program interface (API). For more information on using the APIs, refer to the WebSphere Premises Server API documentation.

Event gateway servlet code:

HTTP Get 
http://premises_host:premises_port/ibmse/eventpublish?eventtype=
eventtype&eventtopic=topicname&eventxml=eventstring  
HTTP Post 
Form Action: /ibmse/eventpublish 
Parameter: eventtype 
Parameter: eventtopic 
Parameter: eventxml

Response if the event XML is null:

SC_BAD_REQUEST (400) and no message body.

Response if the event XML is not sensor event XML:

SC_OK (200) and message body is “Can not convert event xml to sensor event object. 
Publish to deadletter topic”.

Response if the event XML is sensor event XML:

SC_OK (200) and message body is “Publish event to topic topic_name"

Example of a Java™ client using the event gateway servlet

/**********************************************************************************
 * Licensed Materials - Property of IBM
 * 5724-L17 WebSphere Premises Server
 * (c) Copyright IBM Corp. 2008  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 Premises Server 
 * 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.servlet.simulator;

import com.ibm.sensorevent.model.ISensorEvent;
import com.ibm.sensorevent.model.IBMSensorEvent;
import com.ibm.sensorevent.model.converter.CBEConverter;
import com.ibm.sensorevent.model.payload.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.DataOutputStream;

public class ApplicationPingEventServletClientTester {
	private final static String urlString = "http://localhost:9080/ibmse/eventpublish";
	public final static String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
	public final static String CONTENT_TYPE_XML = "text/xml";
	
	public static void main(String args[]) {
		try {
			ISensorEvent ise = IBMSensorEvent.getApplicationPingInstance();			
			ise.getHeader().setSourceId("E2");		
			ApplicationPingPayload payload = (ApplicationPingPayload) ise.getPayload();
			payload.setValue("1,Edge_EdgeName1 (E1)-2007-10-17T0:56:49.176");
			System.out.println(ise);
			System.out.println();
			
			CBEConverter converter = CBEConverter.getInstance();
			String xml = converter.toXMLString(ise);
			
			URL url = new URL(urlString);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("POST");
			connection.setRequestProperty("Content-Type", CONTENT_TYPE_FORM);
			connection.setUseCaches(false);
			connection.setDoInput(true);
			connection.setDoOutput(true);
			connection.connect();

			StringBuffer data = new StringBuffer();		
			data.append("eventXml=" + URLEncoder.encode(xml, "UTF-8"));
			DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
		    dos.writeBytes(data.toString());
			dos.flush();
			dos.close();
						
			System.out.println("result code: " + connection.getResponseCode() + " " + connection.getResponseMessage() );
			if (connection.getResponseCode() == 200) {
				InputStreamReader in = new InputStreamReader(connection.getInputStream());
				BufferedReader dis = new BufferedReader(in);
				System.out.println("result: " + dis.readLine());
			}			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Library | Support | Terms of use

(c) Copyright IBM Corporation 2004, 2008. All rights reserved.
U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.