List of usage examples for javax.jms Message getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.adaptris.core.jms.MessageTypeTranslatorImp.java
/** * Convenience method to translate a {@link Message} into a {@link com.adaptris.core.AdaptrisMessage}. * * <p>/*from w ww .j av a 2 s . com*/ * If translation fails, then an attempt is made to use an {@link AutoConvertMessageTranslator} instance to attempt to translate * the message so that configurations are handled as well as possible. * </p> * * @param translator the translator to use. * @param msg the javax.jms.Message * @return an AdaptrisMessage instance * @throws JMSException if the message could not be translated. */ public static AdaptrisMessage translate(MessageTypeTranslator translator, Message msg) throws JMSException { Logger logR = LoggerFactory.getLogger(translator.getClass()); AdaptrisMessage result = null; try { result = translator.translate(msg); } catch (Exception e) { logR.warn("Can't handle {} using {}", msg.getClass().getName(), translator.getClass().getName()); MessageTypeTranslator mt = replicate(translator); logR.warn("Assuming mis-configuration and attempting to use {}", mt.getClass().getName()); try { start(mt); result = mt.translate(msg); } finally { stop(mt); } } return result; }
From source file:dk.netarkivet.common.distribute.JMSConnection.java
/** * Unwraps a NetarkivetMessage from an ObjectMessage. * * @param msg a javax.jms.ObjectMessage//from w w w. j a va 2 s. com * * @return a NetarkivetMessage * * @throws ArgumentNotValid when msg in valid or format of JMS Object * message is invalid */ public static NetarkivetMessage unpack(Message msg) throws ArgumentNotValid { ArgumentNotValid.checkNotNull(msg, "msg"); ObjectMessage objMsg; try { objMsg = (ObjectMessage) msg; } catch (ClassCastException e) { log.warn("Invalid message type: " + msg.getClass()); throw new ArgumentNotValid("Invalid message type: " + msg.getClass()); } NetarkivetMessage netMsg; String classname = "Unknown class"; // for error reporting purposes try { classname = objMsg.getObject().getClass().getName(); netMsg = (NetarkivetMessage) objMsg.getObject(); // Note: Id is only updated if the message does not already have an // id. On unpack, this means the first time the message is received. // FIXME Fix for NAS-2043 doesn't seem to work //String randomID = UUID.randomUUID().toString(); //netMsg.updateId(randomID); netMsg.updateId(msg.getJMSMessageID()); } catch (ClassCastException e) { log.warn("Invalid message type: " + classname, e); throw new ArgumentNotValid("Invalid message type: " + classname, e); } catch (Exception e) { String message = "Message invalid. Unable to unpack " + "message: " + classname; log.warn(message, e); throw new ArgumentNotValid(message, e); } log.trace("Unpacked message '" + netMsg + "'"); return netMsg; }
From source file:com.fusesource.forge.jmstest.benchmark.command.transport.JMSCommandTransport.java
public void onMessage(Message msg) { try {//ww w. j a v a 2s.com if (!(msg instanceof ObjectMessage)) { log().warn("Ignoring msg of type: " + msg.getClass()); } Object obj = ((ObjectMessage) msg).getObject(); if (!(obj instanceof BenchmarkCommand)) { log().warn("Ignoring msg object of type: " + obj.getClass()); } getHandler().handleCommand((BenchmarkCommand) obj); } catch (JMSException je) { log().error("Unexpected error processing command message", je); } }
From source file:org.addsimplicity.anicetus.io.jms.JsonMessageConverter.java
/** * Convert a JMS text message with a JSON payload to a telemetry artifact. * //from ww w .j a v a 2 s . c om * @param msg * The JMS text message. * @return the telemetry artifact. * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) */ public Object fromMessage(Message msg) throws JMSException, MessageConversionException { if (msg instanceof TextMessage) { return m_decoder.decode(((TextMessage) msg).getText().toCharArray()); } else { throw new JMSException( "Message of type " + msg.getClass().getName() + " is not supported. Only TextMessage"); } }
From source file:com.mirth.connect.connectors.jms.transformers.AbstractJmsTransformer.java
protected Object transformFromMessage(Message source) throws TransformerException { Object result = null;//from w w w.j a va 2s . c om try { if (logger.isDebugEnabled()) { logger.debug("Message type received is: " + source.getClass().getName()); } if (source instanceof BytesMessage) { // If this bytes Message is not compressed it will throw a // NotGZipFormatException // It would be nice if we could check the custom JMS compression // property here. However // When jms bridging other, non-JMS-compliant message servers // occur, there is no guarantee that // Custom properties will be propagated byte[] bytes = JmsMessageUtils.getBytesFromMessage(source); if (CompressionHelper.isCompressed(bytes)) { if (logger.isDebugEnabled()) { logger.debug("Message recieved is compressed"); } result = CompressionHelper.uncompressByteArray(bytes); } else { // If the message is not compressed, handle it the standard // way result = JmsMessageUtils.getObjectForMessage(source); } } else { result = JmsMessageUtils.getObjectForMessage(source); } } catch (Exception e) { throw new TransformerException(this, e); } return result; }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
/** * Template method that allows for custom message mapping. * Invoked when {@link #setTargetType} is not {@link MessageType#TEXT} or * {@link MessageType#BYTES}./*from w w w. j av a 2s. c om*/ * <p>The default implementation throws an {@link IllegalArgumentException}. * @param message the input message * @return the message content * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected String getPayloadFromMessage(Message message) throws JMSException, IOException { throw new IllegalArgumentException("Unsupported message type [" + message.getClass() + "]. default only supports TextMessages and BytesMessages."); }
From source file:com.adaptris.core.jms.AutoConvertMessageTranslator.java
public AdaptrisMessage translate(Message msg) throws JMSException { AdaptrisMessage result = null;// w ww. ja va 2 s . c o m MessageTypeTranslator mt = null; String messageType = null; try { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.isSupported(msg)) { mt = mti.create(this); messageType = mti.name(); break; } } if (mt != null) { start(mt); log.trace("Converting [{}] using [{}]", msg.getClass().getSimpleName(), mt.getClass().getSimpleName()); result = mt.translate(msg); result.addMessageHeader(CONSUMED_MESSAGE_TYPE_KEY, messageType); } } finally { stop(mt); } if (result == null) { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } return result; }
From source file:org.globus.crux.messaging.utils.JAXBMessageConverter.java
/** * <p>/*from ww w .j ava 2 s .c o m*/ * Unmarshal given <code>message</code> into an <code>object</code>. * </p> * * <p> * Should we raise an exception if the XML message encoding is not in sync with the underlying TextMessage encoding when the JMS * Provider supports MOM message's encoding ? * </p> * * @param message * message to unmarshal, MUST be an instance of {@link TextMessage} or of {@link BytesMessage}. * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) */ public Object fromMessage(Message message) throws JMSException, MessageConversionException { Source source; if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; source = new StreamSource(new StringReader(textMessage.getText())); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); source = new StreamSource(new ByteArrayInputStream(bytes)); } else { throw new MessageConversionException("Unsupported JMS Message type " + message.getClass() + ", expected instance of TextMessage or BytesMessage for " + message); } Object result; try { result = context.createUnmarshaller().unmarshal(source); } catch (JAXBException e) { throw new MessageConversionException("Error unmarshalling message", e); } return result; }
From source file:org.carewebframework.jms.GlobalEventDispatcher.java
/** * Process a dequeued message by forwarding it to the local event manager for local delivery. If * the message is a ping request, send the response. * // ww w . j av a 2s . c o m * @param message Message to process. */ protected void processMessage(final Message message) { try { final String eventName = message.getJMSType(); Object eventData; if (message instanceof ObjectMessage) { eventData = ((ObjectMessage) message).getObject(); } else if (message instanceof TextMessage) { eventData = ((TextMessage) message).getText(); } else { log.warn(String.format("Ignoring unsupported message: type [%s], message [%s]", message.getClass(), message)); return; } localEventDelivery(eventName, eventData); } catch (final Exception e) { log.error("Error during local dispatch of global event.", e); } }
From source file:com.redhat.winddrop.mdb.WindupExecutionQueueMDB.java
/** * @see MessageListener#onMessage(Message) *///from w w w. ja v a 2s . c o m public void onMessage(Message message) { String jobDescription = null; try { if (message instanceof TextMessage) { jobDescription = ((TextMessage) message).getText(); StringTokenizer t = new StringTokenizer(jobDescription, UploadService.TOKEN); String hashValue = t.nextToken(); String packages = t.nextToken(); String email = t.nextToken(); LOG.info("Message received for Windup execution: " + jobDescription); LOG.info("hashValue: " + hashValue + " - email: " + email + " - packages: " + packages); buildAndUploadReport(hashValue, email, packages); } else { LOG.warning("Message of wrong type: " + message.getClass().getName()); } } catch (Throwable t) { LOG.log(Level.SEVERE, "Error occured in onMessage for hashValue " + jobDescription, t); } }