org.springframework.jms.UncategorizedJmsException Java Examples

The following examples show how to use org.springframework.jms.UncategorizedJmsException. 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: Journey.java    From k8s-fleetman with MIT License 6 votes vote down vote up
/**
 * Sends a message to the position queue - we've hardcoded this in at present - of course
 * this needs to be fixed on the course!
 * @param positionMessage
 * @throws InterruptedException 
 */
private void sendToQueue(Map<String, String> positionMessage) throws InterruptedException {
	boolean messageNotSent = true;
	while (messageNotSent)
	{
		// broadcast this report
		try
		{
			jmsTemplate.convertAndSend(queueName,positionMessage);
			messageNotSent = false;
		}
		catch (UncategorizedJmsException e)
		{
			// we are going to assume that this is due to downtime - back off and go again
			log.warn("Queue unavailable - backing off 5000ms before retry");
			delay(5000);
		}
	}
}
 
Example #2
Source File: RepublisherImplTest.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testMultipleExceptions() throws InterruptedException {
  republisher.start();

  Object publishedObject1 = new Object();
  CountDownLatch latch = new CountDownLatch(11);

  //republication succeeds
  publisher.publish(publishedObject1); // failure
  // should re-attempt publication every 100ms
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); throw new UncategorizedJmsException(""); }).times(10);

  publisher.publish(publishedObject1); // success
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); return null; });

  control.replay();

  republisher.publicationFailed(publishedObject1);

  //Thread.sleep(2000);
  latch.await();

  assertEquals(11, republisher.getNumberFailedPublications());
  assertEquals(0, republisher.getSizeUnpublishedList());

  control.verify();
}
 
Example #3
Source File: RepublisherImplTest.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testFailToPublish() throws InterruptedException {
  republisher.start();

  Object publishedObject1 = new Object();
  Object publishedObject2 = new Object();
  Object publishedObject3 = new Object();

  publisher.publish(publishedObject1); //failure
  EasyMock.expectLastCall().andThrow(new UncategorizedJmsException("")).anyTimes();
  publisher.publish(publishedObject2); //failure
  EasyMock.expectLastCall().andThrow(new UncategorizedJmsException("")).anyTimes();
  publisher.publish(publishedObject3); //failure
  EasyMock.expectLastCall().andThrow(new UncategorizedJmsException("")).anyTimes();

  control.replay();

  republisher.publicationFailed(publishedObject1);
  republisher.publicationFailed(publishedObject2);
  republisher.publicationFailed(publishedObject3);

  Thread.sleep(1000);

  assertTrue(republisher.getNumberFailedPublications() > 0);
  assertEquals(3, republisher.getSizeUnpublishedList());

  control.verify();
}
 
Example #4
Source File: JmsUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Convert the specified checked {@link javax.jms.JMSException JMSException} to a
 * Spring runtime {@link org.springframework.jms.JmsException JmsException} equivalent.
 * @param ex the original checked JMSException to convert
 * @return the Spring runtime JmsException wrapping the given exception
 */
public static JmsException convertJmsAccessException(JMSException ex) {
	Assert.notNull(ex, "JMSException must not be null");

	if (ex instanceof javax.jms.IllegalStateException) {
		return new org.springframework.jms.IllegalStateException((javax.jms.IllegalStateException) ex);
	}
	if (ex instanceof javax.jms.InvalidClientIDException) {
		return new InvalidClientIDException((javax.jms.InvalidClientIDException) ex);
	}
	if (ex instanceof javax.jms.InvalidDestinationException) {
		return new InvalidDestinationException((javax.jms.InvalidDestinationException) ex);
	}
	if (ex instanceof javax.jms.InvalidSelectorException) {
		return new InvalidSelectorException((javax.jms.InvalidSelectorException) ex);
	}
	if (ex instanceof javax.jms.JMSSecurityException) {
		return new JmsSecurityException((javax.jms.JMSSecurityException) ex);
	}
	if (ex instanceof javax.jms.MessageEOFException) {
		return new MessageEOFException((javax.jms.MessageEOFException) ex);
	}
	if (ex instanceof javax.jms.MessageFormatException) {
		return new MessageFormatException((javax.jms.MessageFormatException) ex);
	}
	if (ex instanceof javax.jms.MessageNotReadableException) {
		return new MessageNotReadableException((javax.jms.MessageNotReadableException) ex);
	}
	if (ex instanceof javax.jms.MessageNotWriteableException) {
		return new MessageNotWriteableException((javax.jms.MessageNotWriteableException) ex);
	}
	if (ex instanceof javax.jms.ResourceAllocationException) {
		return new ResourceAllocationException((javax.jms.ResourceAllocationException) ex);
	}
	if (ex instanceof javax.jms.TransactionInProgressException) {
		return new TransactionInProgressException((javax.jms.TransactionInProgressException) ex);
	}
	if (ex instanceof javax.jms.TransactionRolledBackException) {
		return new TransactionRolledBackException((javax.jms.TransactionRolledBackException) ex);
	}

	// fallback
	return new UncategorizedJmsException(ex);
}
 
