Search in sources :

Example 86 with JMSException

use of javax.jms.JMSException in project Protocol-Adapter-OSLP by OSGP.

the class TariffSwitchingGetStatusRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.info("Processing tariff switching get status request message");
    String correlationUid = null;
    String domain = null;
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;
    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED) ? message.getBooleanProperty(Constants.IS_SCHEDULED) : false;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }
    LOGGER.info("Calling DeviceService function: {} for domain: {} {}", messageType, domain, domainVersion);
    final GetStatusDeviceRequest deviceRequest = new GetStatusDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, DomainTypeDto.TARIFF_SWITCHING, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
    this.deviceService.getStatus(deviceRequest);
}
Also used : JMSException(javax.jms.JMSException) GetStatusDeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.GetStatusDeviceRequest)

Example 87 with JMSException

use of javax.jms.JMSException in project ignite by apache.

the class IgniteJmsStreamerTest method produceObjectMessages.

private void produceObjectMessages(Destination dest, boolean singleMsg) throws JMSException {
    Session ses = connFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer mp = ses.createProducer(dest);
    HashSet<TestTransformers.TestObject> set = new HashSet<>();
    for (String key : TEST_DATA.keySet()) {
        TestTransformers.TestObject to = new TestTransformers.TestObject(key, TEST_DATA.get(key));
        set.add(to);
    }
    int messagesSent;
    if (singleMsg) {
        mp.send(ses.createObjectMessage(set));
        messagesSent = 1;
    } else {
        for (TestTransformers.TestObject to : set) mp.send(ses.createObjectMessage(to));
        messagesSent = set.size();
    }
    if (dest instanceof Queue) {
        try {
            assertEquals(messagesSent, broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics().getMessages().getCount());
        } catch (Exception e) {
            fail(e.toString());
        }
    }
}
Also used : MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) HashSet(java.util.HashSet)

Example 88 with JMSException

use of javax.jms.JMSException in project ignite by apache.

the class IgniteJmsStreamerTest method produceStringMessages.

private void produceStringMessages(Destination dest, boolean singleMsg) throws JMSException {
    Session ses = connFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer mp = ses.createProducer(dest);
    HashSet<String> set = new HashSet<>();
    for (String key : TEST_DATA.keySet()) set.add(key + "," + TEST_DATA.get(key));
    int messagesSent;
    if (singleMsg) {
        StringBuilder sb = new StringBuilder();
        for (String s : set) sb.append(s).append("|");
        sb.deleteCharAt(sb.length() - 1);
        mp.send(ses.createTextMessage(sb.toString()));
        messagesSent = 1;
    } else {
        for (String s : set) mp.send(ses.createTextMessage(s));
        messagesSent = set.size();
    }
    if (dest instanceof Queue) {
        try {
            assertEquals(messagesSent, broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics().getMessages().getCount());
        } catch (Exception e) {
            fail(e.toString());
        }
    }
}
Also used : MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) HashSet(java.util.HashSet)

Example 89 with JMSException

use of javax.jms.JMSException in project hive by apache.

the class TestNotificationListener method onMessage.

@Override
public void onMessage(Message msg) {
    String event;
    try {
        event = msg.getStringProperty(HCatConstants.HCAT_EVENT);
        String format = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT);
        String version = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_VERSION);
        String messageBody = ((TextMessage) msg).getText();
        actualMessages.add(event);
        MessageDeserializer deserializer = MessageFactory.getDeserializer(format, version);
        if (event.equals(HCatConstants.HCAT_CREATE_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            CreateDatabaseMessage message = deserializer.getCreateDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_CREATE_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            CreateTableMessage message = deserializer.getCreateTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((CreateTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_ADD_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            AddPartitionMessage message = deserializer.getAddPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AddPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AddPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AddPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((AddPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_ALTER_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            // for alter partition events
            AlterPartitionMessage message = deserializer.getAlterPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getKeyValues().size());
            Assert.assertTrue(message.getKeyValues().values().contains("2011"));
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AlterPartitionMessage) message2).getKeyValues().size());
            Assert.assertTrue(((AlterPartitionMessage) message2).getKeyValues().values().contains("2011"));
        } else if (event.equals(HCatConstants.HCAT_DROP_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            DropPartitionMessage message = deserializer.getDropPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((DropPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((DropPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_DROP_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            DropTableMessage message = deserializer.getDropTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_DROP_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            DropDatabaseMessage message = deserializer.getDropDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_ALTER_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            AlterTableMessage message = deserializer.getAlterTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(TableType.MANAGED_TABLE.toString(), message.getTableType());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_PARTITION_DONE_EVENT)) {
            // TODO: Fill in when PARTITION_DONE_EVENT is supported.
            Assert.assertTrue("Unexpected: HCAT_PARTITION_DONE_EVENT not supported (yet).", false);
        } else {
            Assert.assertTrue("Unexpected event-type: " + event, false);
        }
    } catch (JMSException e) {
        e.printStackTrace(System.err);
        assert false;
    } finally {
        messageReceivedSignal.countDown();
    }
}
Also used : MessageDeserializer(org.apache.hive.hcatalog.messaging.MessageDeserializer) CreateDatabaseMessage(org.apache.hive.hcatalog.messaging.CreateDatabaseMessage) CreateTableMessage(org.apache.hive.hcatalog.messaging.CreateTableMessage) JMSException(javax.jms.JMSException) HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) DropTableMessage(org.apache.hive.hcatalog.messaging.DropTableMessage) DropPartitionMessage(org.apache.hive.hcatalog.messaging.DropPartitionMessage) DropDatabaseMessage(org.apache.hive.hcatalog.messaging.DropDatabaseMessage) AlterTableMessage(org.apache.hive.hcatalog.messaging.AlterTableMessage) AddPartitionMessage(org.apache.hive.hcatalog.messaging.AddPartitionMessage) TextMessage(javax.jms.TextMessage) AlterPartitionMessage(org.apache.hive.hcatalog.messaging.AlterPartitionMessage)

Example 90 with JMSException

use of javax.jms.JMSException in project hono by eclipse.

the class DeviceRegistrationIT method testOpenReceiverFailsForMalformedReplyToAddress.

/**
 * Verifies that a client must use a correct <em>reply-to</em> address when opening a link for receiving registration responses.
 *
 * @throws Exception if the test fails.
 */
@Test
public void testOpenReceiverFailsForMalformedReplyToAddress() throws Exception {
    // GIVEN a source address that does not contain a resourceId segment
    final Destination invalidSource = new JmsQueue("registration/" + JmsIntegrationTestSupport.TEST_TENANT_ID);
    // WHEN trying to open a receiver link using the malformed source address
    try {
        registration.createConsumerWithoutListener(invalidSource);
        fail("Should have failed to create consumer");
    } catch (JMSException e) {
    // THEN the attempt fails
    }
}
Also used : Destination(javax.jms.Destination) JmsQueue(org.apache.qpid.jms.JmsQueue) JMSException(javax.jms.JMSException) Test(org.junit.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