use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class ProtonClientTest method remoteCloseDefaultSessionTestImpl.
private void remoteCloseDefaultSessionTestImpl(TestContext context, boolean sessionError) throws InterruptedException, ExecutionException {
server.close();
Async async = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer(serverConnection -> {
Promise<ProtonSession> sessionPromise = Promise.<ProtonSession>promise();
// Expect a session to open, when the sender is created by the client
serverConnection.sessionOpenHandler(serverSession -> {
LOG.trace("Server session open");
serverSession.open();
sessionPromise.complete(serverSession);
});
// Expect a receiver link, then close the session after opening it.
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver open");
serverReceiver.open();
context.assertTrue(sessionPromise.future().succeeded(), "Session future not [yet] succeeded");
LOG.trace("Server session close");
ProtonSession s = sessionPromise.future().result();
if (sessionError) {
ErrorCondition error = new ErrorCondition();
error.setCondition(AmqpError.INTERNAL_ERROR);
error.setDescription("error description");
s.setCondition(error);
}
s.close();
});
serverConnection.openHandler(result -> {
LOG.trace("Server connection open");
serverConnection.open();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
context.assertTrue(x.succeeded(), "Connection open failed");
LOG.trace("Client connection opened");
// Create a sender to provoke creation (and subsequent
// closure of by the server) the connections default session
connection.createSender(null).open();
});
connection.closeHandler(x -> {
LOG.trace("Connection close handler called (as espected): " + x.cause());
async.complete();
});
connection.open();
});
async.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class MessagePublisherVerificationTckTest method createServer.
private TestServer createServer() throws Exception {
return new TestServer(vertx, (connection) -> {
connection.openHandler(res -> {
LOG.trace("Client connected: " + connection.getRemoteContainer());
connection.open();
}).closeHandler(c -> {
LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
connection.close();
connection.disconnect();
}).disconnectHandler(c -> {
LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
connection.disconnect();
}).sessionOpenHandler(session -> session.open());
connection.senderOpenHandler(sender -> {
if (!server.getDetachLink()) {
LOG.trace("Sending to client from: " + sender.getRemoteSource().getAddress());
// This is rather naive, for example use only, proper
sender.setSource(sender.getRemoteSource());
// servers should ensure that they advertise their own
// Source settings that actually reflect what is in place.
// The request may have also been for a dynamic address.
AtomicLong count = new AtomicLong();
AtomicLong outstanding = new AtomicLong();
sender.sendQueueDrainHandler(s -> {
while (!s.sendQueueFull()) {
LOG.trace("Sending message to client");
Message m = message("Hello World from Server!" + count.incrementAndGet());
outstanding.incrementAndGet();
s.send(m, delivery -> {
LOG.trace("The message was received by the client.");
});
}
});
sender.closeHandler(s -> {
s.result().close();
});
}
sender.open();
if (server.getDetachLink()) {
sender.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Publisher Requested"), ""));
sender.close();
}
});
});
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class ProtonReceiverImpl method handleMaxMessageSizeExceeded.
private void handleMaxMessageSizeExceeded(final UnsignedLong maxMessageSize, final Receiver receiver) {
try {
LOG.debug("delivery received exceeding max-message-size of " + maxMessageSize + " bytes");
if (maxMessageSizeExceededHandler != null) {
maxMessageSizeExceededHandler.handle(this);
}
} finally {
// Detach link if handler has not sent a detach frame already
if (!receiver.detached() && isOpen()) {
LOG.debug("detaching link with error condition " + LinkError.MESSAGE_SIZE_EXCEEDED);
setCondition(new ErrorCondition(LinkError.MESSAGE_SIZE_EXCEEDED, "exceeded max-message-size of " + maxMessageSize + " bytes "));
detach();
}
}
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class DeliveryPublisherVerificationTckTest method createServer.
private TestServer createServer() throws Exception {
return new TestServer(vertx, (connection) -> {
connection.openHandler(res -> {
LOG.trace("Client connected: " + connection.getRemoteContainer());
connection.open();
}).closeHandler(c -> {
LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
connection.close();
connection.disconnect();
}).disconnectHandler(c -> {
LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
connection.disconnect();
}).sessionOpenHandler(session -> session.open());
connection.senderOpenHandler(sender -> {
if (!server.getDetachLink()) {
LOG.trace("Sending to client from: " + sender.getRemoteSource().getAddress());
// This is rather naive, for example use only, proper
sender.setSource(sender.getRemoteSource());
// servers should ensure that they advertise their own
// Source settings that actually reflect what is in place.
// The request may have also been for a dynamic address.
AtomicLong count = new AtomicLong();
AtomicLong outstanding = new AtomicLong();
sender.sendQueueDrainHandler(s -> {
while (!s.sendQueueFull()) {
LOG.trace("Sending message to client");
Message m = message("Hello World from Server!" + count.incrementAndGet());
outstanding.incrementAndGet();
s.send(m, delivery -> {
LOG.trace("The message was received by the client.");
});
}
});
sender.closeHandler(s -> {
s.result().close();
});
}
sender.open();
if (server.getDetachLink()) {
sender.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Publisher Requested"), ""));
sender.close();
}
});
});
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class TrackerSubscriberWhiteboxVerificationTckTest method createServer.
private TestServer createServer() throws Exception {
return new TestServer(vertx, (connection) -> {
connection.openHandler(res -> {
LOG.trace("Client connected: " + connection.getRemoteContainer());
connection.open();
}).closeHandler(c -> {
LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
connection.close();
connection.disconnect();
}).disconnectHandler(c -> {
LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
connection.disconnect();
}).sessionOpenHandler(session -> session.open());
connection.receiverOpenHandler(receiver -> {
if (!server.getDetachLink()) {
LOG.trace("Receiving from client to: " + receiver.getRemoteTarget().getAddress());
// This is rather naive, for example use only, proper
receiver.setTarget(receiver.getRemoteTarget());
// servers should ensure that they advertise their own
// Target settings that actually reflect what is in place.
// The request may have also been for a dynamic address.
receiver.handler((delivery, msg) -> {
String address = msg.getAddress();
if (address == null) {
address = receiver.getRemoteTarget().getAddress();
}
Section body = msg.getBody();
String content = "unknown";
if (body instanceof AmqpValue) {
content = (String) ((AmqpValue) body).getValue();
}
LOG.trace("message to:" + address + ", body: " + content);
});
receiver.closeHandler(s -> {
s.result().close();
});
}
receiver.open();
if (server.getDetachLink()) {
receiver.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Subscriber Requested"), ""));
receiver.close();
}
});
});
}
Aggregations