Example #5
Source File: JmsTemplateTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testUncategorizedJmsException() throws Exception {
	doTestJmsException(new javax.jms.JMSException(""), UncategorizedJmsException.class);
}
 
Example #6
Source File: JmsUtils.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Convert the specified checked {@link javax.jms.JMSException JMSException} to a
 * Spring runtime {@link org.springframework.jms.JmsException JmsException} equivalent.
 * @param ex the original checked JMSException to convert
 * @return the Spring runtime JmsException wrapping the given exception
 */
public static JmsException convertJmsAccessException(JMSException ex) {
	Assert.notNull(ex, "JMSException must not be null");

	if (ex instanceof javax.jms.IllegalStateException) {
		return new org.springframework.jms.IllegalStateException((javax.jms.IllegalStateException) ex);
	}
	if (ex instanceof javax.jms.InvalidClientIDException) {
		return new InvalidClientIDException((javax.jms.InvalidClientIDException) ex);
	}
	if (ex instanceof javax.jms.InvalidDestinationException) {
		return new InvalidDestinationException((javax.jms.InvalidDestinationException) ex);
	}
	if (ex instanceof javax.jms.InvalidSelectorException) {
		return new InvalidSelectorException((javax.jms.InvalidSelectorException) ex);
	}
	if (ex instanceof javax.jms.JMSSecurityException) {
		return new JmsSecurityException((javax.jms.JMSSecurityException) ex);
	}
	if (ex instanceof javax.jms.MessageEOFException) {
		return new MessageEOFException((javax.jms.MessageEOFException) ex);
	}
	if (ex instanceof javax.jms.MessageFormatException) {
		return new MessageFormatException((javax.jms.MessageFormatException) ex);
	}
	if (ex instanceof javax.jms.MessageNotReadableException) {
		return new MessageNotReadableException((javax.jms.MessageNotReadableException) ex);
	}
	if (ex instanceof javax.jms.MessageNotWriteableException) {
		return new MessageNotWriteableException((javax.jms.MessageNotWriteableException) ex);
	}
	if (ex instanceof javax.jms.ResourceAllocationException) {
		return new ResourceAllocationException((javax.jms.ResourceAllocationException) ex);
	}
	if (ex instanceof javax.jms.TransactionInProgressException) {
		return new TransactionInProgressException((javax.jms.TransactionInProgressException) ex);
	}
	if (ex instanceof javax.jms.TransactionRolledBackException) {
		return new TransactionRolledBackException((javax.jms.TransactionRolledBackException) ex);
	}

	// fallback
	return new UncategorizedJmsException(ex);
}
 
Example #7
Source File: JmsTemplateTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testUncategorizedJmsException() throws Exception {
	doTestJmsException(new javax.jms.JMSException(""), UncategorizedJmsException.class);
}
 
Example #8
Source File: JmsUtils.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Convert the specified checked {@link javax.jms.JMSException JMSException} to a
 * Spring runtime {@link org.springframework.jms.JmsException JmsException} equivalent.
 * @param ex the original checked JMSException to convert
 * @return the Spring runtime JmsException wrapping the given exception
 */
