List of usage examples for javax.jms Message getJMSReplyTo
Destination getJMSReplyTo() throws JMSException;
From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.simple.RemoteClassProvider.java
@Override public void onMessage(Message message) { String className = null;/*from www .j a v a 2s.c o m*/ try { className = ((ClassRequest) ((ObjectMessage) message).getObject()).className; log.fine("Message received:" + className); // we expect sender to specify the query he's waiting response into the JMSReplyTo Destination destination = message.getJMSReplyTo(); UUID correlationId = UUID.fromString(message.getJMSCorrelationID()); // preparing class bytecode. byte[] bytecode = null; try { String classPath = className.replace('.', '/') + ".class";//TODO: use utils. InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(classPath); // If the class cannot be found, attempt to find a resource with the requested name if (is == null) { try { ClassPathResource resource = new ClassPathResource(className); if (resource.exists()) { is = resource.getInputStream(); } } catch (IOException e) { // Ignore } } if (is == null) log.severe(String.format("Requested class %s was not found.", className)); else bytecode = RemoteClassLoaderUtils.getByteArray(is); } catch (Exception ex) { log.severe("Failed to provide required class " + className + ": " + ex.toString()); ex.printStackTrace(); } finally { mq.respond(new ClassResponse(bytecode), destination, correlationId); } } catch (JMSException e) { log.severe("Failed to process message (" + className + "): " + e.toString()); e.printStackTrace(); } }
From source file:org.grouter.common.jms.TopicListenerDestination.java
/** * <br>/*from w ww . j a va2 s. c om*/ */ public void sendReplyToTemporaryDestination(Message request) { TemporaryTopic replyTopic = null; TopicPublisher tempsender = null; String temporaryDestinationName = null; try { if (request.getJMSReplyTo() == null) { throw new IllegalStateException("The sender of this message has not entered a JMSReplyTo field - " + "impossible to send reply on temporary destination!!"); } temporaryDestinationName = request.getJMSReplyTo().toString(); request.setJMSCorrelationID(request.getJMSMessageID()); logger.debug("JMSCorrelationID was set!!!" + request.getJMSCorrelationID()); replyTopic = (TemporaryTopic) request.getJMSReplyTo(); tempsender = topicSession.createPublisher(replyTopic); logger.debug("Created a tempsender and sending reply to " + replyTopic); tempsender.send(request); } catch (JMSException ex) { //ignore logger.warn("Failed sending reply on temporary destination : " + temporaryDestinationName); } finally { try { if (tempsender != null) { tempsender.close(); } if (replyTopic != null) { replyTopic.delete(); } } catch (JMSException ex1) { //ignore } } }
From source file:com.datatorrent.lib.io.jms.AbstractJMSInputOperator.java
/** * If getJMSReplyTo is set then send message back to reply producer. * * @param message/*from w ww. ja va 2 s .c o m*/ */ protected void sendReply(Message message) { try { if (message.getJMSReplyTo() != null) { // Send reply only if the replyTo destination is set replyProducer.send(message.getJMSReplyTo(), getSession().createTextMessage("Reply: " + message.getJMSMessageID())); } } catch (JMSException ex) { LOG.error(ex.getLocalizedMessage()); throwable.set(ex); throw new RuntimeException(ex); } }
From source file:org.logicblaze.lingo.jms.JmsServiceExporterMessageListener.java
/** * Send the given RemoteInvocationResult as a JMS message to the originator * /*from w ww . j a v a 2 s. c om*/ * @param message * current HTTP message * @param result * the RemoteInvocationResult object * @throws javax.jms.JMSException * if thrown by trying to send the message */ protected void writeRemoteInvocationResult(final Message message, final RemoteInvocationResult result) throws JMSException { Message responseMessage = createResponseMessage(getResponseRequestor().getSession(), message, result); getResponseRequestor().send(message.getJMSReplyTo(), responseMessage); }
From source file:org.apache.camel.component.jms.EndpointMessageListener.java
protected Object getReplyToDestination(Message message) throws JMSException { // lets send a response back if we can Object destination = getReplyToDestination(); if (destination == null) { try {/*from w w w .java 2 s. c om*/ destination = message.getJMSReplyTo(); } catch (JMSException e) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot read JMSReplyTo header. Will ignore this exception.", e); } } } return destination; }
From source file:org.grouter.common.jms.QueueListenerDestination.java
/** * <br>/*from w ww.j ava 2 s. c o m*/ */ public void sendReplyToTemporaryDestination(Message request) { TemporaryQueue replyQueue = null; QueueSender tempsender = null; String temporaryDestinationName = null; try { if (request.getJMSReplyTo() == null) { throw new IllegalStateException("The sender of this message has not entered a JMSReplyTo field - " + "impossible to send reply on temporary destination!!"); } temporaryDestinationName = request.getJMSReplyTo().toString(); request.setJMSCorrelationID(temporaryDestinationName); replyQueue = (TemporaryQueue) request.getJMSReplyTo(); tempsender = queueSession.createSender(replyQueue); tempsender.send(request); logger.debug("Created a tempsender and sent reply to " + replyQueue); } catch (JMSException ex) { //ignore logger.warn("Failed sending reply on temporary destination : " + temporaryDestinationName); } finally { try { if (tempsender != null) { tempsender.close(); } if (replyQueue != null) { replyQueue.delete(); } } catch (JMSException ex1) { //ignore } } }
From source file:org.apache.axis2.transport.jms.LogAspect.java
@Before("(call(void javax.jms.MessageProducer.send(javax.jms.Message)) ||" + " call(void javax.jms.TopicPublisher.publish(javax.jms.Message))) && args(message)") public void beforeSend(Message message) { try {//from ww w . ja v a2s .c om OutputStream out = LogManager.INSTANCE.createLog("jms"); try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false); pw.println("Type: " + message.getClass().getName()); pw.println("JMS message ID: " + message.getJMSMessageID()); pw.println("JMS correlation ID: " + message.getJMSCorrelationID()); pw.println("JMS reply to: " + message.getJMSReplyTo()); for (Enumeration<?> e = message.getPropertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); pw.print(name); pw.print(": "); pw.println(message.getStringProperty(name)); } pw.println(); pw.flush(); if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; bytesMessage.reset(); IOUtils.copy(new BytesMessageInputStream(bytesMessage), out); } else if (message instanceof TextMessage) { pw.print(((TextMessage) message).getText()); pw.flush(); } } finally { out.close(); } } catch (Throwable ex) { log.error("Failed to dump JMS message", ex); } }
From source file:org.mule.transport.jms.JmsMessageUtils.java
public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException { if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) { to.setJMSCorrelationID(from.getJMSCorrelationID()); }//from www . j a va 2 s . com if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) { to.setJMSDeliveryMode(from.getJMSDeliveryMode()); } if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) { to.setJMSDestination(from.getJMSDestination()); } if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) { to.setJMSExpiration(from.getJMSExpiration()); } if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) { to.setJMSMessageID(from.getJMSMessageID()); } if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) { to.setJMSPriority(from.getJMSPriority()); } if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) { to.setJMSRedelivered(from.getJMSRedelivered()); } if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) { to.setJMSReplyTo(from.getJMSReplyTo()); } if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) { to.setJMSTimestamp(from.getJMSTimestamp()); } if (connector.supportsProperty(JmsConstants.JMS_TYPE)) { to.setJMSType(from.getJMSType()); } return to; }
From source file:de.adorsys.jmspojo.JMSServiceAdapterFactoryTest.java
@Before public void setup() throws Exception { broker = new BrokerService(); broker.setPersistent(false);//from w w w . ja v a 2s. com // configure the broker broker.addConnector("vm://test"); broker.setBrokerName("test"); broker.setUseShutdownHook(false); broker.start(); cf = new ActiveMQConnectionFactory("vm://localhost?create=false"); qc = cf.createQueueConnection(); QueueSession createQueueSession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); defaultQueue = createQueueSession.createQueue("TestQueue"); createQueueSession.createReceiver(defaultQueue).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { boolean sendTimeout = message.getBooleanProperty("timeout"); if (!sendTimeout) { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( OBJECT_MAPPER, cf, null, JMS_TIMEOUT); jmsSender.send(message.getJMSReplyTo(), null, ((TextMessage) message).getText()); } } catch (JMSException e) { e.printStackTrace(); } } }); dedicatedQueue = createQueueSession.createQueue("DedicatedQueue"); createQueueSession.createReceiver(dedicatedQueue).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( OBJECT_MAPPER, cf, null, JMS_TIMEOUT); PingMessage data = new PingMessage(); data.setPing("dedicted response"); jmsSender.send(message.getJMSReplyTo(), null, data); } catch (JMSException e) { e.printStackTrace(); } } }); qc.start(); JMSServiceAdapterFactory jmsServiceStubFactory = new JMSServiceAdapterFactory(OBJECT_MAPPER, cf, defaultQueue, JMS_TIMEOUT); service = jmsServiceStubFactory.generateJMSServiceProxy(JMSSampleService.class); }
From source file:com.jaliansystems.activeMQLite.impl.RepositoryService.java
/** * Handles message requests for this object repository. * /*from w w w .ja va 2s .c om*/ * All messages are JMSLiteMessage the protocol of which is explained in Protocol.txt */ public void onMessage(Message message) { if (message instanceof ActiveMQBytesMessage) { try { JMSLiteMessage jmsMessage = new JMSLiteMessage((ActiveMQBytesMessage) message); byte message_type = (Byte) jmsMessage.read(); if (message_type == MESSAGE_LOOKUP) { String className = (String) jmsMessage.read(); handleLookup(className, message.getJMSReplyTo(), message.getJMSCorrelationID()); } else if (message_type == MESSAGE_CALL) { JMSLiteMessage rmessage = new JMSLiteMessage(); rmessage.write(MESSAGE_CALL); try { Object returnVal = objectRepository.invoke(jmsMessage, client); rmessage.write(CALL_SUCCESS); rmessage.write(returnVal); } catch (Throwable t) { if (log.isDebugEnabled()) t.printStackTrace(); rmessage.write(CALL_ERROR); rmessage.write(t.getClass().getName()); rmessage.write(t.getMessage()); } rmessage.setJMSCorrelationID(message.getJMSCorrelationID()); rmessage.setJMSDestination(message.getJMSReplyTo()); responseProducer.send(message.getJMSReplyTo(), rmessage); } else if (message_type == MESSAGE_REMOVE) { ObjectHandle handle = (ObjectHandle) jmsMessage.read(); boolean b = objectRepository.removeObject(handle); JMSLiteMessage rmessage = new JMSLiteMessage(); rmessage.write(MESSAGE_REMOVE); rmessage.write(b); rmessage.setJMSCorrelationID(message.getJMSCorrelationID()); rmessage.setJMSDestination(message.getJMSReplyTo()); responseProducer.send(message.getJMSReplyTo(), rmessage); } } catch (Exception e) { e.printStackTrace(); } } }