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:com.oneops.controller.jms.CmsListenerTest.java

@Test
/** test with message where JMSException is forced to happend
 * but we effectively are asserting it must get swallowed*/
public void testBadMessage() throws Exception {
    TextMessage message = mock(TextMessage.class);
    when(message.getText()).thenThrow(new JMSException("mock-forces-errorJMS"));
    listener.onMessage(message);// w  w w.  j a va2  s  . co  m

}

From source file:org.logicblaze.lingo.jms.impl.OneWayRequestor.java

public Message request(Destination destination, Message message, long timeout) throws JMSException {
    throw new JMSException("request(Destination, Message, long) not implemented for OneWayRequestor");
}

From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java

/**
 * Sets SQS endpoint and wraps IllegalArgumentException.
 * /*from  www  .  java 2 s .  co  m*/
 * @param endpoint
 *            The endpoint (ex: "sqs.us-east-1.amazonaws.com") of the region
 *            specific AWS endpoint this client will communicate with.
 * @throws JMSException
 */
public void setEndpoint(String endpoint) throws JMSException {
    try {
        amazonSQSClient.setEndpoint(endpoint);
    } catch (IllegalArgumentException ase) {
        JMSException jmsException = new JMSException(ase.getMessage());
        throw (JMSException) jmsException.initCause(ase);
    }
}

From source file:org.logicblaze.lingo.jms.impl.OneWayRequestor.java

public void request(Destination destination, Message requestMessage, ReplyHandler handler, long timeout)
        throws JMSException {
    throw new JMSException(
            "request(Destination, Message, ReplyHandler, long) not implemented for OneWayRequestor");
}

From source file:Vendor.java

