Java Code Examples for io.vertx.proton.ProtonSender#close()

The following examples show how to use io.vertx.proton.ProtonSender#close() . 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: AmqpServiceBase.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles a request from a client to establish a link for receiving messages from this server.
 *
 * @param con the connection to the client.
 * @param sender the sender created for the link.
 */
protected void handleSenderOpen(final ProtonConnection con, final ProtonSender sender) {
    final Source remoteSource = sender.getRemoteSource();
    log.debug("client [container: {}] wants to open a link [address: {}] for receiving messages",
            con.getRemoteContainer(), remoteSource);
    try {
        final ResourceIdentifier targetResource = getResourceIdentifier(remoteSource.getAddress());
        final AmqpEndpoint endpoint = getEndpoint(targetResource);
        if (endpoint == null) {
            handleUnknownEndpoint(con, sender, targetResource);
        } else {
            final HonoUser user = Constants.getClientPrincipal(con);
            getAuthorizationService().isAuthorized(user, targetResource, Activity.READ).onComplete(authAttempt -> {
                if (authAttempt.succeeded() && authAttempt.result()) {
                    Constants.copyProperties(con, sender);
                    sender.setSource(sender.getRemoteSource());
                    sender.setTarget(sender.getRemoteTarget());
                    endpoint.onLinkAttach(con, sender, targetResource);
                } else {
                    log.debug("subject [{}] is not authorized to READ from [{}]", user.getName(), targetResource);
                    sender.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "unauthorized"));
                    sender.close();
                }
            });
        }
    } catch (final IllegalArgumentException e) {
        log.debug("client has provided invalid resource identifier as target address", e);
        sender.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such address"));
        sender.close();
    }
}
 
Example 2
Source File: RequestResponseEndpoint.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Handles a client's request to establish a link for receiving responses to service invocations.
 * <p>
 * This method registers a consumer on the vert.x event bus for the given reply-to address. Response messages
 * received over the event bus are transformed into AMQP messages using the {@link #getAmqpReply(EventBusMessage)}
 * method and sent to the client over the established link.
 *
 * @param con The AMQP connection that the link is part of.
 * @param sender The link to establish.
 * @param replyToAddress The reply-to address to create a consumer on the event bus for.
 */
@Override
public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender,
        final ResourceIdentifier replyToAddress) {

    if (!isValidReplyToAddress(replyToAddress)) {
        logger.debug("client [{}] provided invalid reply-to address", sender.getName());
        sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD,
                String.format("reply-to address must have the following format %s/<tenant>/<reply-address>",
                        getName())));
        sender.close();
        return;
    }

    final String replyTo = replyToAddress.toString();

    if (this.replyToSenderMap.containsKey(replyTo)) {
        logger.debug("client [{}] wanted to subscribe to already subscribed reply-to address [{}]",
                sender.getName(), replyTo);
        sender.setCondition(ProtonHelper.condition(AmqpError.ILLEGAL_STATE,
                String.format("reply-to address [%s] is already subscribed", replyTo)));
        sender.close();
        return;
    }

    logger.debug("establishing response sender link with client [{}]", sender.getName());
    sender.setQoS(ProtonQoS.AT_LEAST_ONCE);
    sender.setSource(sender.getRemoteSource());
    sender.setTarget(sender.getRemoteTarget());
    registerSenderForReplyTo(replyTo, sender);


    HonoProtonHelper.setCloseHandler(sender, remoteClose -> {
        logger.debug("client [{}] closed sender link", sender.getName());
        unregisterSenderForReplyTo(replyTo);
        sender.close();
    });
    HonoProtonHelper.setDetachHandler(sender, remoteDetach -> {
        logger.debug("client [{}] detached sender link", sender.getName());
        unregisterSenderForReplyTo(replyTo);
        sender.close();
    });

    sender.open();
}
 
Example 3
Source File: AbstractRequestResponseEndpoint.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Handles a client's request to establish a link for receiving responses to service invocations.
 * <p>
 * This method opens a sender for sending request replies back to the client.
 *
 * @param con The AMQP connection that the link is part of.
 * @param sender The link to establish.
 * @param replyToAddress The reply-to address to create a consumer on the event bus for.
 */
@Override
public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender,
        final ResourceIdentifier replyToAddress) {

    if (!isValidReplyToAddress(replyToAddress)) {
        logger.debug("client [{}] provided invalid reply-to address", sender.getName());
        sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD,
                String.format("reply-to address must have the following format %s/<tenant>/<reply-address>",
                        getName())));
        sender.close();
        return;
    }

    final String replyTo = replyToAddress.toString();

    if (this.replyToSenderMap.containsKey(replyTo)) {
        logger.debug("client [{}] wanted to subscribe to already subscribed reply-to address [{}]",
                sender.getName(), replyTo);
        sender.setCondition(ProtonHelper.condition(AmqpError.ILLEGAL_STATE,
                String.format("reply-to address [%s] is already subscribed", replyTo)));
        sender.close();
        return;
    }

    logger.debug("establishing response sender link with client [{}]", sender.getName());
    sender.setQoS(ProtonQoS.AT_LEAST_ONCE);
    sender.setSource(sender.getRemoteSource());
    sender.setTarget(sender.getRemoteTarget());
    registerSenderForReplyTo(replyTo, sender);


    HonoProtonHelper.setCloseHandler(sender, remoteClose -> {
        logger.debug("client [{}] closed sender link", sender.getName());
        unregisterSenderForReplyTo(replyTo);
        sender.close();
    });
    HonoProtonHelper.setDetachHandler(sender, remoteDetach -> {
        logger.debug("client [{}] detached sender link", sender.getName());
        unregisterSenderForReplyTo(replyTo);
        sender.close();
    });

    sender.open();
}
 
Example 4
Source File: AbstractAmqpEndpoint.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier targetResource) {
    logger.info("Endpoint [{}] does not support data retrieval, closing link.", getName());
    sender.setCondition(ProtonHelper.condition(AmqpError.NOT_IMPLEMENTED, "resource cannot be read from"));
    sender.close();
}