if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) { message.setContentType((String) prop.getValue());
if (Strings.isNullOrEmpty(message.getContentType()) && String.class.isInstance(prop.getValue())) { message.setContentType((String) prop.getValue());
/** * Set the payload of the message using a {@link Data} section. * <p> * If the payload is {@code null}, then neither the payload, nor content type will be set. * </p> * * @param message The message to update. * @param contentType An optional content type. * @param payload The optional message payload. * * @throws NullPointerException If the parameter {@code message} was {@code null}. */ public static void setPayload(final Message message, final String contentType, final byte[] payload) { Objects.requireNonNull(message); if (contentType != null) { message.setContentType(contentType); } if (payload != null) { message.setBody(new Data(new Binary(payload))); } }
/** * Set the payload of the message using a {@link Data} section. * <p> * If the payload is {@code null}, then neither the payload, nor content type will be set. * </p> * * @param message The message to update. * @param contentType An optional content type. * @param payload The optional message payload. * * @throws NullPointerException If the parameter {@code message} was {@code null}. */ public static void setPayload(final Message message, final String contentType, final byte[] payload) { Objects.requireNonNull(message); if (contentType != null) { message.setContentType(contentType); } if (payload != null) { message.setBody(new Data(new Binary(payload))); } }
@Override public <T> boolean sendJson(String topic, String json, Map<String, Object> properties, SendOptions sendOptions, CompletionListener<T> listener, T context) throws StoppedException { final String methodName = "sendJson"; logger.entry(this, methodName, topic, json, properties, sendOptions, listener, context); org.apache.qpid.proton.message.Message protonMsg = Proton.message(); protonMsg.setBody(new AmqpValue(json)); protonMsg.setContentType("application/json"); final boolean result = send(topic, protonMsg, properties, sendOptions == null ? defaultSendOptions : sendOptions, listener, context); logger.exit(this, methodName, result); return result; }
break; case AmqpConstants.AMQP_PROPERTY_CONTENT_TYPE: amqpMessage.setContentType((String) systemProperty.getValue()); break; case AmqpConstants.AMQP_PROPERTY_CONTENT_ENCODING:
/** * Verifies that the registered default content type is not set on a downstream message * that already contains a content type. */ @Test public void testAddPropertiesDoesNotAddDefaultContentType() { final Message message = ProtonHelper.message(); message.setContentType("application/existing"); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/existing")); }
msg.setContentType(contentType); if (timeUntilDisconnect != null) { MessageHelper.addTimeUntilDisconnect(msg, timeUntilDisconnect);
msg.setContentType(contentType); if (timeUntilDisconnect != null) { MessageHelper.addTimeUntilDisconnect(msg, timeUntilDisconnect);
message.setContentType(CONTENT_TYPE_OCTET_STREAM);
message.setContentType(CONTENT_TYPE_OCTET_STREAM);
/** * Verifies that a message containing a subject that does not represent * a Credentials API operation does not pass the filter. */ @Test public void testVerifyFailsForUnknownAction() { // GIVEN a message with an unsupported subject final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.unknown); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD)); msg.setContentType("application/json"); // WHEN receiving the message via a link with any tenant final boolean filterResult = CredentialsMessageFilter.verify(target, msg); // THEN message validation fails assertFalse(filterResult); }
/** * Verifies that a message containing a non Data section body * does not pass the filter. */ @Test public void testVerifyFailsForNonDataSectionBody() { // GIVEN a message with an unsupported subject final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD.encode())); msg.setContentType("application/json"); // WHEN receiving the message via a link with any tenant final boolean filterResult = CredentialsMessageFilter.verify(target, msg); // THEN message validation fails assertFalse(filterResult); }
/** * Verifies that a message that does not contain a message-id nor correlation-id * does not pass the filter. */ @Test public void testVerifyFailsForMissingCorrelationId() { // GIVEN a message with an unsupported subject final Message msg = ProtonHelper.message(); msg.setReplyTo("reply"); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD)); msg.setContentType("application/json"); // WHEN receiving the message via a link with any tenant final boolean filterResult = CredentialsMessageFilter.verify(target, msg); // THEN message validation fails assertFalse(filterResult); }
/** * Verifies that a valid message passes the filter. */ @Test public void testVerifySucceedsForValidGetAction() { // GIVEN a credentials message for user billie final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get); msg.setBody(new Data(new Binary(BILLIE_HASHED_PASSWORD.toBuffer().getBytes()))); msg.setContentType("application/json"); // WHEN receiving the message via a link with any tenant final boolean filterResult = CredentialsMessageFilter.verify(target, msg); // THEN message validation succeeds assertTrue(filterResult); }
amqpMessage.setContentType(brokeredMessage.getContentType()); amqpMessage.setCorrelationId(brokeredMessage.getCorrelationId()); amqpMessage.setSubject(brokeredMessage.getLabel());
message.getWrappedMessage().setContentType("text/plain"); message.getWrappedMessage().setBody(new Data(new Binary(messageText.getBytes(StandardCharsets.UTF_8))));
protonMsg.setGroupSequence(testGroupSeq); protonMsg.setReplyToGroupId(testReplyToGroupId); protonMsg.setContentType(testContentType); protonMsg.setContentEncoding(testContentEncoding); protonMsg.setCreationTime(testCreationTime);