本文整理汇总了Java中org.apache.qpid.proton.amqp.messaging.Rejected类的典型用法代码示例。如果您正苦于以下问题:Java Rejected类的具体用法?Java Rejected怎么用?Java Rejected使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rejected类属于org.apache.qpid.proton.amqp.messaging包,在下文中一共展示了Rejected类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testProcessMessageRejectsRegistrationAssertionForWrongTenant
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that a message containing a registration assertion for a tenant
* other than the one from the message's target address is rejected.
*/
@Test
public void testProcessMessageRejectsRegistrationAssertionForWrongTenant() {
final String invalidToken = getToken(SECRET, "wrong-tenant", "4711");
UpstreamReceiver client = mock(UpstreamReceiver.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
when(tokenValidator.isValid(invalidToken, "tenant", "4711")).thenReturn(Boolean.FALSE);
MessageForwardingEndpoint<ServiceConfigProperties> endpoint = getEndpoint();
endpoint.setRegistrationAssertionValidator(tokenValidator);
Message msg = ProtonHelper.message();
MessageHelper.addRegistrationAssertion(msg, invalidToken);
MessageHelper.addAnnotation(msg, MessageHelper.APP_PROPERTY_RESOURCE, "telemetry/tenant/4711");
endpoint.forwardMessage(client, delivery, msg);
verify(delivery).disposition(any(Rejected.class), anyBoolean());
verify(client, never()).close(any(ErrorCondition.class));
}
示例2: testHandleMessageRejectsMalformedMessage
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that the endpoint rejects malformed request messages.
*/
@Test
public void testHandleMessageRejectsMalformedMessage() {
Message msg = ProtonHelper.message();
ProtonConnection con = mock(ProtonConnection.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(false);
// WHEN a malformed message is received
endpoint.handleMessage(con, receiver, resource, delivery, msg);
// THEN the link is closed and the message is rejected
ArgumentCaptor<DeliveryState> deliveryState = ArgumentCaptor.forClass(DeliveryState.class);
verify(delivery).disposition(deliveryState.capture(), booleanThat(is(Boolean.TRUE)));
assertThat(deliveryState.getValue(), instanceOf(Rejected.class));
verify(receiver, never()).close();
}
示例3: testHandleMessageRejectsUnauthorizedRequests
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that the endpoint rejects request messages for operations the client
* is not authorized to invoke.
*/
@Test
public void testHandleMessageRejectsUnauthorizedRequests() {
Message msg = ProtonHelper.message();
msg.setSubject("unauthorized");
ProtonConnection con = mock(ProtonConnection.class);
ProtonDelivery delivery = mock(ProtonDelivery.class);
AuthorizationService authService = mock(AuthorizationService.class);
when(authService.isAuthorized(any(HonoUser.class), any(ResourceIdentifier.class), anyString())).thenReturn(Future.succeededFuture(Boolean.FALSE));
Future<Void> processingTracker = Future.future();
RequestResponseEndpoint<ServiceConfigProperties> endpoint = getEndpoint(true, processingTracker);
endpoint.setAuthorizationService(authService);
// WHEN a request for an operation is received that the client is not authorized to invoke
endpoint.handleMessage(con, receiver, resource, delivery, msg);
// THEN the the message is rejected
ArgumentCaptor<DeliveryState> deliveryState = ArgumentCaptor.forClass(DeliveryState.class);
verify(delivery).disposition(deliveryState.capture(), booleanThat(is(Boolean.TRUE)));
assertThat(deliveryState.getValue(), instanceOf(Rejected.class));
verify(receiver, never()).close();
verify(authService).isAuthorized(Constants.PRINCIPAL_ANONYMOUS, resource, "unauthorized");
assertFalse(processingTracker.isComplete());
}
示例4: openReceiverWithHandler
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
private void openReceiverWithHandler(ProtonReceiver receiver, RequestHandler requestHandler) {
receiver.handler((delivery, message) -> {
vertx.executeBlocking(future -> {
try {
Optional<HandlerContext> context = Optional.ofNullable(replyHandlers.get(message.getReplyTo()));
Message response = requestHandler.handleMessage(message);
context.ifPresent(ctx -> vertx.runOnContext(v -> ctx.sender.send(response)));
} catch (Exception e) {
log.warn("Error handling addressing message", e);
future.fail(e);
}
}, result -> {
if (result.succeeded()) {
delivery.disposition(new Accepted(), true);
} else {
delivery.disposition(new Rejected(), true);
}
});
});
receiver.open();
}
示例5: createEndpoint
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
@Override
protected Sender createEndpoint(JmsSessionInfo resourceInfo) {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(TxnCapability.LOCAL_TXN);
Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
Source source = new Source();
source.setOutcomes(outcomes);
String coordinatorName = "qpid-jms:coordinator:" + resourceInfo.getId().toString();
Sender sender = getParent().getSession().getEndpoint().sender(coordinatorName);
sender.setSource(source);
sender.setTarget(coordinator);
sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
return sender;
}
示例6: testMessageHandlerRejectsMalformedMessage
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that the endpoint rejects messages that do not pass formal verification.
*/
@SuppressWarnings("unchecked")
@Test
public void testMessageHandlerRejectsMalformedMessage() {
// GIVEN an endpoint with an attached client
final ProtonConnection connection = mock(ProtonConnection.class);
when(connection.getRemoteContainer()).thenReturn("test-client");
final ProtonReceiver receiver = mock(ProtonReceiver.class);
final ResourceIdentifier targetAddress = ResourceIdentifier.fromString("telemetry/tenant");
ArgumentCaptor<ProtonMessageHandler> messageHandler = ArgumentCaptor.forClass(ProtonMessageHandler.class);
when(receiver.handler(messageHandler.capture())).thenReturn(receiver);
when(receiver.closeHandler(any(Handler.class))).thenReturn(receiver);
when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_MOST_ONCE);
final DownstreamAdapter adapter = mock(DownstreamAdapter.class);
doAnswer(invocation -> {
invocation.getArgumentAt(1, Handler.class).handle(Future.succeededFuture(null));
return null;
}).when(adapter).onClientAttach(any(UpstreamReceiver.class), any(Handler.class));
MessageForwardingEndpoint<ServiceConfigProperties> endpoint = getEndpoint(false);
endpoint.setDownstreamAdapter(adapter);
endpoint.onLinkAttach(connection, receiver, targetAddress);
// WHEN a client sends a malformed message
Message message = ProtonHelper.message("malformed");
ProtonDelivery upstreamDelivery = mock(ProtonDelivery.class);
messageHandler.getValue().handle(upstreamDelivery, message);
// THEN a the endpoint rejects the message
ArgumentCaptor<Rejected> deliveryState = ArgumentCaptor.forClass(Rejected.class);
verify(upstreamDelivery).disposition(deliveryState.capture(), eq(Boolean.TRUE));
assertThat(deliveryState.getValue().getError().getCondition(), is(AmqpError.DECODE_ERROR));
// but does not close the link
verify(receiver, never()).close();
}
示例7: sendMessage
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
@Override
protected Future<ProtonDelivery> sendMessage(final Message message) {
Objects.requireNonNull(message);
final String messageId = String.format("%s-%d", getClass().getSimpleName(), MESSAGE_COUNTER.getAndIncrement());
message.setMessageId(messageId);
final ProtonDelivery result = sender.send(message, deliveryUpdated -> {
if (deliveryUpdated.remotelySettled()) {
if (Accepted.class.isInstance(deliveryUpdated.getRemoteState())) {
LOG.trace("message [message ID: {}] accepted by peer", messageId);
} else if (Rejected.class.isInstance(deliveryUpdated.getRemoteState())) {
Rejected remoteState = (Rejected) deliveryUpdated.getRemoteState();
if (remoteState.getError() == null) {
LOG.debug("message [message ID: {}] rejected by peer", messageId);
} else {
LOG.debug("message [message ID: {}] rejected by peer: {}, {}", messageId,
remoteState.getError().getCondition(), remoteState.getError().getDescription());
}
} else {
LOG.debug("message [message ID: {}] not accepted by peer: {}", messageId, deliveryUpdated.getRemoteState());
}
} else {
LOG.warn("peer did not settle telemetry message [message ID: {}, remote state: {}]", messageId, deliveryUpdated.getRemoteState());
}
});
LOG.trace("sent telemetry message [ID: {}], remaining credit: {}, queued messages: {}", messageId, sender.getCredit(), sender.getQueued());
return Future.succeededFuture(result);
}
示例8: sendMessage
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
@Override
protected Future<ProtonDelivery> sendMessage(final Message message) {
Objects.requireNonNull(message);
final Future<ProtonDelivery> result = Future.future();
final String messageId = String.format("%s-%d", getClass().getSimpleName(), MESSAGE_COUNTER.getAndIncrement());
message.setMessageId(messageId);
sender.send(message, deliveryUpdated -> {
if (deliveryUpdated.remotelySettled()) {
if (Accepted.class.isInstance(deliveryUpdated.getRemoteState())) {
LOG.trace("event [message ID: {}] accepted by peer", messageId);
result.complete(deliveryUpdated);
} else if (Rejected.class.isInstance(deliveryUpdated.getRemoteState())) {
Rejected rejected = (Rejected) deliveryUpdated.getRemoteState();
if (rejected.getError() == null) {
LOG.debug("event [message ID: {}] rejected by peer", messageId);
result.fail(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else {
LOG.debug("event [message ID: {}] rejected by peer: {}, {}", messageId,
rejected.getError().getCondition(), rejected.getError().getDescription());
result.fail(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, rejected.getError().getDescription()));
}
} else {
LOG.debug("event [message ID: {}] not accepted by peer: {}", messageId, deliveryUpdated.getRemoteState());
result.fail(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
}
} else {
LOG.warn("peer did not settle event, failing delivery [new remote state: {}]", deliveryUpdated.getRemoteState());
result.fail(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR));
}
});
LOG.trace("sent event [ID: {}], remaining credit: {}, queued messages: {}", messageId, sender.getCredit(), sender.getQueued());
return result;
}
示例9: testSendMessageFailsForRejectedOutcome
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that the sender fails if the peer does not accept a message.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings({ "unchecked" })
@Test
public void testSendMessageFailsForRejectedOutcome(final TestContext ctx) {
// GIVEN a sender that has credit
when(sender.sendQueueFull()).thenReturn(Boolean.FALSE);
MessageSender messageSender = new EventSenderImpl(config, sender, "tenant", "telemetry/tenant", context);
final AtomicReference<Handler<ProtonDelivery>> handlerRef = new AtomicReference<>();
doAnswer(invocation -> {
handlerRef.set(invocation.getArgumentAt(1, Handler.class));
return mock(ProtonDelivery.class);
}).when(sender).send(any(Message.class), any(Handler.class));
// WHEN trying to send a message
final Future<ProtonDelivery> result = messageSender.send("device", "some payload", "application/text", "token");
// THEN the message has been sent
// and the result is not completed yet
verify(sender).send(any(Message.class), eq(handlerRef.get()));
assertFalse(result.isComplete());
// and the result fails once the peer rejects the message
ProtonDelivery rejected = mock(ProtonDelivery.class);
when(rejected.remotelySettled()).thenReturn(Boolean.TRUE);
when(rejected.getRemoteState()).thenReturn(new Rejected());
handlerRef.get().handle(rejected);
assertFalse(result.succeeded());
}
示例10: testSendMessageDoesNotWaitForAcceptedOutcome
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Verifies that the sender does not wait for the peer to settle and
* accept a message before succeeding.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings({ "unchecked" })
@Test
public void testSendMessageDoesNotWaitForAcceptedOutcome(final TestContext ctx) {
// GIVEN a sender that has credit
when(sender.sendQueueFull()).thenReturn(Boolean.FALSE);
MessageSender messageSender = new TelemetrySenderImpl(config, sender, "tenant", "telemetry/tenant", context);
final AtomicReference<Handler<ProtonDelivery>> handlerRef = new AtomicReference<>();
doAnswer(invocation -> {
handlerRef.set(invocation.getArgumentAt(1, Handler.class));
return mock(ProtonDelivery.class);
}).when(sender).send(any(Message.class), any(Handler.class));
// WHEN trying to send a message
final Future<ProtonDelivery> result = messageSender.send("device", "some payload", "application/text", "token");
// which gets rejected by the peer
ProtonDelivery rejected = mock(ProtonDelivery.class);
when(rejected.remotelySettled()).thenReturn(Boolean.TRUE);
when(rejected.getRemoteState()).thenReturn(new Rejected());
handlerRef.get().handle(rejected);
// THEN the resulting future is succeeded nevertheless
assertTrue(result.succeeded());
// and the message has been sent
verify(sender).send(any(Message.class), eq(handlerRef.get()));
}
示例11: sendSubscribe
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Send the AMQP_SUBSCRIBE message to the Subscription Service
*
* @param amqpSubscribeMessage AMQP_SUBSCRIBE message
* @param handler callback called on message delivered
*/
public void sendSubscribe(AmqpSubscribeMessage amqpSubscribeMessage, Handler<AsyncResult<ProtonDelivery>> handler) {
// send AMQP_SUBSCRIBE message
this.sender.send(amqpSubscribeMessage.toAmqp(), delivery -> {
if ((delivery.getRemoteState() == Accepted.getInstance()) ||
(delivery.getRemoteState() instanceof Rejected)) {
LOG.info("AMQP subscribe delivery {}", delivery.getRemoteState());
handler.handle(Future.succeededFuture(delivery));
} else {
handler.handle(Future.failedFuture(String.format("AMQP subscribe delivery %s", delivery.getRemoteState())));
}
});
}
示例12: handleMessage
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
private synchronized void handleMessage(Receiver receiver, String address, ProtonDelivery delivery, org.apache.qpid.proton.message.Message message) {
List<Sender> senderList = senderMap.get(address);
if (senderList == null || senderList.isEmpty()) {
delivery.disposition(new Rejected(), true);
} else {
Sender sender = senderList.get(senderList.size() - 1);
sender.send(message, delivery, receiver);
}
}
示例13: rejectedDelivery
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
/**
* Send a "rejected" delivery to the AMQP remote sender
*
* @param linkName AMQP link name
* @param delivery AMQP delivery
* @param cause exception related to the rejection cause
*/
private void rejectedDelivery(String linkName, ProtonDelivery delivery, Throwable cause) {
Rejected rejected = new Rejected();
rejected.setError(new ErrorCondition(Symbol.valueOf(AmqpBridge.AMQP_ERROR_SEND_TO_KAFKA),
cause.getMessage()));
delivery.disposition(rejected, true);
log.debug("Delivery sent [rejected] on link {}", linkName);
}
示例14: run
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
public void run(Vertx vertx) {
ProtonClient client = ProtonClient.create(vertx);
client.connect(AmqpBridgeSender.BRIDGE_HOST, AmqpBridgeSender.BRIDGE_PORT, ar -> {
if (ar.succeeded()) {
this.connection = ar.result();
this.connection.open();
log.info("Connected as {}", this.connection.getContainer());
this.sender = this.connection.createSender(ExampleOne.TOPIC);
this.sender.open();
String topic = ExampleOne.TOPIC;
Message message = ProtonHelper.message(topic, "Simple message from " + this.connection.getContainer());
this.sender.send(ProtonHelper.tag("my_tag"), message, delivery -> {
log.info("Message delivered {}", delivery.getRemoteState());
if (delivery.getRemoteState() instanceof Rejected) {
Rejected rejected = (Rejected)delivery.getRemoteState();
log.info("... but rejected {} {}", rejected.getError().getCondition(), rejected.getError().getDescription());
}
});
} else {
log.info("Error on connection ... {}", ar.cause());
}
});
try {
System.in.read();
this.sender.close();
this.connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: newInstance
import org.apache.qpid.proton.amqp.messaging.Rejected; //导入依赖的package包/类
public Rejected newInstance(Object described)
{
List l = (List) described;
Rejected o = new Rejected();
switch(1 - l.size())
{
case 0:
o.setError( (ErrorCondition) l.get( 0 ) );
}
return o;
}