Example usage for javax.jms JMSException JMSException

List of usage examples for javax.jms JMSException JMSException

Introduction

In this page you can find the example usage for javax.jms JMSException JMSException.

Prototype

public JMSException(String reason) 

Source Link

Document

Constructs a JMSException with the specified reason and with the error code defaulting to null.

Usage

From source file:org.osgp.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }//from w w  w  . j a  v a  2 s. co m

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());

    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    return this.messageProcessors.get(messageType.ordinal());
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }//from  www. ja va2s .com

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        throw new IllegalArgumentException("Message type is not supported: " + message.getJMSType());
    }

    return messageProcessor;
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }/*from  w  w  w.  jav  a  2 s  . c o m*/

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor for message type: " + message.getJMSType());
    }

    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        LOGGER.error("No message processor instance found in message processor map for message type: {}",
                message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    return messageProcessor;
}

From source file:com.nesscomputing.jms.JsonProducerCallback.java

@Override
@CheckForNull//w  w w.  ja va 2  s.  co m
public Message buildMessage(final AbstractProducer<Object> producer, final Object data)
        throws IOException, JMSException {
    Preconditions.checkState(mapper != null, "need object mapper configured!");

    final TextMessage message = producer.createTextMessage();
    if (message == null) {
        throw new JMSException("Could not create text message, not connected?");
    } else {
        final String dataText = mapper.writeValueAsString(data);
        message.setText(dataText);
        return message;
    }
}

From source file:org.toobsframework.jms.doitref.JmsDoItRefSender.java

public void sendMessage(final DoItRefBean doItRefBean) {
    jmsTemplate.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {

            Message objMessage = null;/*from   w  ww. j a  va  2s . c  om*/
            try {
                objMessage = session.createObjectMessage(doItRefBean);
            } catch (Exception e) {
                log.error("JMS Mail exception " + e.getMessage(), e);
                throw new JMSException(e.getMessage());
            }
            return objMessage;
        }
    });

}

From source file:com.mirth.connect.connectors.jms.JmsMessageUtils.java

public static Message getMessageForObject(Object object, Session session) throws JMSException {
    if (object instanceof Message) {
        return (Message) object;
    } else if (object instanceof String) {
        TextMessage text = session.createTextMessage((String) object);
        return text;
    } else if (object instanceof Map) {
        MapMessage map = session.createMapMessage();
        Map.Entry entry = null;//from   w  ww  . ja  v  a2s  .  c  om
        Map temp = (Map) object;

        for (Iterator i = temp.entrySet().iterator(); i.hasNext();) {
            entry = (Map.Entry) i.next();
            map.setObject(entry.getKey().toString(), entry.getValue());
        }

        return map;
    } else if (object instanceof InputStream) {
        StreamMessage stream = session.createStreamMessage();
        InputStream temp = (InputStream) object;

        byte[] buffer = new byte[1024 * 4];
        int len = 0;
        try {
            while ((len = temp.read(buffer)) != -1) {
                stream.writeBytes(buffer, 0, len);
            }
        } catch (IOException e) {
            throw new JMSException("Failed to read input stream to create a stream message: " + e);
        }

        return stream;
    } else if (object instanceof byte[]) {
        BytesMessage bytes = session.createBytesMessage();
        byte[] buf = (byte[]) object;
        for (int i = 0; i < buf.length; i++) {
            bytes.writeByte(buf[i]);
        }

        return bytes;
    } else if (object instanceof Serializable) {
        ObjectMessage oMsg = session.createObjectMessage();
        oMsg.setObject((Serializable) object);
        return oMsg;
    } else {
        throw new JMSException(
                "Source was not a supported type, data must be Serializable, String, byte[], Map or InputStream");
    }
}

From source file:org.fusesource.camel.util.BlobMessageConverter.java

@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    if (message instanceof BlobMessage) {
        try {/*from  w w  w .  j  a  v a2 s  .  co m*/
            return ((BlobMessage) message).getInputStream();
        } catch (IOException e) {
            JMSException jmsE = new JMSException("Unable to read blob message.");
            jmsE.setLinkedException(e);
            throw jmsE;
        }
    } else {
        throw new MessageConversionException("Message must be of type ActiveMQBlobMessage.");
    }
}

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  ww.jav  a2 s.  c o  m

    // 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:com.clican.pluto.cluster.jms.SynchronizeServiceJmsImpl.java

public void synchronize(final Message msg) throws SynchronizeException {
    if (log.isDebugEnabled()) {
        log.debug("Send message [" + msg.toString() + "] to topic [" + msg.getName() + "]");
    }//from  ww w.  j a  v a  2s .co m
    Destination destination = destinationMap.get(msg.getName());
    if (destination == null) {
        throw new SynchronizeException(msg);
    }
    try {
        jmsTemplate.send(destination, new MessageCreator() {
            public javax.jms.Message createMessage(Session session) throws JMSException {
                ObjectMessage om = session.createObjectMessage();
                om.setObject(msg);
                return om;
            }
        });
    } catch (JmsException e) {
        // If the <code>JmsException</code> is thrown, we have to invoke the
        // onException method to inform the SimpleConnectionFactory to
        // re-get
        // connection from newer ConnectionFactory which is injected as an
        // target.
        ConnectionFactory cf = jmsTemplate.getConnectionFactory();
        if (cf instanceof ExceptionListener) {
            ((ExceptionListener) cf).onException(new JMSException(e.getMessage()));
        }
        try {
            jmsTemplate.send(destination, new MessageCreator() {
                public javax.jms.Message createMessage(Session session) throws JMSException {
                    ObjectMessage om = session.createObjectMessage();
                    om.setObject(msg);
                    return om;
                }
            });
        } catch (JmsException ex) {
            throw new SynchronizeException(ex, msg);
        }
    }

}

From source file:org.toobsframework.jms.email.JmsEmailSender.java

public void sendMessage(final EmailBean emailBean) {
    jmsTemplate.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {

            MapMessage mapMessage = null;
            try {
                mapMessage = session.createMapMessage();
                mapMessage.setString("sender", emailBean.getEmailSender());
                mapMessage.setString("subject", emailBean.getEmailSubject());
                mapMessage.setString("recipients", getRecipientList(emailBean.getRecipients()));
                mapMessage.setString("messageText", emailBean.getMessageText());
                mapMessage.setString("messageHtml", emailBean.getMessageHtml());
                mapMessage.setString("mailSenderKey", emailBean.getMailSenderKey());
                mapMessage.setInt("attempts", emailBean.getAttempts());
                mapMessage.setInt("type", emailBean.getType());
                mapMessage.setString("failureCause", emailBean.getFailureCause());
            } catch (Exception e) {
                log.error("JMS Mail exception " + e.getMessage(), e);
                throw new JMSException(e.getMessage());
            }//from  w  w  w  .j a  v  a 2  s . c  o m
            return mapMessage;
        }
    });

}