List of usage examples for javax.jms ObjectMessage getObject
Serializable getObject() throws JMSException;
From source file:org.fuin.auction.query.server.AuctionMessageListener.java
@Override @Transactional(propagation = Propagation.REQUIRES_NEW) public final void onMessage(final Message message) { if (LOG.isDebugEnabled()) { LOG.debug(message.toString());/*from w w w . ja va 2 s .c o m*/ } try { if (message instanceof ObjectMessage) { final ObjectMessage objectMessage = (ObjectMessage) message; try { final Serializable obj = objectMessage.getObject(); if (obj instanceof CategoryCreatedMessage) { handleMessage((CategoryCreatedMessage) obj); } else if (obj instanceof CategoryMarkedForDeletionMessage) { handleMessage((CategoryMarkedForDeletionMessage) obj); } else if (obj instanceof CategoryDeletedMessage) { handleMessage((CategoryDeletedMessage) obj); } else if (obj instanceof UserRegisteredMessage) { handleMessage((UserRegisteredMessage) obj); } else if (obj instanceof UserEmailVerifiedMessage) { handleMessage((UserEmailVerifiedMessage) obj); } else if (obj instanceof UserPasswordChangedMessage) { handleMessage((UserPasswordChangedMessage) obj); } else { LOG.warn("Received non-Auction message: " + obj); } } catch (final JMSException ex) { LOG.error("Error reading object from message", ex); } } else { LOG.warn("Received non-Object message: " + message); } } catch (final RuntimeException ex) { LOG.error("Error handling message", ex); } }
From source file:it.cnr.isti.labse.glimpse.impl.ComplexEventProcessorImpl.java
@Override public void onMessage(Message arg0) { ObjectMessage msg = (ObjectMessage) arg0; try {// w ww . j a v a 2 s . c om GlimpseBaseEvent<?> receivedEvent = (GlimpseBaseEvent<?>) msg.getObject(); if (eventStream != null) { try { eventStream.insert(receivedEvent); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives: " + receivedEvent.getData() + " from: " + receivedEvent.getConnectorID() + " execution: " + receivedEvent.getConnectorInstanceID()); DebugMessages.line(); } catch (org.drools.RuntimeDroolsException droolsCrashException) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), droolsCrashException.getMessage()); new UnknownMethodCallRuleException(); } } } catch (JMSException e) { e.printStackTrace(); } catch (ClassCastException ex) { } }
From source file:eu.learnpad.simulator.mon.impl.ComplexEventProcessorImpl.java
@Override public void onMessage(Message arg0) { ObjectMessage msg = (ObjectMessage) arg0; try {// w ww . j a va2 s . c o m GlimpseBaseEvent<?> receivedEvent = (GlimpseBaseEvent<?>) msg.getObject(); if (eventStream != null && receivedEvent != null) { try { eventStream.insert(receivedEvent); if (receivedEvent instanceof GlimpseBaseEventBPMN<?>) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives:\n" + "eventData: " + receivedEvent.getEventData() + "\n" + "eventName: " + receivedEvent.getEventName() + "\n" + "timestamp: " + receivedEvent.getTimeStamp() + "\n" + "event: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getEvent()); } else { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives:\n" + "eventData: " + receivedEvent.getEventData() + "\n" + "eventName: " + receivedEvent.getEventName() + "\n" + "timestamp: " + receivedEvent.getTimeStamp()); } DebugMessages.line(); } catch (org.drools.RuntimeDroolsException droolsCrashException) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), droolsCrashException.getMessage()); new UnknownMethodCallRuleException(); } } } catch (JMSException e) { e.printStackTrace(); } catch (ClassCastException ex) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), ex.getMessage()); } }
From source file:it.geosolutions.geoserver.jms.client.JMSQueueListener.java
@Override public void onMessage(Message message, Session session) throws JMSException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message event for session: " + session.toString()); }//from w w w . j av a 2 s . com // CHECKING LISTENER STATUS if (!isEnabled()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message is swallowed since this component is disabled"); } return; } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.INSTANCE_NAME_KEY)) { throw new JMSException("Unable to handle incoming message, property \'" + JMSConfiguration.INSTANCE_NAME_KEY + "\' not set."); } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.GROUP_KEY)) { throw new JMSException( "Unable to handle incoming message, property \'" + JMSConfiguration.GROUP_KEY + "\' not set."); } // check if message comes from a master with the same name of this slave if (message.getStringProperty(JMSConfiguration.INSTANCE_NAME_KEY) .equals(config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY))) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: source is equal to destination"); } // if so discard the message return; } // check if message comes from a different group final String group = message.getStringProperty(JMSConfiguration.GROUP_KEY); final String localGroup = config.getConfiguration(JMSConfiguration.GROUP_KEY); if (!group.equals(localGroup)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: incoming group-->" + group + " is different from the local one-->" + localGroup); } // if so discard the message return; } // check the property which define the SPI used (to serialize on the // server side). if (!message.propertyExists(JMSEventHandlerSPI.getKeyName())) throw new JMSException("Unable to handle incoming message, property \'" + JMSEventHandlerSPI.getKeyName() + "\' not set."); // END -> FILTERING INCOMING MESSAGE // get the name of the SPI used to serialize the message final String generatorClass = message.getStringProperty(JMSEventHandlerSPI.getKeyName()); if (generatorClass == null || generatorClass.isEmpty()) { throw new IllegalArgumentException("Unable to handle a message without a generator class name"); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Incoming message was serialized using an handler generated by: \'" + generatorClass + "\'"); } // USING INCOMING MESSAGE if (message instanceof ObjectMessage) { final ObjectMessage objMessage = (ObjectMessage) (message); final Serializable obj = objMessage.getObject(); try { // lookup the SPI handler, search is performed using the // name final JMSEventHandler<Serializable, Object> handler = jmsManager .getHandlerByClassName(generatorClass); if (handler == null) { throw new JMSException("Unable to find SPI named \'" + generatorClass + "\', be shure to load that SPI into your context."); } final Enumeration<String> keys = message.getPropertyNames(); final Properties options = new Properties(); while (keys.hasMoreElements()) { String key = keys.nextElement(); options.put(key, message.getObjectProperty(key)); } handler.setProperties(options); // try to synchronize object locally if (!handler.synchronize(handler.deserialize(obj))) { throw new JMSException("Unable to synchronize message locally.\n SPI: " + generatorClass); } } catch (Exception e) { final JMSException jmsE = new JMSException(e.getLocalizedMessage()); jmsE.initCause(e); throw jmsE; } } else throw new JMSException("Unrecognized message type for catalog incoming event"); }
From source file:it.cnr.isti.labsedc.glimpse.impl.ComplexEventProcessorImpl.java
@Override public void onMessage(Message arg0) { ObjectMessage msg = (ObjectMessage) arg0; try {//from www . j a v a2 s . c o m GlimpseBaseEvent<?> receivedEvent = (GlimpseBaseEvent<?>) msg.getObject(); if (eventStream != null && receivedEvent != null) { try { eventStream.insert(receivedEvent); if (receivedEvent instanceof GlimpseBaseEventChoreos<?>) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives:\n" + "eventData: " + receivedEvent.getEventData() + "\n" + "eventName: " + receivedEvent.getEventName() + "\n" + "timestamp: " + receivedEvent.getTimeStamp() + "\n" + "machineIP: " + ((GlimpseBaseEventChoreos<?>) receivedEvent).getMachineIP() + "\n" + "choreographySource: " + ((GlimpseBaseEventChoreos<?>) receivedEvent).getChoreographySource()); } else if (receivedEvent instanceof GlimpseBaseEventBPMN<?>) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives:\n" + "eventData: " + receivedEvent.getEventData() + "\n" + "eventName: " + receivedEvent.getEventName() + "\n" + "timestamp: " + receivedEvent.getTimeStamp() + "\n" + "sessionID: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getSessionID() + "\n" + "assigneeID: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getAssigneeID() + "\n" + "roleID: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getRoleID() + "\n" + "taskID: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getTaskID() + "\n" + "subProcessID: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getSubProcessID() + "\n" + "desideredCompletionTime: " + ((GlimpseBaseEventBPMN<?>) receivedEvent).getDesideredCompletionTime()); } else { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receives:\n" + "eventData: " + receivedEvent.getEventData() + "\n" + "eventName: " + receivedEvent.getEventName() + "\n" + "timestamp: " + receivedEvent.getTimeStamp()); } DebugMessages.line(); } catch (org.drools.RuntimeDroolsException droolsCrashException) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), droolsCrashException.getMessage()); new UnknownMethodCallRuleException(); } } } catch (JMSException e) { e.printStackTrace(); } catch (ClassCastException ex) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), ex.getMessage()); } }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityJMSMessageParser.java
/** * Parse JMS {@link ObjectMessage} activity info into activity data map. * * @param objMessage/*from w w w. ja va 2 s.c om*/ * JMS object message * @param dataMap * activity data map collected from JMS {@link ObjectMessage} * @throws JMSException * if JMS exception occurs while getting {@link Serializable} object from message. */ protected void parseObjectMessage(ObjectMessage objMessage, Map<String, Object> dataMap) throws JMSException { Serializable serializableObj = objMessage.getObject(); if (serializableObj != null) { dataMap.put(StreamsConstants.ACTIVITY_DATA_KEY, serializableObj); } }
From source file:drepcap.frontend.jms.JmsAdapter.java
public void startReceiveData() throws JMSException { dataTopic = session.createTopic(componentName + ".data"); dataConsumer = session.createConsumer(dataTopic); dataConsumer.setMessageListener(new MessageListener() { @Override/*from w w w . j ava 2s . c om*/ public void onMessage(Message msg) { for (ByteArrayReceiver baDataReceiver : byteArrayDataReceivers) { if (baDataReceiver != null && msg instanceof BytesMessage) { BytesMessage bMsg = (BytesMessage) msg; try { byte[] data = new byte[(int) bMsg.getBodyLength()]; bMsg.readBytes(data); baDataReceiver.process(data); } catch (JMSException e) { e.printStackTrace(); } } } for (ObjectReceiver objReceiver : objectReceivers) { if (objReceiver != null && msg instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) msg; try { objReceiver.process(objMsg.getObject()); } catch (JMSException e) { e.printStackTrace(); } } } } }); }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.SigningServerResponsesMessageListener.java
@Override public void onMessage(final Message message) { try {//from w w w . j a v a 2 s. co m LOGGER.info("Received message of type: {}", message.getJMSType()); final ObjectMessage objectMessage = (ObjectMessage) message; final String messageType = objectMessage.getJMSType(); final String correlationId = objectMessage.getJMSCorrelationID(); final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION); final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject(); final ResponseMessageResultType result = responseMessage == null ? null : responseMessage.getResult(); // Check the result. if (result.equals(ResponseMessageResultType.NOT_OK)) { LOGGER.error("OslpEnvelope was not signed by signing-server. Unable to send request to device: {}", deviceIdentification); this.oslpSigningService.handleError(deviceIdentification, responseMessage); return; } LOGGER.info("messageType: {}, deviceIdentification: {}, result: {}, correlationId: {}", messageType, deviceIdentification, result, correlationId); // Get the DTO object containing signed OslpEnvelope. final SignedOslpEnvelopeDto signedOslpEnvelopeDto = (SignedOslpEnvelopeDto) responseMessage .getDataObject(); this.oslpSigningService.handleSignedOslpEnvelope(signedOslpEnvelopeDto, deviceIdentification); } catch (final JMSException ex) { LOGGER.error("Exception: {} ", ex.getMessage(), ex); } }
From source file:com.chakray.chilcano.wso2.rabbitmq.message.store.RabbitMQConsumer.java
public MessageContext receive() { boolean error; JMSException exception;/*from w ww. j a v a 2 s .c om*/ if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Cannot reconnect."); } return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } if (!checkConnection()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store."); } return null; } try { Message message = consumer.receive(3000); if (message == null) { return null; } if (!(message instanceof ObjectMessage)) { logger.warn(getId() + ". Did not receive a javax.jms.ObjectMessage"); message.acknowledge(); // TODO: return null; } ObjectMessage msg = (ObjectMessage) message; String messageId = msg.getStringProperty(Constants.OriginalMessageID); if (!(msg.getObject() instanceof StorableMessage)) { logger.warn(getId() + ". Did not receive a valid message."); message.acknowledge(); return null; } StorableMessage storableMessage = (StorableMessage) msg.getObject(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(message, synapseMc, messageId, false); if (logger.isDebugEnabled()) { logger.debug( getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority()); } return synapseMc; } catch (JMSException e) { error = true; exception = e; } if (error) { if (!isReceiveError) { logger.error( getId() + " cannot receive message from store. Error:" + exception.getLocalizedMessage());//, exception); } updateCache(null, null, "", true); cleanup(); return null; } return null; }
From source file:com.cws.esolutions.agent.mq.MQMessageHandler.java
public void onMessage(final Message message) { final String methodName = MQMessageHandler.CNAME + "#onMessage(final Message message)"; if (DEBUG) {//from w w w . j a v a 2 s.c om DEBUGGER.debug(methodName); DEBUGGER.debug("Message: {}", message); } final Session session = agentBean.getSession(); final MessageProducer producer = agentBean.getProducer(); final Destination destination = MQMessageHandler.agentBean.getResponseQueue(); if (DEBUG) { DEBUGGER.debug("Session: {}", session); DEBUGGER.debug("MessageProducer: {}", producer); DEBUGGER.debug("Destination: {}", destination); } try { ObjectMessage mqMessage = (ObjectMessage) message; if (DEBUG) { DEBUGGER.debug("mqMessage: {}", mqMessage); } if ((StringUtils.equals(MQMessageHandler.serverConfig.getRequestQueue(), MQMessageHandler.serverConfig.getResponseQueue())) && (mqMessage.getObject() instanceof AgentResponse)) { return; } AgentRequest agentRequest = (AgentRequest) mqMessage.getObject(); if (DEBUG) { DEBUGGER.debug("agentRequest: {}", agentRequest); } mqMessage.acknowledge(); AgentResponse agentResponse = MQMessageHandler.processor.processRequest(agentRequest); if (DEBUG) { DEBUGGER.debug("AgentResponse: {}", agentResponse); } ObjectMessage oMessage = session.createObjectMessage(true); oMessage.setObject(agentResponse); oMessage.setJMSCorrelationID(message.getJMSCorrelationID()); if (DEBUG) { DEBUGGER.debug("ObjectMessage: {}", oMessage); } producer.send(destination, oMessage); } catch (JMSException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); } catch (AgentException ax) { ERROR_RECORDER.error(ax.getMessage(), ax); } }