import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import javax.servlet.http.HttpServlet; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; import javax.ws.rs.core.MediaType; public class MessageServlet extends HttpServlet { @PUT @Consumes(MediaType.TEXT_PLAIN) public void putString(String myString) throws JMSException { MessageProducer producer = (MessageProducer) getServletContext() .getAttribute(MyContextListener.ACTIVE_MQ_PRODUCER); Session session = (Session) getServletContext().getAttribute( MyContextListener.ACTIVE_MQ_SESSION); TextMessage txtmessage = session.createTextMessage(); if (txtmessage != null && producer != null) { txtmessage.clearBody(); txtmessage.setText(myString); producer.send(txtmessage); } } }
/** * Test that the <code>TextMessage.clearBody()</code> effectively clear the body of the message */ public void testClearBody_1() { try { TextMessage message = senderSession.createTextMessage(); message.setText("bar"); message.clearBody(); assertEquals("3 .11.1 the clearBody method of Message resets the value of the message body " + "to the 'empty' initial message value as set by the message type's create " + "method provided by Session.\n", null, message.getText()); } catch (JMSException e) { fail(e); } }
/** * Test that the <code>TextMessage.clearBody()</code> method does nto clear the * message properties. */ public void testClearBody_2() { try { TextMessage message = senderSession.createTextMessage(); message.setStringProperty("prop", "foo"); message.clearBody(); assertEquals("3.11.1 Clearing a message's body does not clear its property entries.\n", "foo", message .getStringProperty("prop")); } catch (JMSException e) { fail(e); } }
m2.clearBody(); ProxyAssertSupport.assertNull(m2.getText()); m2.setText("Now it is read-write");
/** * Test that the <code>TextMessage.clearBody()</code> effectively clear the body of the message */ @Test public void testClearBody_1() { try { TextMessage message = senderSession.createTextMessage(); message.setText("bar"); message.clearBody(); Assert.assertEquals("sec. 3 .11.1 the clearBody method of Message resets the value of the message body " + "to the 'empty' initial message value as set by the message type's create " + "method provided by Session.\n", null, message.getText()); } catch (JMSException e) { fail(e); } }
/** * Test that the <code>TextMessage.clearBody()</code> method does not clear the * message properties. */ @Test public void testClearBody_2() { try { TextMessage message = senderSession.createTextMessage(); message.setStringProperty("prop", "foo"); message.clearBody(); Assert.assertEquals("sec. 3.11.1 Clearing a message's body does not clear its property entries.\n", "foo", message.getStringProperty("prop")); } catch (JMSException e) { fail(e); } }