The Enterprise Business Logic application submits events to the WebSphere® Premises Server using WebSphere Premises Server API and IBM® Sensor Events.
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess();
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess(<Server Name>)
premisesAccess.startLocation(locationid);
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess();
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess(<Server Name>)
premisesAccess.stopLocation(locationid);
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess();
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess(<Server Name>)
premisesAccess. sendAcceptToLightStack (locationid);
PremisesAccess premisesAccess = PremisesContext.getPremisesAccess();
To get premisesaccess object in the case of WebSphere Premises Server is remote to the EBL. PremisesAccess premisesAccess = PremisesContext.getPremisesAccess(<Server Name>)
premisesAccess. sendRejectToLightStack (locationid);
In order to process Application Ping and send ApplPong to Data Capture and Delivery, you need to develop new MDB. The following is a sample of MDB code. The sample requires IBM_RFID_HOME\RFID\premises\api\lib\ibmse_event_model.jar and IBM_RFID_HOME\RFID\premises\api\lib\ibmse_event_model_uuid.jar as J2EE Module Dependencies.
/********************************************************************************** * 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. ***********************************************************************************/ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Hashtable; import javax.jms.JMSException; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.TextMessage; import javax.naming.InitialContext; import javax.naming.NamingException; import com.ibm.sensorevent.model.IBMSensorEvent; import com.ibm.sensorevent.model.IConstants; import com.ibm.sensorevent.model.ISensorEvent; import com.ibm.sensorevent.model.converter.XMLConverter; import com.ibm.sensorevent.model.generic.SensorEventException; import com.ibm.sensorevent.model.payload.ApplicationPongPayload; /** * Bean implementation class for Enterprise Bean: SimulatedBusBackEnd */ public class SimulatedBusBackEndBean implements javax.ejb.MessageDrivenBean,javax.jms.MessageListener { private static final long serialVersionUID = 6285653378773758308L; private javax.ejb.MessageDrivenContext fMessageDrivenCtx; private static final String VALUE = "value"; private static final String RESPONSE_QUEUE_NAME = "ENTERPRISE.IN.Q"; private static final String RESPONSE_VALUE = "REJECTED"; private static final String RESPONSE_PARAMETER = "IBMSE_EBL_TEST_RESPONSE"; private static final String TAG_REPORT = "TagReport"; private static final String TAG_AGGREGATION_REPORT = "TagAggregationReport"; private static final String TAG_FEEDBACK_EVENT_TYPE_SUFFIX = "/report/tag/feedback"; private static final String APP_PONG_EVENT_TYPE_SUFFIX = "/dccontroller/report/diagnostic/applpong"; private static final String APP_PING = "applping"; private static final String CLASS_NAME = "com.ibmse.ebl.test.SimulatedBusBackEndBean"; private Logger logger = Logger.getLogger(CLASS_NAME); protected InitialContext context; private static Hashtable<String,Object> jndiObjects ; private static final String QCF_JNDI_NAME="jms/ibmsensoreventQCF"; private static final String Queue_JNDI_NAME="jms/enterprise.in.bus.q"; /** * getMessageDrivenContext */ public javax.ejb.MessageDrivenContext getMessageDrivenContext() { return fMessageDrivenCtx; } /** * setMessageDrivenContext */ public void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx) { fMessageDrivenCtx = ctx; } /** * ejbCreate */ public void ejbCreate() { } /** * onMessage */ public void onMessage(javax.jms.Message msg) { String incomingXML; try { incomingXML = ((TextMessage) msg).getText(); if (logger.isLoggable(Level.FINE)) logger.fine("received message XML: "+incomingXML); // Investigate incoming message XMLConverter converter = (XMLConverter)XMLConverter.getInstance(); ISensorEvent fromPremISE = converter.toIBMSensorEvent(incomingXML); // Process EventType String originatingEventType = fromPremISE.getHeader().getEventType(); if(originatingEventType.indexOf(APP_PING)!=-1) { sendApplicationPong(fromPremISE); } } catch (JMSException e) { e.printStackTrace(); } catch (SensorEventException e) { e.printStackTrace(); } } /** * ejbRemove */ public void ejbRemove() { } /** * sendApplicationPong * @param fromPremISE */ public void sendApplicationPong(ISensorEvent fromPremISE) { try { String originatingEventId = fromPremISE.getHeader().getEventId(); // Create response XML ISensorEvent responseISE = IBMSensorEvent.getApplicationPongInstance(APP_PONG_EVENT_TYPE_SUFFIX); responseISE.getHeader().setAssetId(fromPremISE.getHeader().getAssetId()); responseISE.getHeader().setGeoLocation(fromPremISE.getHeader().getGeoLocation()); responseISE.getHeader().setOriginatingEventId(originatingEventId); responseISE.getHeader().setPriority(IConstants.PRIORITY_DEFAULT); responseISE.getHeader().setSourceId(fromPremISE.getHeader().getTargetId()); responseISE.getHeader().setTargetId(fromPremISE.getHeader().getSourceId()); ApplicationPongPayload newpayload = (ApplicationPongPayload) responseISE.getPayload(); String eventType = fromPremISE.getHeader().getEventType(); String pingValue = fromPremISE.getPayload().getGroup(eventType).getStringAttributeValue(VALUE); newpayload.setValue(pingValue + getApplicationPingEntry()); XMLConverter converter = (XMLConverter)XMLConverter.getInstance(); String responseXML = converter.toXMLString(responseISE); if (logger.isLoggable(Level.FINE)) logger.fine("response XML: "+responseXML); // Send response XML // MQHelper.send(RESPONSE_QUEUE_NAME, responseXML); send(responseXML); } catch (SensorEventException e) { e.printStackTrace(); } if (logger.isLoggable(Level.FINE)) logger.exiting(CLASS_NAME, "sendApplicationPong"); } /** * getApplicationPingEntry * @return */ private String getApplicationPingEntry(){ String entry= ", Premises"; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); String dateTime = formatter.format(new Date()); entry+= "-" + dateTime; return entry; } private void send(String msg){ QueueConnection queueConnection = null; QueueSession queueSession = null; QueueSender queueSender = null; try{ QueueConnectionFactory connectionFactory = (QueueConnectionFactory)getRemoteObject(QCF_JNDI_NAME); Queue queue = (Queue)getRemoteObject(Queue_JNDI_NAME); queueConnection = connectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); TextMessage message = queueSession.createTextMessage(msg); queueConnection.start(); queueSender.send(message); } catch(Exception e ) { e.printStackTrace(); } finally { if(queueSender != null) { try { queueSender.close(); } catch(Exception e) { } } if(queueConnection != null) { try { queueSession.close(); } catch(Exception e) { } } if(queueConnection != null) { try { queueConnection.close(); } catch(Exception e) { } } } } protected Object getRemoteObject(String ejbRef) throws Exception { synchronized (this) { if (jndiObjects == null) { jndiObjects = new Hashtable<String,Object>(); } } synchronized (jndiObjects) { if (jndiObjects.containsKey(ejbRef)) { return jndiObjects.get(ejbRef); } } Object obj = null; synchronized (jndiObjects) { // defect 146354 try { obj = getInitialContext().lookup("java:comp/env/" + ejbRef); } catch(Exception e) { obj = getInitialContext().lookup(ejbRef); } //obj = getInitialContext().lookup(ejbRef); jndiObjects.put(ejbRef, obj); } return obj; } protected synchronized InitialContext getInitialContext() throws NamingException { if(context == null) { context = new InitialContext(); } return context; } }