Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#getBodySize()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#getBodySize() .
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: ActiveMQ.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) { int size = msg.getBodySize(); if (size <= 0) return null; byte[] body = new byte[size]; msg.getBodyBuffer().readBytes(body); String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE); if (contentType == null) { throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity"); } MediaType ct = MediaType.valueOf(contentType); MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct); if (reader == null) { throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType); } Providers current = ResteasyProviderFactory.getContextData(Providers.class); ResteasyProviderFactory.pushContext(Providers.class, factory); try { return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body)); } catch (IOException e) { throw new RuntimeException(e); } finally { ResteasyProviderFactory.popContextData(Providers.class); if (current != null) ResteasyProviderFactory.pushContext(Providers.class, current); } }
Example 2
Source File: ScaleDownDirectTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void checkBody(ClientMessage message, int bufferSize) { assertEquals(bufferSize, message.getBodySize()); byte[] body = new byte[message.getBodySize()]; message.getBodyBuffer().readBytes(body); for (int bpos = 0; bpos < bufferSize; bpos++) { if (getSamplebyte(bpos) != body[bpos]) { fail("body comparison failure at " + message); } } }
Example 3
Source File: AmqpCoreTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onMessage(ClientMessage message) { instanceLog.debug("received: " + message.getBodySize()); if (message.getBodySize() == 0) { instanceLog.debug("xxx found zero len message!"); zeroLen = true; } addMessage(message); }
Example 4
Source File: LocalMessageQueue.java From elasticactors with Apache License 2.0 | 5 votes |
@Override public void onMessage(ClientMessage message) { byte[] bodyBuffer = new byte[message.getBodySize()]; message.getBodyBuffer().readBytes(bodyBuffer); // execute on separate (thread bound) executor queueExecutor.execute(new ActiveMQMessageHandler(queueName,bodyBuffer,internalMessageDeserializer,messageHandler,new ActiveMQAck(message),logger)); }
Example 5
Source File: XmlImportExportTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testBytesMessage() throws Exception { StringBuilder data = new StringBuilder(); for (int i = 0; i < 2610; i++) { data.append("X"); } ClientSession session = basicSetUp(); session.createQueue(new QueueConfiguration(QUEUE_NAME)); ClientProducer producer = session.createProducer(QUEUE_NAME); ClientMessage msg = session.createMessage(Message.BYTES_TYPE, true); msg.getBodyBuffer().writeBytes(data.toString().getBytes()); producer.send(msg); session.close(); locator.close(); server.stop(); ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream(); XmlDataExporter xmlDataExporter = new XmlDataExporter(); xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory()); System.out.print(new String(xmlOutputStream.toByteArray())); clearDataRecreateServerDirs(); server.start(); checkForLongs(); locator = createInVMNonHALocator(); factory = createSessionFactory(locator); session = factory.createSession(false, true, true); ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray()); XmlDataImporter xmlDataImporter = new XmlDataImporter(); xmlDataImporter.validate(xmlInputStream); xmlInputStream.reset(); xmlDataImporter.process(xmlInputStream, session); ClientConsumer consumer = session.createConsumer(QUEUE_NAME); session.start(); msg = consumer.receive(CONSUMER_TIMEOUT); assertEquals(Message.BYTES_TYPE, msg.getType()); byte[] result = new byte[msg.getBodySize()]; msg.getBodyBuffer().readBytes(result); assertEquals(data.toString().getBytes().length, result.length); }
Example 6
Source File: InVMNonPersistentMessageBufferTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSendSameMessageMultipleTimes() throws Exception { ClientMessage message = session.createMessage(false); final String body = RandomUtil.randomString(); message.getBodyBuffer().writeString(body); int bodySize = message.getBodySize(); for (int i = 0; i < 10; i++) { ClientMessage received = sendAndReceive(message); Assert.assertNotNull(received); Assert.assertEquals(bodySize, received.getBodySize()); Assert.assertEquals(body, received.getBodyBuffer().readString()); Assert.assertFalse(received.getBodyBuffer().readable()); } }
Example 7
Source File: InVMNonPersistentMessageBufferTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testSendMessageResetSendAgainDifferentBody() throws Exception { ClientMessage message = session.createMessage(false); String body = RandomUtil.randomString(); for (int i = 0; i < 10; i++) { // Make the body a bit longer each time body += "XX"; message.getBodyBuffer().writeString(body); int bodySize = message.getBodySize(); ClientMessage received = sendAndReceive(message); Assert.assertNotNull(received); Assert.assertEquals(bodySize, received.getBodySize()); Assert.assertEquals(body, received.getBodyBuffer().readString()); Assert.assertFalse(received.getBodyBuffer().readable()); message.getBodyBuffer().clear(); Assert.assertEquals(DataConstants.SIZE_INT, message.getBodyBuffer().writerIndex()); Assert.assertEquals(DataConstants.SIZE_INT, message.getBodyBuffer().readerIndex()); } }