org.apache.qpid.proton.amqp.Binary Java Examples
The following examples show how to use
org.apache.qpid.proton.amqp.Binary.
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: SaslImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testPlainHelperEncodesExpectedResponse() { TransportImpl transport = new TransportImpl(); SaslImpl sasl = new SaslImpl(transport, 512); // Use a username + password with a unicode char that encodes // differently under changing charsets String username = "username-with-unicode" + "\u1F570"; String password = "password-with-unicode" + "\u1F570"; byte[] usernameBytes = username.getBytes(StandardCharsets.UTF_8); byte[] passwordBytes = password.getBytes(StandardCharsets.UTF_8); byte[] expectedResponseBytes = new byte[usernameBytes.length + passwordBytes.length + 2]; System.arraycopy(usernameBytes, 0, expectedResponseBytes, 1, usernameBytes.length); System.arraycopy(passwordBytes, 0, expectedResponseBytes, 2 + usernameBytes.length, passwordBytes.length); sasl.plain(username, password); assertEquals("Unexpected response data", new Binary(expectedResponseBytes), sasl.getChallengeResponse()); }
Example #2
Source File: AmqpJmsTextMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testGetTextWithUnknownEncodedDataThrowsJMSException() throws Exception { String encodedString = "myEncodedString"; byte[] encodedBytes = encodedString.getBytes(Charset.forName("UTF-16")); Message message = Message.Factory.create(); message.setBody(new Data(new Binary(encodedBytes))); AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message); try { amqpTextMessageFacade.getText(); fail("expected exception not thrown"); } catch (JMSException ise) { // expected } }
Example #3
Source File: JMSContextIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testCreateContextWithTransactedSessionMode() throws Exception { Binary txnId = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, JMSContext.SESSION_TRANSACTED); assertEquals(JMSContext.SESSION_TRANSACTED, context.getSessionMode()); // Session should be created and a coordinator should be attached since this // should be a TX session, then a new TX is declared, once closed the TX should // be discharged as a roll back. testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); testPeer.expectDeclare(txnId); testPeer.expectDischarge(txnId, true); testPeer.expectEnd(); testPeer.expectClose(); context.createTopic("TopicName"); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #4
Source File: BinaryTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private void doTestEncodeBinaryTypeReservation(int size) throws IOException { byte[] data = new byte[size]; for (int i = 0; i < size; ++i) { data[i] = (byte) (i % 255); } Binary binary = new Binary(data); WritableBuffer writable = new WritableBuffer.ByteBufferWrapper(this.buffer); WritableBuffer spy = Mockito.spy(writable); encoder.setByteBuffer(spy); encoder.writeBinary(binary); // Check that the BinaryType tries to reserve space, actual encoding size not computed here. Mockito.verify(spy).ensureRemaining(Mockito.anyInt()); }
Example #5
Source File: DecoderImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Binary readBinary(final Binary defaultValue) { byte encodingCode = _buffer.get(); switch (encodingCode) { case EncodingCodes.VBIN8: return (Binary) _constructors[EncodingCodes.VBIN8 & 0xff].readValue(); case EncodingCodes.VBIN32: return (Binary) _constructors[EncodingCodes.VBIN32 & 0xff].readValue(); case EncodingCodes.NULL: return defaultValue; default: throw new ProtonException("Expected Binary type but found encoding: " + EncodingCodes.toString(encodingCode)); } }
Example #6
Source File: DataImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testEncodeStringBinary32() { byte[] payload = createStringPayloadBytes(1372); assertTrue("Length must be over 255 to ensure use of vbin32 encoding", payload.length > 255); int encodedSize = 1 + 4 + payload.length; // 1b type + 4b length + content ByteBuffer expectedEncoding = ByteBuffer.allocate(encodedSize); expectedEncoding.put((byte) 0xB0); expectedEncoding.putInt(payload.length); expectedEncoding.put(payload); Data data = new DataImpl(); data.putBinary(new Binary(payload)); Binary encoded = data.encode(); assertEquals("unexpected encoding", new Binary(expectedEncoding.array()), encoded); }
Example #7
Source File: MessageImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void setUserId(byte[] userId) { if(userId == null) { if(_properties != null) { _properties.setUserId(null); } } else { if(_properties == null) { _properties = new Properties(); } byte[] id = new byte[userId.length]; System.arraycopy(userId, 0, id,0, userId.length); _properties.setUserId(new Binary(id)); } }
Example #8
Source File: InterconnectReadData.java From maestro-java with Apache License 2.0 | 6 votes |
/** * Create request message * @param component string representation component name * @return created message * @throws JMSException if unable to create message */ private Message createMessage(String component) throws JMSException { logger.debug("Creating request message for: {}", component); Message message = session.createObjectMessage(); message.setBooleanProperty("JMS_AMQP_TYPED_ENCODING", true); message.setStringProperty("name", "self"); message.setStringProperty("operation", "QUERY"); message.setStringProperty("type", "org.amqp.management"); Binary requestFor = new Binary(("org.apache.qpid.dispatch." + component).getBytes()); ((JmsMessage) message).getFacade().setProperty("entityType", requestFor); HashMap<String,Object> map = new HashMap<>(); map.put("attributeNames", new ArrayList<>()); ((ObjectMessage) message).setObject(map); message.setJMSReplyTo(destination); return message; }
Example #9
Source File: DeliveryImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testAppendBinaryWithOffsetsToBuffer() throws Exception { DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null); byte[] data1 = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] data2 = new byte[] { 6, 7, 8, 9, 10, 11 }; Binary binary1 = new Binary(data1, 1, 2); Binary binary2 = new Binary(data2, 0, 4); delivery.append(binary1); delivery.append(binary2); assertEquals(binary1.getLength() + binary2.getLength(), delivery.getDataLength()); assertNotNull(delivery.getData()); assertEquals(binary1.getLength() + binary2.getLength(), delivery.getData().remaining()); }
Example #10
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void doCreateTextMessageFromDataWithContentTypeTestImpl(String contentType, Charset expectedCharset) throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType(contentType); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); if (StandardCharsets.UTF_8.equals(expectedCharset)) { assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); } else { assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); } }
Example #11
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private Binary createBinaryId() { byte length = 10; byte[] idBytes = new byte[length]; for (int i = 0; i < length; i++) { idBytes[i] = (byte) (length - i); } return new Binary(idBytes); }
Example #12
Source File: BinaryType.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public Binary readValue() { int size = ((int)getDecoder().readRawByte()) & 0xff; byte[] data = new byte[size]; getDecoder().readRaw(data, 0, size); return new Binary(data); }
Example #13
Source File: CoreAmqpConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static Binary getBinaryFromMessageBody(ServerJMSBytesMessage message) throws JMSException { byte[] data = new byte[(int) message.getBodyLength()]; message.readBytes(data); message.reset(); // Need to reset after readBytes or future readBytes return new Binary(data); }
Example #14
Source File: JMSMappingOutboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testConvertEmptyBytesMessageToAmqpMessageWithAmqpValueBody() throws Exception { ServerJMSBytesMessage outbound = createBytesMessage(); outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_VALUE_BINARY); outbound.encode(); AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null); assertNotNull(amqp.getBody()); assertTrue(amqp.getBody() instanceof AmqpValue); assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Binary); assertEquals(0, ((Binary) ((AmqpValue) amqp.getBody()).getValue()).getLength()); }
Example #15
Source File: BinaryElement.java From qpid-proton-j with Apache License 2.0 | 5 votes |
BinaryElement(Element parent, Element prev, Binary b) { super(parent, prev); byte[] data = new byte[b.getLength()]; System.arraycopy(b.getArray(),b.getArrayOffset(),data,0,b.getLength()); _value = new Binary(data); }
Example #16
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that a message with an empty data body section, and with the content type set to an * unknown value results in a BytesMessage when not otherwise annotated to indicate the type * of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateBytesMessageFromDataWithUnknownContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType("unknown-content-type"); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); }
Example #17
Source File: FastPathDataType.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public Data readValue() { ReadableBuffer buffer = getDecoder().getBuffer(); byte encodingCode = buffer.get(); int size = 0; switch (encodingCode) { case EncodingCodes.VBIN8: size = buffer.get() & 0xFF; break; case EncodingCodes.VBIN32: size = buffer.getInt(); break; case EncodingCodes.NULL: return new Data(null); default: throw new ProtonException("Expected Binary type but found encoding: " + encodingCode); } if (size > buffer.remaining()) { throw new IllegalArgumentException("Binary data size " + size + " is specified to be greater than the " + "amount of data available ("+ buffer.remaining()+")"); } byte[] data = new byte[size]; buffer.get(data, 0, size); return new Data(new Binary(data)); }
Example #18
Source File: BinaryType.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public Binary readValue() { final DecoderImpl decoder = getDecoder(); int size = decoder.readRawInt(); if (size > decoder.getByteBufferRemaining()) { throw new IllegalArgumentException("Binary data size "+size+" is specified to be greater than the amount of data available ("+ decoder.getByteBufferRemaining()+")"); } byte[] data = new byte[size]; decoder.readRaw(data, 0, size); return new Binary(data); }
Example #19
Source File: StringUtilsTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testEmptyBinaryNonEmptyArray() { byte[] bytes = new byte[] {(byte) 0, (byte) 0, (byte) 0}; Binary bin = new Binary(bytes, 0, 0); assertEquals("unexpected result", "\"\"", StringUtils.toQuotedString(bin, 10, true)); }
Example #20
Source File: JMSConsumerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testReceiveBodyBytesMessage() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer); testPeer.expectBegin(); Queue queue = context.createQueue("myQueue"); PropertiesDescribedType properties = new PropertiesDescribedType(); properties.setContentType(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE); MessageAnnotationsDescribedType msgAnnotations = null; msgAnnotations = new MessageAnnotationsDescribedType(); msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE.toString(), AmqpMessageSupport.JMS_BYTES_MESSAGE); final byte[] expectedContent = "expectedContent".getBytes(); DescribedType dataContent = new DataDescribedType(new Binary(expectedContent)); testPeer.expectReceiverAttach(); testPeer.expectLinkFlowRespondWithTransfer(null, msgAnnotations, properties, null, dataContent); testPeer.expectDispositionThatIsAcceptedAndSettled(); JMSConsumer messageConsumer = context.createConsumer(queue); byte[] received = messageConsumer.receiveBody(byte[].class, 3000); testPeer.waitForAllHandlersToComplete(3000); assertNotNull(received); assertTrue(Arrays.equals(expectedContent, received)); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(3000); } }
Example #21
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that a data body containing nothing, but with the content type set to * {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not * otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE); AMQPStandardMessage amqp = encodeAndCreateAMQPMessage(message); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(amqp.toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); }
Example #22
Source File: FrameWithNoPayloadMatchingHandler.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override protected final void verifyPayload(Binary payload) { _logger.debug("About to check that there is no payload"); if(payload != null && payload.getLength() > 0) { throw new AssertionError("Expected no payload but received payload of length: " + payload.getLength()); } }
Example #23
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that getting the messageId when using an underlying received message with a * Binary message id returns the expected value. */ @Test public void testGetMessageIdOnReceivedMessageWithBinary() { Binary testMessageId = createBinaryId(); String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + AmqpMessageIdHelper.convertBinaryToHexString(testMessageId.getArray()); messageIdOnReceivedMessageTestImpl(testMessageId, expected); }
Example #24
Source File: InteropTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testMessage() throws IOException { Message m = decodeMessage("message"); Binary b = (Binary) (((AmqpValue) m.getBody()).getValue()); String s = createDecoder(b.getArray()).readString(); assertEquals("hello", s); }
Example #25
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testTransactionRolledBackTimesOut() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setRequestTimeout(500); connection.start(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4}); testPeer.expectDeclare(txnId1); // Expect discharge but don't respond so that the request timeout kicks in and fails // the discharge. The pipelined declare should arrive as well and be discharged as the // client attempts to recover to a known good state. testPeer.expectDischargeButDoNotRespond(txnId1, true); // Session should throw from the rollback and then try and recover. testPeer.expectDeclare(txnId2); testPeer.expectDischarge(txnId2, true); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); try { session.rollback(); fail("Should have timed out waiting for declare."); } catch (JmsOperationTimedOutException jmsEx) { } catch (Throwable error) { fail("Should have caught an timed out exception:"); LOG.error("Caught -> ", error); } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #26
Source File: PropertiesTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testCopy() { Properties original = new Properties(); original.setAbsoluteExpiryTime(new Date(System.currentTimeMillis())); original.setContentEncoding(Symbol.valueOf("utf-8")); original.setContentType(Symbol.valueOf("test/plain")); original.setCorrelationId("1"); original.setCreationTime(new Date(System.currentTimeMillis())); original.setGroupId("group-1"); original.setGroupSequence(UnsignedInteger.MAX_VALUE); original.setMessageId("ID:1"); original.setReplyTo("queue"); original.setReplyToGroupId("3"); original.setSubject("subject"); original.setTo("to-queue"); original.setUserId(new Binary(new byte[1])); Properties copy = new Properties(original); assertEquals(original.getAbsoluteExpiryTime(), copy.getAbsoluteExpiryTime()); assertEquals(original.getContentEncoding(), copy.getContentEncoding()); assertEquals(original.getContentType(), copy.getContentType()); assertEquals(original.getCorrelationId(), copy.getCorrelationId()); assertEquals(original.getCreationTime(), copy.getCreationTime()); assertEquals(original.getGroupId(), copy.getGroupId()); assertEquals(original.getGroupSequence(), copy.getGroupSequence()); assertEquals(original.getMessageId(), copy.getMessageId()); assertEquals(original.getReplyTo(), copy.getReplyTo()); assertEquals(original.getReplyToGroupId(), copy.getReplyToGroupId()); assertEquals(original.getSubject(), copy.getSubject()); assertEquals(original.getTo(), copy.getTo()); assertEquals(original.getUserId(), copy.getUserId()); }
Example #27
Source File: SaslImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void handleMechanisms(SaslMechanisms saslMechanisms, Binary payload, Void context) { if(_role == null) { client(); } checkRole(Role.CLIENT); _mechanisms = saslMechanisms.getSaslServerMechanisms(); if(_saslListener != null) { _saslListener.onSaslMechanisms(this, _transport); } }
Example #28
Source File: AMQPMessageIdHelperTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that {@link AMQPMessageIdHelper#toIdObject(String)} returns a Binary * when given a string indicating an encoded AMQP binary id, using upper case * hex characters * * @throws Exception * if an error occurs during the test. */ @Test public void testToIdObjectWithEncodedBinaryUppercaseHexString() throws Exception { byte[] bytes = new byte[] {(byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF}; Binary binaryId = new Binary(bytes); String provided = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF"; doToIdObjectTestImpl(provided, binaryId); }
Example #29
Source File: AmqpJmsObjectMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that clearing the body on a message results in the underlying body * section being set with the null object body, ensuring getObject returns null. * * @throws Exception if an error occurs during the test. */ @Test public void testClearBodyWithExistingSerializedBodySection() throws Exception { Message protonMessage = Message.Factory.create(); protonMessage.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString()); protonMessage.setBody(new Data(new Binary(new byte[0]))); AmqpJmsObjectMessageFacade amqpObjectMessageFacade = createReceivedObjectMessageFacade(createMockAmqpConsumer(), protonMessage); assertNotNull("Expected existing body section to be found", amqpObjectMessageFacade.getBody()); amqpObjectMessageFacade.clearBody(); assertSame("Expected existing body section to be replaced", AmqpSerializedObjectDelegate.NULL_OBJECT_BODY, amqpObjectMessageFacade.getBody()); assertNull("Expected null object", amqpObjectMessageFacade.getObject()); }
Example #30
Source File: AMQPMessageIdHelperTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that {@link AMQPMessageIdHelper#toCorrelationIdString(Object)} * returns a string indicating an AMQP encoded binary when given a Binary * object. */ @Test public void testToCorrelationIdStringWithBinary() { byte[] bytes = new byte[] {(byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF}; Binary binary = new Binary(bytes); String expected = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF"; doToCorrelationIDTestImpl(binary, expected); }