Java Code Examples for org.apache.qpid.proton.message.Message#getReplyTo()

The following examples show how to use org.apache.qpid.proton.message.Message#getReplyTo() . 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: TenantMessageFilter.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Checks whether a given tenant message contains all required properties.
 *
 * @param linkTarget The resource path to check the message's properties against for consistency.
 * @param msg The AMQP 1.0 message to perform the checks on.
 * @return {@code true} if the message passes all checks.
 */
public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {

    final Object correlationId = MessageHelper.getCorrelationId(msg);

    if (correlationId == null) {
        LOG.trace("message has neither a message-id nor correlation-id");
        return false;
    } else if (msg.getSubject() == null) {
        LOG.trace("message [correlation ID: {}] does not contain a subject", correlationId);
        return false;
    } else if (msg.getReplyTo() == null) {
        LOG.trace("message [correlation ID: {}] contains no reply-to address", correlationId);
        return false;
    } else {
        return true;
    }
}
 
Example 2
Source File: RegistrationMessageFilter.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Checks whether a given registration message contains all required properties.
 *
 * @param linkTarget The resource path to check the message's properties against for consistency.
 * @param msg The AMQP 1.0 message to perform the checks on.
 * @return {@code true} if the message passes all checks.
 */
 public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {

     final Object correlationId = MessageHelper.getCorrelationId(msg);

     if (!hasValidDeviceId(linkTarget, msg)) {
         return false;
     } else if (correlationId == null) {
         LOG.trace("message has neither a message-id nor correlation-id");
         return false;
     } else if (msg.getSubject() == null) {
         LOG.trace("message [correlation ID: {}] does not contain a subject", correlationId);
         return false;
     } else if (msg.getReplyTo() == null) {
         LOG.trace("message [correlation ID: {}] contains no reply-to address", correlationId);
         return false;
     } else {
         return true;
     }
}
 
Example 3
Source File: CredentialsMessageFilter.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Checks whether a given credentials message contains all required properties.
 *
 * @param linkTarget The resource path to check the message's properties against for consistency.
 * @param msg The AMQP 1.0 message to perform the checks on.
 * @return {@code true} if the message passes all checks.
 */
public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {

    if (msg.getMessageId() == null && msg.getCorrelationId() == null) {
        LOG.trace("message has neither a message-id nor correlation-id");
        return false;
    } else if (!CredentialsConstants.CredentialsAction.isValid(msg.getSubject())) {
        LOG.trace("message [{}] does not contain valid subject property", msg.getMessageId());
        return false;
    } else if (msg.getReplyTo() == null) {
        LOG.trace("message [{}] has no reply-to address set", msg.getMessageId());
        return false;
    } else if (!MessageHelper.hasDataBody(msg)) {
        LOG.trace("message [{}] contains no Data section payload", msg.getMessageId());
        return false;
    } else {
        return true;
    }
}
 
Example 4
Source File: DeviceConnectionMessageFilter.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Checks whether a given device connection message contains all required properties.
 *
 * @param linkTarget The resource path to check the message's properties against for consistency.
 * @param msg The AMQP 1.0 message to perform the checks on.
 * @return {@code true} if the message passes all checks.
 */
public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {

    final Object correlationId = MessageHelper.getCorrelationId(msg);

    if (!hasValidDeviceId(linkTarget, msg)) {
        return false;
    } else if (correlationId == null) {
        LOG.trace("message has neither a message-id nor correlation-id");
        return false;
    } else if (msg.getSubject() == null) {
        LOG.trace("message [correlation ID: {}] does not contain a subject", correlationId);
        return false;
    } else if (msg.getReplyTo() == null) {
        LOG.trace("message [correlation ID: {}] contains no reply-to address", correlationId);
        return false;
    } else {
        return true;
    }
}
 