public static JmsException convertJmsAccessException(JMSException ex) {
	Assert.notNull(ex, "JMSException must not be null");

	if (ex instanceof javax.jms.IllegalStateException) {
		return new org.springframework.jms.IllegalStateException((javax.jms.IllegalStateException) ex);
	}
	if (ex instanceof javax.jms.InvalidClientIDException) {
		return new InvalidClientIDException((javax.jms.InvalidClientIDException) ex);
	}
	if (ex instanceof javax.jms.InvalidDestinationException) {
		return new InvalidDestinationException((javax.jms.InvalidDestinationException) ex);
	}
	if (ex instanceof javax.jms.InvalidSelectorException) {
		return new InvalidSelectorException((javax.jms.InvalidSelectorException) ex);
	}
	if (ex instanceof javax.jms.JMSSecurityException) {
		return new JmsSecurityException((javax.jms.JMSSecurityException) ex);
	}
	if (ex instanceof javax.jms.MessageEOFException) {
		return new MessageEOFException((javax.jms.MessageEOFException) ex);
	}
	if (ex instanceof javax.jms.MessageFormatException) {
		return new MessageFormatException((javax.jms.MessageFormatException) ex);
	}
	if (ex instanceof javax.jms.MessageNotReadableException) {
		return new MessageNotReadableException((javax.jms.MessageNotReadableException) ex);
	}
	if (ex instanceof javax.jms.MessageNotWriteableException) {
		return new MessageNotWriteableException((javax.jms.MessageNotWriteableException) ex);
	}
	if (ex instanceof javax.jms.ResourceAllocationException) {
		return new ResourceAllocationException((javax.jms.ResourceAllocationException) ex);
	}
	if (ex instanceof javax.jms.TransactionInProgressException) {
		return new TransactionInProgressException((javax.jms.TransactionInProgressException) ex);
	}
	if (ex instanceof javax.jms.TransactionRolledBackException) {
		return new TransactionRolledBackException((javax.jms.TransactionRolledBackException) ex);
	}

	// fallback
	return new UncategorizedJmsException(ex);
}
 
Example #9
Source File: JmsTemplateTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testUncategorizedJmsException() throws Exception {
	doTestJmsException(new javax.jms.JMSException(""), UncategorizedJmsException.class);
}
 
Example #10
Source File: RepublisherImplTest.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test republication if publisher throws 1 exception.
 * @throws InterruptedException
 */
@Test
public void testSingleRepublicationAfterException() throws InterruptedException {
  republisher.start();

  Object publishedObject = new Object();

  //re-publication fails
  publisher.publish(publishedObject);
  EasyMock.expectLastCall().andThrow(new UncategorizedJmsException(""));

  //second succeeds
  publisher.publish(publishedObject);

  control.replay();

  republisher.publicationFailed(publishedObject);

  Thread.sleep(500);

  assertEquals(2, republisher.getNumberFailedPublications()); //manual call + automatic publication
  assertEquals(0, republisher.getSizeUnpublishedList());

  control.verify();
}
 
Example #11
Source File: RepublisherImplTest.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
@Ignore("This test is flaky!")
public void testMultiplePublicationsWithExceptions() throws InterruptedException {
  republisher.start();

  Object publishedObject1 = new Object();
  Object publishedObject2 = new Object();
  Object publishedObject3 = new Object();
  CountDownLatch latch = new CountDownLatch(18);

  //republication succeeds
  publisher.publish(publishedObject1); // failure
  // should re-attempt publication every 100ms
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); throw new UncategorizedJmsException(""); }).times(10);

  publisher.publish(publishedObject1); //success
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); return null; });

  publisher.publish(publishedObject2); //failure
  // should re-attempt publication every 100ms
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); throw new UncategorizedJmsException(""); }).times(5);

  publisher.publish(publishedObject2); //success
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); return null; });
  publisher.publish(publishedObject3); //success
  EasyMock.expectLastCall().andAnswer(() -> { latch.countDown(); return null; });

  control.replay();

  republisher.publicationFailed(publishedObject1);
  republisher.publicationFailed(publishedObject2);
  republisher.publicationFailed(publishedObject3);

  // Thread.sleep(2000);
  latch.await();

  assertEquals(11 + 6 + 1, republisher.getNumberFailedPublications());
  assertEquals(0, republisher.getSizeUnpublishedList());

  control.verify();
}