Java Code Examples for javax.jms.JMSException#getMessage()

The following examples show how to use javax.jms.JMSException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Build a descriptive exception message for the given JMSException,
 * incorporating a linked exception's message if appropriate.
 * @param ex the JMSException to build a message for
 * @return the descriptive message String
 * @see javax.jms.JMSException#getLinkedException()
 */
public static String buildExceptionMessage(JMSException ex) {
	String message = ex.getMessage();
	Exception linkedEx = ex.getLinkedException();
	if (linkedEx != null) {
		if (message == null) {
			message = linkedEx.toString();
		}
		else {
			String linkedMessage = linkedEx.getMessage();
			if (linkedMessage != null && !message.contains(linkedMessage)) {
				message = message + "; nested exception is " + linkedEx;
			}
		}
	}
	return message;
}
 
Example 2
Source File: ConnectionFactoryIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20_000)
public void testConfigureFutureFactoryFromURITypeUnknown() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        // Ignore errors from peer close due to not sending any Open / Close frames
        testPeer.setSuppressReadExceptionOnClose(true);

        String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?provider.futureType=unknown";

        JmsConnectionFactory factory = new JmsConnectionFactory(uri);

        try {
            factory.createConnection();
            fail("Should not allow a connection to proceed with a bad future factory type");
        } catch (JMSException ex) {
            String message = ex.getMessage();
            assertTrue(message.contains("No ProviderFuture implementation"));
        }

        testPeer.waitForAllHandlersToCompleteNoAssert(1000);
    }
}
 
Example 3
Source File: JmsUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Build a descriptive exception message for the given JMSException,
 * incorporating a linked exception's message if appropriate.
 * @param ex the JMSException to build a message for
 * @return the descriptive message String
 * @see javax.jms.JMSException#getLinkedException()
 */
public static String buildExceptionMessage(JMSException ex) {
	String message = ex.getMessage();
	Exception linkedEx = ex.getLinkedException();
	if (linkedEx != null) {
		if (message == null) {
			message = linkedEx.toString();
		}
		else {
			String linkedMessage = linkedEx.getMessage();
			if (linkedMessage != null && !message.contains(linkedMessage)) {
				message = message + "; nested exception is " + linkedEx;
			}
		}
	}
	return message;
}
 
Example 4
Source File: WsIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testNonSslWebSocketConnectionFailsToSslServer() throws Exception {
    TransportOptions serverOptions = new TransportOptions();
    serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
    serverOptions.setKeyStorePassword(PASSWORD);
    serverOptions.setVerifyHost(false);

    try (NettySimpleAmqpServer server = new NettySimpleAmqpServer(serverOptions, true, false, true)) {
        server.start();

        JmsConnectionFactory factory = new JmsConnectionFactory("amqpws://localhost:" + server.getServerPort());

        try {
            factory.createConnection();
            fail("should not have connected");
        }
        catch (JMSException jmse) {
            String message = jmse.getMessage();
            assertNotNull(message);
            assertTrue("Unexpected message: " + message, message.contains("Connection failed"));
        }
    }
}
 
Example 5
Source File: JMSClientConnector.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch a text or binary message from the JMS queue and use the correct
 * deserializer for the received message.
 *
 * @return One new IMonitoringRecord
 *
 * @throws ConnectorDataTransmissionException
 *             if the message type is neither binary nor text, or if a
 *             JMSException occurs
 * @throws ConnectorEndOfDataException
 *             if the received message is null indicating that the consumer is
 *             closed
 */
@Override
public IMonitoringRecord deserializeNextRecord()
		throws ConnectorDataTransmissionException, ConnectorEndOfDataException {
	final Message message;
	try {
		message = this.consumer.receive();
		if (message != null) {
			if (message instanceof BytesMessage) {
				return this.deserialize((BytesMessage) message);
			} else if (message instanceof TextMessage) {
				return this.deserialize(((TextMessage) message).getText());
			} else {
				throw new ConnectorDataTransmissionException(
						"Unsupported message type " + message.getClass().getCanonicalName());
			}
		} else {
			throw new ConnectorEndOfDataException("No more records in the queue");
		}
	} catch (final JMSException e) {
		throw new ConnectorDataTransmissionException(e.getMessage(), e);
	}

}
 
Example 6
Source File: WsIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testWebsocketConnectionToBlackHoleServerTimesOut() throws Exception {
    TransportOptions serverOptions = new TransportOptions();

    try (NettyBlackHoleServer server = new NettyBlackHoleServer(serverOptions, false)) {
        server.start();

        JmsConnectionFactory factory = new JmsConnectionFactory("amqpws://localhost:" + server.getServerPort() + "?transport.connectTimeout=25");

        try {
            factory.createConnection();
            fail("should not have connected");
        }
        catch (JMSException jmse) {
            String message = jmse.getMessage();
            assertNotNull(message);
            assertTrue("Unexpected message: " + message, message.contains("WebSocket handshake timed out"));
        }
    }
}
 