Example 5
Source File: ProtonRequestClient.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Message request(Message message, long timeout, TimeUnit timeUnit) {
    Map<String, Object> properties = new HashMap<>();
    if (message.getApplicationProperties() != null) {
        properties.putAll(message.getApplicationProperties().getValue());
    }
    message.setApplicationProperties(new ApplicationProperties(properties));

    if (message.getReplyTo() == null) {
        message.setReplyTo(replyTo);
    }
    context.runOnContext(h -> sender.send(message));
    try {
        return replies.poll(timeout, timeUnit);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: AmqpExampleDevice.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
private void handleCommand(final Message commandMessage) {

        final String subject = commandMessage.getSubject();
        final String commandPayload = MessageHelper.getPayloadAsString(commandMessage);

        if (commandMessage.getReplyTo() == null || commandMessage.getCorrelationId() == null) {
            // one-way command
            System.out.println(String.format("Received one-way command [name: %s]: %s", subject, commandPayload));
        } else {
            // request-response command
            System.out.println(String.format("Received command [name: %s]: %s", subject, commandPayload));
            sendCommandResponse(commandMessage);
        }
    }
 
Example 7
Source File: AbstractRequestResponseEndpoint.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Handles a request message received from a client.
 * <p>
 * The message gets rejected if
 * <ul>
 * <li>the message does not pass {@linkplain #passesFormalVerification(ResourceIdentifier, Message) formal
 * verification} or</li>
 * <li>the client is not {@linkplain #isAuthorized(HonoUser, ResourceIdentifier, Message) authorized to execute the
 * operation} indicated by the message's <em>subject</em> or</li>
 * <li>its payload cannot be parsed</li>
 * </ul>
 *
 * @param con The connection with the client.
 * @param receiver The link over which the message has been received.
 * @param targetAddress The address the message is sent to.
 * @param delivery The message's delivery status.
 * @param requestMessage The request message.
 */
protected final void handleRequestMessage(
        final ProtonConnection con,
        final ProtonReceiver receiver,
        final ResourceIdentifier targetAddress,
        final ProtonDelivery delivery,
        final Message requestMessage) {

    final HonoUser clientPrincipal = Constants.getClientPrincipal(con);
    final String replyTo = requestMessage.getReplyTo();
    final SpanContext spanContext = TracingHelper.extractSpanContext(tracer, requestMessage);
    final Span currentSpan = TracingHelper.buildServerChildSpan(tracer, spanContext, "process request message", getName())
            .withTag(Tags.HTTP_METHOD.getKey(), requestMessage.getSubject())
            .withTag(Tags.MESSAGE_BUS_DESTINATION.getKey(), targetAddress.toString())
            .start();

    if (!passesFormalVerification(targetAddress, requestMessage)) {
        MessageHelper.rejected(delivery, new ErrorCondition(Constants.AMQP_BAD_REQUEST, "malformed request message"));
        flowCreditToRequestor(receiver, replyTo);
        TracingHelper.logError(currentSpan, "malformed request message");
        currentSpan.finish();
        return;
    }

    ProtonHelper.accepted(delivery, true);
    currentSpan.log("request message accepted");

    getSenderForConnection(con, replyTo)
            .compose(sender -> isAuthorized(clientPrincipal, targetAddress, requestMessage)
                    .map(authorized -> {

                        logger.debug("client [{}] is {}authorized to {}:{}", clientPrincipal.getName(),
                                authorized ? "" : "not ", targetAddress, requestMessage.getSubject());

                        if (authorized) {
                            return authorized;
                        } else {
                            throw new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, "not authorized to invoke operation");
                        }
                    })
                    .compose(authorized -> handleRequestMessage(requestMessage, targetAddress, currentSpan.context()))
                    .compose(amqpMessage -> filterResponse(clientPrincipal, requestMessage, amqpMessage))
                    .otherwise(t -> {

                        logger.debug("error processing request [resource: {}, op: {}]: {}", targetAddress,
                                requestMessage.getSubject(), t.getMessage());
                        currentSpan.log("error processing request");
                        TracingHelper.logError(currentSpan, t);

                        final ServiceInvocationException ex = getServiceInvocationException(t);
                        Tags.HTTP_STATUS.set(currentSpan, ex.getErrorCode());
                        return RequestResponseApiConstants.getErrorMessage(ex.getErrorCode(), ex.getMessage(), requestMessage);
                    })
                    .map(amqpMessage -> {
                        Tags.HTTP_STATUS.set(currentSpan, MessageHelper.getStatus(amqpMessage));
                        if (sender.isOpen()) {
                            final ProtonDelivery responseDelivery = sender.send(amqpMessage);
                            //TODO handle send exception
                            logger.debug("sent response message to client  [correlation-id: {}, content-type: {}]",
                                    amqpMessage.getCorrelationId(), amqpMessage.getContentType());
                            currentSpan.log("sent response message to client");
                            return responseDelivery;
                        } else {
                            TracingHelper.logError(currentSpan, "cannot send response, reply-to link is closed");
                            return null;
                        }
                    }))
            .onComplete(s -> {
                // allow client to send another request
                flowCreditToRequestor(receiver, replyTo);
                currentSpan.finish();
            });
}