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

The following examples show how to use javax.jms.JMSException#printStackTrace() . 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: SecureConfigurationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemporaryQueue() throws Exception {
   ConnectionFactory connectionFactory = getConnectionFactory("a", "a");
   String message = "blah";

   //Expect to be able to create subscriber on pre-defined/existing queue.
   String messageRecieved = sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryQueue(), (d, s) -> s.createConsumer(d));
   Assert.assertEquals(message, messageRecieved);

   connectionFactory = getConnectionFactory("c", "c");
   try {
      sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryQueue(), (d, s) -> s.createConsumer(d));
      Assert.fail("Security exception expected, but did not occur, excepetion expected as not permissioned to create a temporary queue");
   } catch (JMSSecurityException jmsse) {
   } catch (JMSException e) {
      e.printStackTrace();
      Assert.fail("thrown a JMSEXception instead of a JMSSEcurityException");
   }
}
 
Example 2
Source File: DurableSubscriptionOffline3Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessage(Message message) {
   count++;

   try {
      Object b = message.getObjectProperty("$b");
      if (b != null) {
         boolean c = message.getBooleanProperty("$c");
         assertTrue("", c);
      } else {
         String d = message.getStringProperty("$d");
         assertTrue("", "D1".equals(d) || "D2".equals(d));
      }
   } catch (JMSException e) {
      e.printStackTrace();
      exceptions.add(e);
   }
}
 
Example 3
Source File: MessageOrderingTest.java    From olat with Apache License 2.0 6 votes vote down vote up
public void onMessage(Message arg0) {
    try {
        if (!(arg0 instanceof MapMessage)) {
            new Exception("Wrong message type: " + arg0).printStackTrace(System.out);
            System.exit(1);
        }
        MapMessage message = (MapMessage) arg0;
        int receivedCounter = message.getInt("Counter");
        System.out.println("Received counter=" + receivedCounter);
        if (receivedCounter != counter_) {
            new Exception("Out of order, expected " + counter_ + ", but got " + receivedCounter).printStackTrace(System.out);
            System.exit(1);
        }
        counter_++;
    } catch (JMSException e) {
        e.printStackTrace(System.out);
        System.exit(1);
    }
}
 
Example 4
Source File: SoakSender.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private synchronized void disconnect() {
   if (connection != null) {
      try {
         connection.setExceptionListener(null);
         connection.close();
      } catch (JMSException e) {
         e.printStackTrace();
      } finally {
         connection = null;
      }
   }
}
 
Example 5
Source File: ActiveMQMapMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testGetChar() {
   ActiveMQMapMessage msg = new ActiveMQMapMessage();
   try {
      msg.setChar(this.name, 'a');
      msg = (ActiveMQMapMessage) msg.copy();
      assertTrue(msg.getChar(this.name) == 'a');
   } catch (JMSException jmsEx) {
      jmsEx.printStackTrace();
      assertTrue(false);
   }
}
 
Example 6
Source File: Consumer.java    From pro-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
	try {
		log.info("Consumer> " + message.getBody(Object.class));
	}catch (JMSException ex) {
		ex.printStackTrace();
	}
}
 
Example 7
Source File: JmsTransactionTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeMutableObjectInObjectMessageThenRollback() throws Exception {
   ArrayList<String> list = new ArrayList<>();
   list.add("First");
   Message outbound = session.createObjectMessage(list);
   outbound.setStringProperty("foo", "abc");

   beginTx();
   producer.send(outbound);
   commitTx();

   beginTx();
   Message message = consumer.receive(5000);

   List<String> body = assertReceivedObjectMessageWithListBody(message);

   // now lets try mutate it
   try {
      message.setStringProperty("foo", "def");
      fail("Cannot change properties of the object!");
   } catch (JMSException e) {
      System.out.println("Caught expected exception: " + e);
      e.printStackTrace();
   }
   body.clear();
   body.add("This should never be seen!");
   rollbackTx();

   beginTx();
   message = consumer.receive(5000);
   List<String> secondBody = assertReceivedObjectMessageWithListBody(message);
   assertNotSame("Second call should return a different body", secondBody, body);
   commitTx();
}
 