Example 7
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setDeliveryDelay(long deliveryDelay) {
   try {
      producer.setDeliveryDelay(deliveryDelay);
      return this;
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
}
 
Example 8
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public long getTimeToLive() {
   long timeToLive = 0;
   try {
      timeToLive = producer.getTimeToLive();
      return timeToLive;
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
}
 
Example 9
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setTimeToLive(long timeToLive) {
   try {
      producer.setTimeToLive(timeToLive);
      return this;
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
}
 
Example 10
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setPriority(int priority) {
   try {
      producer.setPriority(priority);
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
   return this;
}
 
Example 11
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int getDeliveryMode() {
   try {
      return producer.getDeliveryMode();
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
}
 
Example 12
Source File: JMSProducerImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer send(final Destination destination, final Map<String, Object> body) {
    final MapMessage message = wrap(context.createMapMessage());
    if (body != null) {
        try {
            for (final Map.Entry<String, Object> entry : body.entrySet()) {
                final String name = entry.getKey();
                final Object v = entry.getValue();
                if (v instanceof String) {
                    message.setString(name, (String) v);
                } else if (v instanceof Long) {
                    message.setLong(name, (Long) v);
                } else if (v instanceof Double) {
                    message.setDouble(name, (Double) v);
                } else if (v instanceof Integer) {
                    message.setInt(name, (Integer) v);
                } else if (v instanceof Character) {
                    message.setChar(name, (Character) v);
                } else if (v instanceof Short) {
                    message.setShort(name, (Short) v);
                } else if (v instanceof Boolean) {
                    message.setBoolean(name, (Boolean) v);
                } else if (v instanceof Float) {
                    message.setFloat(name, (Float) v);
                } else if (v instanceof Byte) {
                    message.setByte(name, (Byte) v);
                } else if (v instanceof byte[]) {
                    byte[] array = (byte[]) v;
                    message.setBytes(name, array, 0, array.length);
                } else {
                    message.setObject(name, v);
                }
            }
        } catch (final JMSException e) {
            throw new MessageFormatRuntimeException(e.getMessage());
        }
    }
    send(destination, message);
    return this;
}
 
Example 13
Source File: JMSProducerImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public int getDeliveryMode() {
    try {
        return producer.getDeliveryMode();
    } catch (final JMSException e) {
        final JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
        e2.initCause(e);
        throw e2;
    }
}
 
Example 14
Source File: JMSProducerImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setPriority(final int priority) {
    try {
        producer.setPriority(priority);
    } catch (final JMSException e) {
        final JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
        e2.initCause(e);
        throw e2;
    }
    return this;
}
 
Example 15
Source File: ITJms_1_1_TracingMessageProducer.java    From brave with Apache License 2.0 5 votes vote down vote up
void should_set_error(JMSRunnable send) {
  String message;
  try {
    send.run();
    throw new AssertionError("expected to throw");
  } catch (JMSException e) {
    message = e.getMessage();
  }

  testSpanHandler.takeRemoteSpanWithErrorMessage(PRODUCER, message);
}
 
Example 16
Source File: JMSProducerImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setDeliveryDelay(final long deliveryDelay) {
    try {
        producer.setDeliveryDelay(deliveryDelay);
        return this;
    } catch (final JMSException e) {
        JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
        e2.initCause(e);
        throw e2;
    }
}
 
Example 17
Source File: JmsExceptionThrowingBiConsumer.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Wraps a {@link JmsExceptionThrowingBiConsumer} returning a BiConsumer by converting thrown {@link JMSException}s
 * to {@link JMSRuntimeException}s.
 *
 * @param throwingConsumer the JmsExceptionThrowingBiConsumer that throws {@link JMSException}
 * @return a BiConsumer that throws {@link JMSRuntimeException}
 */
static <T> BiConsumer<Message, T> wrap(final JmsExceptionThrowingBiConsumer<T> throwingConsumer) {
    return (m, v) -> {
        try {
            throwingConsumer.accept(m, v);
        } catch (final JMSException jmsException) {
            throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(),
                    jmsException.getCause());
        }
    };
}
 
Example 18
Source File: JmsExceptionThrowingFunction.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Wraps a {@link org.eclipse.ditto.services.connectivity.messaging.amqp.JmsExceptionThrowingFunction} returning
 * a function by converting thrown {@link javax.jms.JMSException} to {@link javax.jms.JMSRuntimeException}.
 *
 * @param throwingFunction the JmsExceptionThrowingBiConsumer that throws {@link javax.jms.JMSException}
 * @param <T> type of results.
 * @return a function that throws {@link javax.jms.JMSRuntimeException}
 */
static <T> Function<Message, T> wrap(final JmsExceptionThrowingFunction<T> throwingFunction) {
    return (m) -> {
        try {
            return throwingFunction.apply(m);
        } catch (final JMSException jmsException) {
            throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(),
                    jmsException.getCause());
        }
    };
}
 
Example 19
Source File: MockJMSObjectMessage.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected <T> T doGetBody(Class<T> asType) throws JMSException {
    try {
        return (T) getObject();
    } catch (JMSException e) {
        throw new MessageFormatException("Failed to read Object: " + e.getMessage());
    }
}
 
Example 20
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * Setup the connection.
 *
 * @throws ResourceException Thrown if a connection couldn't be created
 */
private void setup() throws ResourceException {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("setup()");
   }

   try {

      createCF();

      boolean transacted = cri.isTransacted();
      int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
      if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION) {
         if (userName != null && password != null) {
            connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection(userName, password);
         } else {
            connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection();
         }

         connection.setExceptionListener(this);

         xaSession = connection.createXATopicSession();
         nonXAsession = connection.createNonXATopicSession(transacted, acknowledgeMode);

      } else if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION) {
         if (userName != null && password != null) {
            connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection(userName, password);
         } else {
            connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection();
         }

         connection.setExceptionListener(this);

         xaSession = connection.createXAQueueSession();
         nonXAsession = connection.createNonXAQueueSession(transacted, acknowledgeMode);

      } else {
         if (userName != null && password != null) {
            connection = (ActiveMQXAConnection) connectionFactory.createXAConnection(userName, password);
         } else {
            connection = (ActiveMQXAConnection) connectionFactory.createXAConnection();
         }

         connection.setExceptionListener(this);

         xaSession = connection.createXASession();
         nonXAsession = connection.createNonXASession(transacted, acknowledgeMode);
      }

   } catch (JMSException je) {
      throw new ResourceException(je.getMessage(), je);
   }
}