Search in sources :

Example 96 with JMSException

use of javax.jms.JMSException in project wso2-synapse by wso2.

the class JmsStore method getConsumer.

public MessageConsumer getConsumer() throws SynapseException {
    JmsConsumer consumer = new JmsConsumer(this);
    consumer.setId(nextConsumerId());
    try {
        Connection connection = newConnection();
        Session session = newSession(connection, Session.CLIENT_ACKNOWLEDGE, false);
        javax.jms.MessageConsumer jmsConsumer = newConsumer(session);
        consumer.setConnection(connection).setSession(session).setConsumer(jmsConsumer);
        if (logger.isDebugEnabled()) {
            logger.debug(nameString() + " created message consumer " + consumer.getId());
        }
    } catch (JMSException | StoreForwardException e) {
        throw new SynapseException("Could not create a Message Consumer for " + nameString(), e);
    }
    return consumer;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Connection(javax.jms.Connection) QueueConnection(javax.jms.QueueConnection) StoreForwardException(org.apache.synapse.message.StoreForwardException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Example 97 with JMSException

use of javax.jms.JMSException in project rabbitmq-jms-client by rabbitmq.

the class RMQSession method getBrowsingChannel.

/**
 * Get a (new) channel for queue browsing.
 * @return channel for browsing queues
 * @throws JMSException if channel not available
 */
Channel getBrowsingChannel() throws JMSException {
    try {
        synchronized (this.bcLock) {
            // not transactional
            Channel chan = this.getConnection().createRabbitChannel(false);
            this.browsingChannels.add(chan);
            return chan;
        }
    } catch (Exception e) {
        // includes unchecked exceptions, e.g. ShutdownSignalException
        throw new RMQJMSException("Cannot create browsing channel", e);
    }
}
Also used : RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) Channel(com.rabbitmq.client.Channel) TimeoutException(java.util.concurrent.TimeoutException) RMQJMSSelectorException(com.rabbitmq.jms.util.RMQJMSSelectorException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) IOException(java.io.IOException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Example 98 with JMSException

use of javax.jms.JMSException in project rabbitmq-jms-client by rabbitmq.

the class RMQBytesMessage method recreate.

public static RMQMessage recreate(BytesMessage msg) throws JMSException {
    msg.reset();
    long bodyLength = msg.getBodyLength();
    int bodySize = (int) Math.min(Math.max(0L, bodyLength), Integer.MAX_VALUE);
    if (bodyLength != bodySize)
        throw new JMSException(String.format("BytesMessage body invalid length (%s). Negative or too large.", bodyLength));
    try {
        RMQBytesMessage rmqBMsg = new RMQBytesMessage();
        RMQMessage.copyAttributes(rmqBMsg, msg);
        byte[] byteArray = new byte[bodySize];
        if (bodyLength > 0) {
            if (// must read the whole body at once
            bodySize != msg.readBytes(byteArray, bodySize))
                throw new MessageEOFException("Cannot read all of non-RMQ Message body.");
        }
        rmqBMsg.writeBytes(byteArray);
        // make body read-only and set pointer to start.
        rmqBMsg.reset();
        return rmqBMsg;
    } catch (OutOfMemoryError e) {
        throw new RMQJMSException("Body too large for conversion to RMQMessage.", e);
    }
}
Also used : RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) MessageEOFException(javax.jms.MessageEOFException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException)

Example 99 with JMSException

use of javax.jms.JMSException in project rabbitmq-jms-client by rabbitmq.

the class RMQStreamMessage method readPrimitiveType.

private Object readPrimitiveType(Class<?> type) throws JMSException {
    if (!this.reading)
        throw new MessageNotReadableException(NOT_READABLE);
    if (this.readbuf != null) {
        throw new MessageFormatException("You must call 'int readBytes(byte[])' since the buffer is not empty");
    }
    boolean success = true;
    try {
        this.bin.mark(0);
        Object o = RMQMessage.readPrimitive(in);
        if (o instanceof byte[]) {
            if (type == ByteArray.class || type == Object.class) {
                return o;
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "byte[]"));
            }
        } else if (type == ByteArray.class) {
            if (o == null) {
                return null;
            }
            throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "byte[]"));
        } else if (type == Boolean.class) {
            if (o == null) {
                return Boolean.FALSE;
            } else if (o instanceof Boolean) {
                return o;
            } else if (o instanceof String) {
                return Boolean.parseBoolean((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "boolean"));
            }
        } else if (type == Byte.class) {
            if (o instanceof Byte) {
                return o;
            } else if (o instanceof String) {
                return Byte.parseByte((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "byte"));
            }
        } else if (type == Short.class) {
            if (o instanceof Byte) {
                return (short) (Byte) o;
            } else if (o instanceof Short) {
                return o;
            } else if (o instanceof String) {
                return Short.parseShort((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "byte"));
            }
        } else if (type == Integer.class) {
            if (o instanceof Byte) {
                return (int) (Byte) o;
            } else if (o instanceof Short) {
                return (int) (Short) o;
            } else if (o instanceof Integer) {
                return o;
            } else if (o instanceof String) {
                return Integer.parseInt((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "int"));
            }
        } else if (type == Character.class) {
            if (o instanceof Character) {
                return o;
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "char"));
            }
        } else if (type == Long.class) {
            if (o instanceof Byte) {
                return (long) (Byte) o;
            } else if (o instanceof Short) {
                return (long) (Short) o;
            } else if (o instanceof Integer) {
                return (long) (Integer) o;
            } else if (o instanceof Long) {
                return o;
            } else if (o instanceof String) {
                return Long.parseLong((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "long"));
            }
        } else if (type == Float.class) {
            if (o instanceof Float) {
                return (Float) o;
            } else if (o instanceof String) {
                return Float.parseFloat((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "float"));
            }
        } else if (type == Double.class) {
            if (o instanceof Float) {
                return (double) (Float) o;
            } else if (o instanceof Double) {
                return (Double) o;
            } else if (o instanceof String) {
                return Double.parseDouble((String) o);
            } else {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "double"));
            }
        } else if (type == String.class) {
            if (o == null) {
                return null;
            } else if (o instanceof byte[]) {
                throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, "String"));
            } else {
                return o.toString();
            }
        } else if (type == Object.class) {
            return o;
        } else {
            throw new MessageFormatException(String.format(UNABLE_TO_CAST, o, type.toString()));
        }
    } catch (NumberFormatException x) {
        success = false;
        throw x;
    } catch (ClassNotFoundException x) {
        success = false;
        throw new RMQJMSException(x);
    } catch (EOFException x) {
        success = false;
        throw new MessageEOFException(MSG_EOF);
    } catch (UTFDataFormatException x) {
        success = false;
        throw new RMQMessageFormatException(x);
    } catch (IOException x) {
        success = false;
        throw new RMQJMSException(x);
    } catch (Exception x) {
        success = false;
        if (x instanceof JMSException) {
            throw (JMSException) x;
        } else {
            throw new RMQJMSException(x);
        }
    } finally {
        if (!success) {
            this.bin.reset();
        }
    }
}
Also used : MessageEOFException(javax.jms.MessageEOFException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) RMQMessageFormatException(com.rabbitmq.jms.util.RMQMessageFormatException) MessageEOFException(javax.jms.MessageEOFException) EOFException(java.io.EOFException) RMQMessageFormatException(com.rabbitmq.jms.util.RMQMessageFormatException) MessageFormatException(javax.jms.MessageFormatException) MessageNotReadableException(javax.jms.MessageNotReadableException) IOException(java.io.IOException) RMQMessageFormatException(com.rabbitmq.jms.util.RMQMessageFormatException) IOException(java.io.IOException) MessageEOFException(javax.jms.MessageEOFException) EOFException(java.io.EOFException) JMSException(javax.jms.JMSException) MessageNotWriteableException(javax.jms.MessageNotWriteableException) MessageFormatException(javax.jms.MessageFormatException) MessageNotReadableException(javax.jms.MessageNotReadableException) UTFDataFormatException(java.io.UTFDataFormatException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) UTFDataFormatException(java.io.UTFDataFormatException)