Example 8
Source File: OpsEventListenerTest.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Exceptions test.
 * 
 * @throws OpampException
 */
public void exceptionsTest() throws OpampException
{
    OpsEventListener oel = new OpsEventListener();
    opsEventListener.setGson(new Gson());

    when(opsEventListener.getEventUtil().getGson()).thenReturn(new Gson());
    String eventJson = makeJson(UNHEALTHY, "oldstate");
    TextMessage message = mock(TextMessage.class);
    try
    {
        when(message.getStringProperty("type")).thenReturn("ci-change-state");
        when(message.getText()).thenReturn(eventJson);

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

    BadStateProcessor bsProcessorMock = mock(BadStateProcessor.class);
    CiChangeStateEvent changeEvent = new CiChangeStateEvent();
    OpsBaseEvent event = new OpsBaseEvent();
    event.setCiId(anyLong());

    doThrow(new OpsException(1, "expected")).when(bsProcessorMock).processUnhealthyState(changeEvent);
    oel.setBsProcessor(bsProcessorMock);
    oel.onMessage(message);
    // /further test coverage could be done with this mixture. save for
    // later
    // when(bsProcessorMock.processUnhealthyState(anyLong());
    // doThrow(new
    // OpampException("expected")).when(bsProcessorMock).processUnhealthyState(anyLong());
    // oel.setBsProcessor(bsProcessorMock);
    // bsProcessor.processUnhealthyState(event.getCiId());

}
 
Example 9
Source File: JMSChannelHandler.java    From diirt with MIT License 5 votes vote down vote up
@Override
protected void disconnect() {
    try {
        System.out.println("channel close");
        consumer.close();
        processConnection(null);
    } catch (JMSException e) {
        reportExceptionToAllReadersAndWriters(e);
        // TODO cleanup
        e.printStackTrace();
    }
}
 
Example 10
Source File: XASendExample.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(final Message message) {
   try {
      System.out.println("Message received: " + message);
      receiveHolder.add(((TextMessage) message).getText());
   } catch (JMSException e) {
      result.set(false);
      e.printStackTrace();
   }
}
 
Example 11
Source File: MessageGroup2Example.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
   try {
      TextMessage msg = (TextMessage) message;
      System.out.format("Message: [%s] received by %s%n", msg.getText(), name);
      messageReceiverMap.put(msg.getText(), name);
   } catch (JMSException e) {
      e.printStackTrace();
   }
}
 
Example 12
Source File: TopicListener.java    From chipster with MIT License 5 votes vote down vote up
private static boolean checkText(Message m, String s) {
    try {
        return m instanceof TextMessage && ((TextMessage)m).getText().equals(s);
    } catch (JMSException e) {
        e.printStackTrace(System.out);
        return false;
    }
}
 
Example 13
Source File: QueueBridgeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message msg) {
   try {
      TextMessage textMsg = (TextMessage) msg;
      String payload = "REPLY: " + textMsg.getText();
      Destination replyTo;
      replyTo = msg.getJMSReplyTo();
      textMsg.clearBody();
      textMsg.setText(payload);
      requestServerProducer.send(replyTo, textMsg);
   } catch (JMSException e) {
      e.printStackTrace();
   }
}
 
Example 14
Source File: ActiveMQBytesMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testReadUTF() {
   ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
   try {
      String str = "this is a test";
      msg.writeUTF(str);
      msg.reset();
      assertTrue(msg.readUTF().equals(str));
   } catch (JMSException jmsEx) {
      jmsEx.printStackTrace();
      assertTrue(false);
   }
}
 
