sender.setCondition(new ErrorCondition(AmqpError.INVALID_FIELD, "No source terminus specified")); sender.open(); sender.close();
@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(); }
@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(); }
@Override public void onLinkAttach(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(); }
/** * Close the endpoint, detaching the link * * @param isDetachForced if link should be detached with error */ public void close(boolean isDetachForced) { if (this.sender.isOpen()) { if (isDetachForced) { ErrorCondition errorCondition = new ErrorCondition(LinkError.DETACH_FORCED, "Link detached due to a brute MQTT client disconnection"); this.sender.setCondition(errorCondition); } // detach link this.sender.close(); } } }
/** * Verifies that the endpoint closes a sender that does not contain a source address * that is not suitable as a reply-to-address. */ @Test public void testOnLinkAttachClosesSenderWithoutAppropriateReplyAddress() { final RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(true); endpoint.onLinkAttach(connection, sender, resource); verify(sender).setCondition(any()); verify(sender).close(); }
} else { LOG.debug("subject [{}] is not authorized to READ from [{}]", user.getName(), targetResource); sender.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "unauthorized")); sender.close(); sender.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such address")); sender.close();
@Override public void onLinkAttach(final ProtonSender sender, final ResourceIdentifier targetResource) { /* note: we "misuse" deviceId part of the resource as reply address here */ if (targetResource.getResourceId() == null) { logger.debug("link target provided in client's link ATTACH does not match pattern \"registration/<tenant>/<reply-address>\""); sender.setCondition(condition(AmqpError.INVALID_FIELD.toString(), "link target must have the following format registration/<tenant>/<reply-address>")); sender.close(); } else { logger.debug("establishing sender link with client [{}]", MessageHelper.getLinkName(sender)); final MessageConsumer<JsonObject> replyConsumer = vertx.eventBus().consumer(targetResource.toString(), message -> { // TODO check for correct session here...? logger.trace("forwarding reply to client: {}", message.body()); final Message amqpReply = RegistrationConstants.getAmqpReply(message); sender.send(amqpReply); }); sender.closeHandler(senderClosed -> { replyConsumer.unregister(); senderClosed.result().close(); final String linkName = MessageHelper.getLinkName(sender); logger.debug("receiver closed link [{}], removing associated event bus consumer [{}]", linkName, replyConsumer.address()); }); sender.setQoS(ProtonQoS.AT_LEAST_ONCE).open(); } }
} else { LOG.debug("subject [{}] is not authorized to READ from [{}]", user.getName(), targetResource); sender.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "unauthorized")); sender.close(); sender.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such address")); sender.close();
sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, String.format("reply-to address must have the following format %s/<tenant>/<reply-address>", getName()))); 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();
sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, String.format("reply-to address must have the following format %s/<tenant>/<reply-address>", getName()))); 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();
} else { final String message = String.format("subject [%s] is not authorized to READ from [%s]", user, targetResource); sender.setCondition(condition(UNAUTHORIZED_ACCESS.toString(), message)).close();
serverConnection.senderOpenHandler(serverSender -> { linkOpened.set(true); serverSender.setCondition(ProtonHelper.condition(AmqpError.PRECONDITION_FAILED, "Expected no links")); serverSender.close(); });
serverSender.setCondition(ProtonHelper.condition(AmqpError.INTERNAL_ERROR, "testing-error"));
serverSender.setCondition(ProtonHelper.condition(AmqpError.INTERNAL_ERROR, "testing-error"));