Example 100 with JMSException

use of javax.jms.JMSException in project rabbitmq-jms-client by rabbitmq.

the class ConnectionCloseIT method testCloseDuringReceiveWithExceptionListener.

@Test
public void testCloseDuringReceiveWithExceptionListener() throws Exception {
    ExceptionListener eListener = new ExceptionListener() {

        @Override
        public void onException(JMSException exception) {
            atomBool.set(true);
            atomJMSExceptionRef.set(exception);
        }
    };
    topicConn.setExceptionListener(eListener);
    topicConn.start();
    TopicSession topicSession = topicConn.createTopicSession(true, Session.DUPS_OK_ACKNOWLEDGE);
    Topic topicDestination = topicSession.createTopic(TOPIC_NAME);
    MessageConsumer messageConsumer = topicSession.createConsumer(topicDestination);
    Completion receiveCompletion = new Completion();
    Thread receiver = new DelayedReceive(ZERO_SECONDS, messageConsumer, receiveCompletion);
    Thread closer = new DelayedClose(ONE_SECOND, topicConn);
    receiver.start();
    closer.start();
    try {
        receiveCompletion.waitUntilComplete(FIVE_SECONDS, TimeUnit.MILLISECONDS);
    } catch (TimeoutException e) {
        fail("Timeout before receive returns!");
    }
    if (atomBool.get()) {
        fail(String.format("ExceptionListener driven with exception %s", atomJMSExceptionRef.get()));
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TopicSession(javax.jms.TopicSession) Completion(com.rabbitmq.jms.client.Completion) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Aggregations

JMSException (javax.jms.JMSException)1094 Message (javax.jms.Message)355 Test (org.junit.Test)335 Session (javax.jms.Session)309 TextMessage (javax.jms.TextMessage)302 Connection (javax.jms.Connection)271 MessageProducer (javax.jms.MessageProducer)169 MessageConsumer (javax.jms.MessageConsumer)156 Destination (javax.jms.Destination)105 ObjectMessage (javax.jms.ObjectMessage)100 Queue (javax.jms.Queue)100 MapMessage (javax.jms.MapMessage)70 ConnectionFactory (javax.jms.ConnectionFactory)68 CountDownLatch (java.util.concurrent.CountDownLatch)64 IOException (java.io.IOException)62 BytesMessage (javax.jms.BytesMessage)59 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)54 MessageListener (javax.jms.MessageListener)49 NamingException (javax.naming.NamingException)44 MessageFormatException (javax.jms.MessageFormatException)43