Example 15
Source File: MainScheduler.java    From oneops with Apache License 2.0 5 votes vote down vote up
private void publishCIPendingEvents() {
    //logger.info("start reading" + eventType);
    isRunning = true;
    lastRun = System.currentTimeMillis();
    List<CMSEvent> events = ciEventReader.getEvents();
    while (events.size() > 0) {
        logger.info("Got " + events.size() + " ci events; Using CIEventPublisher");
        for (CMSEvent event : events) {
            String action = event.getHeaders().get("action");
            try {
                if (event.getPayload() != null || "delete".equals(action)) {
                    eventPublisher.publishCIEvents(event);
                } else {
                    logger.info("Event payload found null for " + event.getHeaders());
                }
                ciEventReader.removeEvent(event.getEventId());
            } catch (JMSException e) {
                e.printStackTrace();
                logger.error(e.getMessage(), e);
                //stopPublishing();
                return;
            }
        }
        events = ciEventReader.getEvents();
    }
    //System.out.println("Done;");
}
 
Example 16
Source File: MdbTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public MessageEndpoint createEndpoint(final XAResource xaResource) throws UnavailableException {
    try {
        return new JmsEndpoint(connectionFactory);
    } catch (final JMSException e) {
        e.printStackTrace();
        throw new UnavailableException(e);
    }
}
 
Example 17
Source File: QueueReceiver2.java    From code with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
	try {
		System.out.println("QueueReceiver2接收到消息:" + ((TextMessage) message).getText());
	} catch (JMSException e) {
		e.printStackTrace();
	}
}
 
Example 18
Source File: DeadLetterSender.java    From training with MIT License 5 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void sendDeadLetter(Message message, String errorString, Throwable throwable) {
	try {
		System.out.println("return message as dead letter");

		Connection conn = factory.createConnection();
		Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		session.createProducer(deadLetterQueue).send(message);
		conn.close();
	} catch (JMSException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		// other escallation
	}
}
 
Example 19
Source File: QueueReceiver2.java    From yunsleLive_room with MIT License 4 votes vote down vote up
@Override
public void onMessage(Message message) {
    try {
        if (message instanceof ActiveMQBytesMessage) {
            System.out.println("QueueReceiver2接收到消息:"+((ActiveMQBytesMessage)message).getContent().toString());
        }else{
            System.out.println("QueueReceiver2接收到消息:"+((TextMessage)message).getText());
        }
        message.acknowledge();////手动向broker确认接收成功,如果发生异常,就不反回ack
    } catch (JMSException e) {
        e.printStackTrace();
    }
}
 
Example 20
Source File: JMSChat.java    From maven-framework-project with MIT License 4 votes vote down vote up
public JMSChat() {

        try {

            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(this.url);
            this.connection = factory.createConnection();
            this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            this.topic = this.session.createTopic("sampletopic.flex.jms.chat");

            MessageConsumer consumer = this.session.createConsumer(this.topic);
            consumer.setMessageListener(this);

            this.producer = this.session.createProducer(this.topic);
            this.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            this.connection.start();

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

        // Build user interface
        JFrame frame = new JFrame("JMS Chat");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.taChat = new JTextArea();
        frame.getContentPane().add(this.taChat, BorderLayout.CENTER);

        Box north = new Box(BoxLayout.X_AXIS);
        north.add(new JLabel("User Name:"));
        this.tfUser = new JTextField();
        north.add(this.tfUser);
        frame.getContentPane().add(north, BorderLayout.NORTH);

        Box south = new Box(BoxLayout.X_AXIS);
        south.add(new JLabel("Message:"));
        this.tfMessage = new JTextField();
        south.add(this.tfMessage);
        JButton btSend = new JButton("Send");
        btSend.addActionListener(this);
        south.add(btSend);
        frame.getContentPane().add(south, BorderLayout.SOUTH);

        int width = 300;
        int height = 300;
        frame.setSize(width, height);
        frame.setVisible(true);

    }