public void run() {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
    Session session = null;//  ww  w . j ava2 s.c om
    Destination orderQueue;
    Destination monitorOrderQueue;
    Destination storageOrderQueue;
    TemporaryQueue vendorConfirmQueue;
    MessageConsumer orderConsumer = null;
    MessageProducer monitorProducer = null;
    MessageProducer storageProducer = null;

    try {
        Connection connection = connectionFactory.createConnection();

        session = connection.createSession(true, Session.SESSION_TRANSACTED);
        orderQueue = session.createQueue("VendorOrderQueue");
        monitorOrderQueue = session.createQueue("MonitorOrderQueue");
        storageOrderQueue = session.createQueue("StorageOrderQueue");

        orderConsumer = session.createConsumer(orderQueue);
        monitorProducer = session.createProducer(monitorOrderQueue);
        storageProducer = session.createProducer(storageOrderQueue);

        Connection asyncconnection = connectionFactory.createConnection();
        asyncSession = asyncconnection.createSession(true, Session.SESSION_TRANSACTED);

        vendorConfirmQueue = asyncSession.createTemporaryQueue();
        MessageConsumer confirmConsumer = asyncSession.createConsumer(vendorConfirmQueue);
        confirmConsumer.setMessageListener(this);

        asyncconnection.start();

        connection.start();

        while (true) {
            Order order = null;
            try {
                Message inMessage = orderConsumer.receive();
                MapMessage message;
                if (inMessage instanceof MapMessage) {
                    message = (MapMessage) inMessage;

                } else {
                    // end of stream
                    Message outMessage = session.createMessage();
                    outMessage.setJMSReplyTo(vendorConfirmQueue);
                    monitorProducer.send(outMessage);
                    storageProducer.send(outMessage);
                    session.commit();
                    break;
                }

                // Randomly throw an exception in here to simulate a Database error
                // and trigger a rollback of the transaction
                if (new Random().nextInt(3) == 0) {
                    throw new JMSException("Simulated Database Error.");
                }

                order = new Order(message);

                MapMessage orderMessage = session.createMapMessage();
                orderMessage.setJMSReplyTo(vendorConfirmQueue);
                orderMessage.setInt("VendorOrderNumber", order.getOrderNumber());
                int quantity = message.getInt("Quantity");
                System.out.println("Vendor: Retailer ordered " + quantity + " " + message.getString("Item"));

                orderMessage.setInt("Quantity", quantity);
                orderMessage.setString("Item", "Monitor");
                monitorProducer.send(orderMessage);
                System.out.println("Vendor: ordered " + quantity + " Monitor(s)");

                orderMessage.setString("Item", "HardDrive");
                storageProducer.send(orderMessage);
                System.out.println("Vendor: ordered " + quantity + " Hard Drive(s)");

                session.commit();
                System.out.println("Vendor: Comitted Transaction 1");

            } catch (JMSException e) {
                System.out.println("Vendor: JMSException Occured: " + e.getMessage());
                e.printStackTrace();
                session.rollback();
                System.out.println("Vendor: Rolled Back Transaction.");
            }
        }

        synchronized (supplierLock) {
            while (numSuppliers > 0) {
                try {
                    supplierLock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        connection.close();
        asyncconnection.close();

    } catch (JMSException e) {
        e.printStackTrace();
    }

}

From source file:com.amazon.sqs.javamessaging.SQSMessageProducer.java

void sendInternal(Queue queue, Message message) throws JMSException {
    checkClosed();/*w ww  .j a v a2 s .  co  m*/
    String sqsMessageBody = null;
    String messageType = null;
    if (message instanceof SQSMessage) {
        message.setJMSDestination(queue);
        if (message instanceof SQSBytesMessage) {
            sqsMessageBody = Base64.encodeAsString(((SQSBytesMessage) message).getBodyAsBytes());
            messageType = SQSMessage.BYTE_MESSAGE_TYPE;
        } else if (message instanceof SQSObjectMessage) {
            sqsMessageBody = ((SQSObjectMessage) message).getMessageBody();
            messageType = SQSMessage.OBJECT_MESSAGE_TYPE;
        } else if (message instanceof SQSTextMessage) {
            sqsMessageBody = ((SQSTextMessage) message).getText();
            messageType = SQSMessage.TEXT_MESSAGE_TYPE;
        }
    } else {
        throw new MessageFormatException(
                "Unrecognized message type. Messages have to be one of: SQSBytesMessage, SQSObjectMessage, or SQSTextMessage");
    }
    if (sqsMessageBody == null || sqsMessageBody.isEmpty()) {
        throw new JMSException("Message body cannot be null or empty");
    }
    Map<String, MessageAttributeValue> messageAttributes = propertyToMessageAttribute((SQSMessage) message);
    addMessageTypeReservedAttribute(messageAttributes, (SQSMessage) message, messageType);
    SendMessageRequest sendMessageRequest = new SendMessageRequest(((SQSQueueDestination) queue).getQueueUrl(),
            sqsMessageBody);
    sendMessageRequest.setMessageAttributes(messageAttributes);

    String messageId = amazonSQSClient.sendMessage(sendMessageRequest).getMessageId();
    LOG.info("Message sent to SQS with SQS-assigned messageId: " + messageId);
    /** TODO: Do not support disableMessageID for now.*/
    message.setJMSMessageID(String.format(SQSMessagingClientConstants.MESSAGE_ID_FORMAT, messageId));
    ((SQSMessage) message).setSQSMessageId(messageId);
}

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

public static Object getObjectForMessage(Message source) throws JMSException {
    Object result = null;/*from www .  ja v  a  2s  . c  o  m*/
    try {
        if (source instanceof ObjectMessage) {
            result = ((ObjectMessage) source).getObject();
        } else if (source instanceof MapMessage) {
            Hashtable map = new Hashtable();
            MapMessage m = (MapMessage) source;

            for (Enumeration e = m.getMapNames(); e.hasMoreElements();) {
                String name = (String) e.nextElement();
                Object obj = m.getObject(name);
                map.put(name, obj);
            }

            result = map;
        } else if (source instanceof javax.jms.BytesMessage) {

            javax.jms.BytesMessage bm = (javax.jms.BytesMessage) source;
            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

            byte[] buffer = new byte[1024 * 4];
            int len = 0;
            bm.reset();
            while ((len = bm.readBytes(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }
            baos.flush();
            result = baos.toByteArray();
            baos.close();
            if (result != null) {
                if (logger.isDebugEnabled())
                    logger.debug("JMSToObject: extracted " + ((byte[]) result).length
                            + " bytes from JMS BytesMessage");
            }
        } else if (source instanceof TextMessage) {
            result = ((TextMessage) source).getText();

        } else if (source instanceof BytesMessage) {
            byte[] bytes = getBytesFromMessage(source);
            return CompressionHelper.uncompressByteArray(bytes);
        } else if (source instanceof StreamMessage) {

            StreamMessage sm = (javax.jms.StreamMessage) source;

            result = new java.util.Vector();
            try {
                Object obj = null;
                while ((obj = sm.readObject()) != null) {
                    ((java.util.Vector) result).addElement(obj);
                }
            } catch (MessageEOFException eof) {
            } catch (Exception e) {
                throw new JMSException("Failed to extract information from JMS Stream Message: " + e);
            }
        } else {
            result = source;
        }
    } catch (Exception e) {
        throw new JMSException("Failed to transform message: " + e.getMessage());
    }
    return result;
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

protected RemoteInvocationResult onInvalidClientMessage(Message message) throws JMSException {
    throw new JMSException("Invalid response message: " + message);
}

From source file:com.adaptris.core.jms.VendorImplementationImp.java

public JmsDestination createDestination(String destination, JmsActorConfig c) throws JMSException {
    JmsDestinationImpl jmsDest = new JmsDestinationImpl();
    try {//from   www .  j a v a  2  s  .  co  m
        URI uri = new URI(destination);
        if (!uri.getScheme().equals("jms")) {
            throw new JMSException("failed to parse [" + destination + "]; doesn't start with 'jms'");
        }
        String[] parts = uri.getRawSchemeSpecificPart().split("\\?");
        String[] typeAndName = parts[0].split(":");
        String type = URLDecoder.decode(typeAndName[0], URI_CHARSET);
        String name = URLDecoder.decode(typeAndName[1], URI_CHARSET);
        jmsDest.destType = JmsDestination.DestinationType.valueOf(type.toUpperCase());

        jmsDest.setDestination(jmsDest.destType.create(this, c, name));

        if (parts.length > 1) {
            Map<String, String> params = URLHelper.queryStringToMap(parts[1], URI_CHARSET);
            jmsDest.setDeliveryMode(params.get(RFC6167_DELIVERY_MODE));
            jmsDest.setPriority(params.get(RFC6167_PRIORITY));
            jmsDest.setTimeToLive(params.get(RFC6167_TIME_TO_LIVE));
            jmsDest.setSubscriptionId(params.get(RFC6167_SUBSCRIPTION_ID));
            jmsDest.setSharedConsumerId(params.get(JMS20_SHARED_CONSUMER_ID));
            jmsDest.setNoLocal(params.get(RFC6167_NO_LOCAL));
            String replyToName = params.get(RFC6167_REPLY_TO_NAME);
            if (!isEmpty(replyToName)) {
                jmsDest.setReplyTo(jmsDest.destType.create(this, c, replyToName));
            }
        }
    } catch (NullPointerException e) {
        throw new JMSException("failed to parse [" + destination + "]; NullPointerException");
    } catch (Exception e) {
        JmsUtils.rethrowJMSException(e);
    }
    return jmsDest;
}

From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java

/**
 * Sets SQS region and wraps <code>IllegalArgumentException</code>. This is the recommend
 * way to set-up the SQS end-points.//from   w  w w.  ja v  a  2  s . c o  m
 * 
 * @param region
 *            The region this client will communicate with. See
 *            {@link Region#getRegion(com.amazonaws.regions.Regions)} for
 *            accessing a given region.
 * @throws JMSException
 */
public void setRegion(Region region) throws JMSException {
    try {
        amazonSQSClient.setRegion(region);
    } catch (IllegalArgumentException ase) {
        JMSException jmsException = new JMSException(ase.getMessage());
        throw (JMSException) jmsException.initCause(ase);
    }
}