List of usage examples for javax.jms ObjectMessage setObject
void setObject(Serializable object) throws JMSException;
From source file:org.audit4j.core.AsyncAuditEngine.java
/** * Send./*from w w w . j a va 2 s .c o m*/ * * @param t * the t */ public void send(final Serializable t) { try { final MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); final ObjectMessage objectMessage = session.createObjectMessage(); objectMessage.setObject(t); // Tell the producer to send the message System.out.println("Sent message: " + t.hashCode()); producer.send(objectMessage); } catch (final Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.probe.GlimpseAbstractProbe.java
/** * This method send a {@link GlimpseBaseEvent} message on the ESB<br /> * specifically on the channel specified in the {@link #settings} object. * /*from ww w . j a v a2 s . c o m*/ * @param event the event to send * @param debug * @throws JMSException * @throws NamingException */ protected void sendEventMessage(GlimpseBaseEventAbstract<?> event, boolean debug) throws JMSException, NamingException { if (debug) { DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating Message "); } try { ObjectMessage messageToSend = publishSession.createObjectMessage(); messageToSend.setJMSMessageID(String.valueOf(MESSAGEID++)); messageToSend.setObject(event); if (debug) { DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Publishing message "); } tPub.publish(messageToSend); if (debug) { DebugMessages.ok(); DebugMessages.line(); } } catch (JMSException e) { e.printStackTrace(); } }
From source file:org.mule.transport.jms.integration.JmsTransformersTestCase.java
@Test public void testTransformObjectMessage() throws Exception { RequestContext.setEvent(getTestEvent("test")); ObjectMessage oMsg = session.createObjectMessage(); File f = FileUtils.newFile("/some/random/path"); oMsg.setObject(f); AbstractJmsTransformer trans = createObject(JMSMessageToObject.class); Object result = trans.transform(oMsg); assertTrue("Transformed object should be a File", result.getClass().equals(File.class)); AbstractJmsTransformer trans2 = new SessionEnabledObjectToJMSMessage(session); trans2.setReturnDataType(DataTypeFactory.create(ObjectMessage.class)); initialiseObject(trans2);/*from www. j a v a 2 s. com*/ Object result2 = trans2.transform(f); assertTrue("Transformed object should be an object message", result2 instanceof ObjectMessage); }
From source file:org.wso2.carbon.identity.agent.outbound.server.UserStoreServerEndpoint.java
/** * Process response message and send to response queue. * @param message Message/*from ww w . j a v a2s . co m*/ */ private void processResponse(String message) { JMSConnectionFactory connectionFactory = new JMSConnectionFactory(); Connection connection = null; MessageProducer producer; try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Start processing response message: " + message); } MessageBrokerConfig conf = ServerConfigurationBuilder.build().getMessagebroker(); connectionFactory.createActiveMQConnectionFactory(conf.getUrl()); connection = connectionFactory.createConnection(); connectionFactory.start(connection); javax.jms.Session session = connectionFactory.createSession(connection); Destination responseQueue = connectionFactory.createQueueDestination(session, UserStoreConstants.QUEUE_NAME_RESPONSE); producer = connectionFactory.createMessageProducer(session, responseQueue, DeliveryMode.NON_PERSISTENT); producer.setTimeToLive(UserStoreConstants.QUEUE_SERVER_MESSAGE_LIFETIME); JSONObject resultObj = new JSONObject(message); String responseData = resultObj.get(UserStoreConstants.UM_JSON_ELEMENT_RESPONSE_DATA).toString(); String correlationId = (String) resultObj .get(UserStoreConstants.UM_JSON_ELEMENT_REQUEST_DATA_CORRELATION_ID); UserOperation responseOperation = new UserOperation(); responseOperation.setCorrelationId(correlationId); responseOperation.setResponseData(responseData.toString()); ObjectMessage responseMessage = session.createObjectMessage(); responseMessage.setObject(responseOperation); responseMessage.setJMSCorrelationID(correlationId); producer.send(responseMessage); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Finished processing response message: " + message); } } catch (JMSException e) { LOGGER.error("Error occurred while sending message: " + message, e); } catch (JSONException e) { LOGGER.error("Error occurred while reading json payload of message: " + message, e); } catch (JMSConnectionException e) { LOGGER.error("Error occurred while creating JMS connection to send message: " + message, e); } finally { try { connectionFactory.closeConnection(connection); } catch (JMSConnectionException e) { LOGGER.error("Error occurred while closing JMS connection", e); } } }
From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java
public void fireNotificationEvent(final NotificationEvent event) { if (brokerService == null || !brokerInitialized) { log.debug("The broker service is not running in fireNotificationEvent."); return;/*from ww w .j ava 2 s .c o m*/ } if (event == null || event.getEventType() == null) { log.warn( "Request was made to generate an event but the required attributes were not present in the request."); return; } log.info("Fire notification for event " + event.getEventType().getEventTypeName()); Topic topic = topicMap.get(event.getEventType().getEventTypeName()); if (topic == null) { log.warn("Request was made to generate an event but the event type is unknown."); return; } try { jmsTemplate.send(topic, new MessageCreator() { public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(); message.setObject(event); return message; } }); } catch (RuntimeException e) { log.warn("Unable to send out a notification event: " + e, e); } }
From source file:org.aludratest.service.jms.impl.JmsActionImpl.java
@Override public void sendObjectMessage(Serializable object, String destinationName) { ObjectMessage msg = createObjectMessage(); try {//from w w w. j a va 2 s .co m msg.setObject(object); } catch (JMSException e) { throw new TechnicalException("Could not set object of object message", e); } sendMessage(msg, destinationName); }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {/*from ww w.ja va2 s . c o m*/ Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
/** * Produce the mail to the JMS Queue//from w w w.j av a 2 s . c o m */ protected void produceMail(Map<String, Object> props, int msgPrio, Mail mail) throws JMSException, MessagingException, IOException { ObjectMessage message = session.createObjectMessage(); for (Map.Entry<String, Object> entry : props.entrySet()) { message.setObjectProperty(entry.getKey(), entry.getValue()); } long size = mail.getMessageSize(); ByteArrayOutputStream out; if (size > -1) { out = new ByteArrayOutputStream((int) size); } else { out = new ByteArrayOutputStream(); } mail.getMessage().writeTo(out); // store the byte array in a ObjectMessage so we can use a // SharedByteArrayInputStream later // without the need of copy the day message.setObject(out.toByteArray()); producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE); }
From source file:org.jbpm.bpel.integration.server.SoapHandler.java
protected ObjectMessage sendRequest(SOAPMessage soapMessage, Session jmsSession, JbpmContext jbpmContext) throws SOAPException, JMSException { // create a jms message to deliver the incoming content ObjectMessage jmsRequest = jmsSession.createObjectMessage(); // put the partner link identified by handle in a jms property PartnerLinkEntry partnerLinkEntry = integrationControl.getPartnerLinkEntry(portTypeName, serviceName, portName);/* w w w . j ava 2 s . c o m*/ long partnerLinkId = partnerLinkEntry.getId(); jmsRequest.setLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP, partnerLinkId); Operation operation = determineOperation(soapMessage); if (operation == null) throw new SOAPException("could not determine operation to perform"); // put the operation name in a jms property String operationName = operation.getName(); jmsRequest.setStringProperty(IntegrationConstants.OPERATION_NAME_PROP, operationName); log.debug("received request: partnerLink=" + partnerLinkId + ", operation=" + operationName); // extract message content HashMap requestParts = new HashMap(); formatter.readMessage(operationName, soapMessage, requestParts, MessageDirection.INPUT); jmsRequest.setObject(requestParts); // fill message properties BpelProcessDefinition process = integrationControl.getDeploymentDescriptor() .findProcessDefinition(jbpmContext); MessageType requestType = process.getImportDefinition() .getMessageType(operation.getInput().getMessage().getQName()); fillCorrelationProperties(requestParts, jmsRequest, requestType.getPropertyAliases()); // set up producer MessageProducer producer = jmsSession.createProducer(partnerLinkEntry.getDestination()); try { // is the exchange pattern request/response? if (operation.getOutput() != null) { Destination replyTo = integrationControl.getIntegrationServiceFactory().getResponseDestination(); jmsRequest.setJMSReplyTo(replyTo); // have jms discard request message if response timeout expires Number responseTimeout = getResponseTimeout(jbpmContext); if (responseTimeout != null) producer.setTimeToLive(responseTimeout.longValue()); } else { // have jms discard message if one-way timeout expires Number oneWayTimeout = getOneWayTimeout(jbpmContext); if (oneWayTimeout != null) producer.setTimeToLive(oneWayTimeout.longValue()); } // send request message producer.send(jmsRequest); log.debug("sent request: " + RequestListener.messageToString(jmsRequest)); return jmsRequest; } finally { // release producer resources producer.close(); } }