List of usage examples for javax.jms ObjectMessage setStringProperty
void setStringProperty(String name, String value) throws JMSException;
From source file:org.grouter.common.jms.TopicSenderDestination.java
/** * <b>See documentation in {@link org.grouter.common.jms.AbstractSenderDestination#sendMessage(java.io.Serializable,java.util.HashMap)}.</b><br> * <br>/* ww w .j a v a 2 s. c o m*/ * * @param message a serializable object instance * @param headerProperties properties to store in header for JMS message * * @return ObjectMessage an object message */ private ObjectMessage createMessage(Serializable message, HashMap<String, String> headerProperties) { ObjectMessage msg = null; try { msg = topicSession.createObjectMessage(message); msg.clearProperties(); if (headerProperties != null) { for (String key : headerProperties.keySet()) { String value = headerProperties.get(key); msg.setStringProperty(key, value); } } } catch (JMSException e) { logger.warn("Failed setting header for message.", e); } return msg; }
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);/*from w w w. j av a 2 s . c om*/ 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(); } }
From source file:org.nuxeo.ecm.core.event.jms.JmsEventForwarder.java
protected void produceJMSMessage(SerializableEventBundle message) throws JMSBusNotActiveException { InitialContext ctx;/* w w w . j a v a 2 s .c om*/ Topic nuxeoTopic; try { ctx = new InitialContext(); nuxeoTopic = (Topic) ctx.lookup(NUXEO_JMS_TOPIC); } catch (NamingException e) { jmsBusIsActive = false; throw new JMSBusNotActiveException(e); } TopicConnection nuxeoTopicConnection = null; TopicSession nuxeoTopicSession = null; TopicPublisher nuxeoMessagePublisher = null; try { TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory"); nuxeoTopicConnection = factory.createTopicConnection(); nuxeoTopicSession = nuxeoTopicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); ObjectMessage jmsMessage = nuxeoTopicSession.createObjectMessage(message); // add Headers for JMS message jmsMessage.setStringProperty("BundleEvent", message.getEventBundleName()); nuxeoMessagePublisher = nuxeoTopicSession.createPublisher(nuxeoTopic); nuxeoMessagePublisher.send(jmsMessage); log.debug("Event bundle " + message.getEventBundleName() + " forwarded to JMS topic"); } catch (Exception e) { log.error("Error during JMS forwarding", e); } finally { if (nuxeoTopicSession != null) { try { if (nuxeoMessagePublisher != null) { nuxeoMessagePublisher.close(); } nuxeoTopicConnection.close(); nuxeoTopicSession.close(); } catch (JMSException e) { log.error("Error during JMS cleanup", e); } } } }