/** * Writes the given frame to the socket. * @param frame the frame, must not be <code>null</code>. * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerConnection} */ public io.vertx.rxjava.ext.stomp.StompServerConnection write(Frame frame) { delegate.write(frame); return this; }
/** * Writes the given frame to the socket. * @param frame the frame, must not be <code>null</code>. * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerConnection} */ public io.vertx.rxjava.ext.stomp.StompServerConnection write(Frame frame) { delegate.write(frame); return this; }
/** * Writes the given buffer to the socket. This is a low level API that should be used carefully. * @param buffer the buffer * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerConnection} */ public io.vertx.rxjava.ext.stomp.StompServerConnection write(io.vertx.rxjava.core.buffer.Buffer buffer) { delegate.write(buffer.getDelegate()); return this; }
/** * Writes the given buffer to the socket. This is a low level API that should be used carefully. * @param buffer the buffer * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerConnection} */ public io.vertx.rxjava.ext.stomp.StompServerConnection write(io.vertx.rxjava.core.buffer.Buffer buffer) { delegate.write(buffer.getDelegate()); return this; }
/** * Dispatches the given frame. * * @param connection the connection * @param frame the frame ({@code SEND} frame). * @return the current instance of {@link Destination} */ @Override public synchronized Destination dispatch(StompServerConnection connection, Frame frame) { for (Subscription subscription : subscriptions) { String messageId = UUID.randomUUID().toString(); Frame message = transform(frame, subscription, messageId); subscription.connection.write(message); } return this; }
/** * Dispatches the given frame. * * @param connection the connection * @param frame the frame ({@code SEND} frame). * @return the current instance of {@link Destination} */ @Override public synchronized Destination dispatch(StompServerConnection connection, Frame frame) { if (subscriptions.isEmpty()) { lastUsedSubscriptions = -1; return this; } Subscription subscription = getNextSubscription(); String messageId = UUID.randomUUID().toString(); Frame message = transform(frame, subscription, messageId); subscription.connection.write(message); return this; }
public static io.vertx.ext.stomp.StompServerConnection write(io.vertx.ext.stomp.StompServerConnection j_receiver, java.util.Map<String, Object> frame) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.write(frame != null ? new io.vertx.ext.stomp.Frame(io.vertx.core.impl.ConversionHelper.toJsonObject(frame)) : null)); return j_receiver; } }
static void handleReceipt(Frame frame, StompServerConnection connection) { String receipt = frame.getReceipt(); if (receipt != null) { connection.write(createReceiptFrame(receipt, Headers.create())); } }
public void sendMessage(String subscriptionId, String message) { Map<String, String> messageHeaders = new HashMap<>(); messageHeaders.put(Frame.SUBSCRIPTION, subscriptionId); messageHeaders.put(Frame.MESSAGE_ID, Integer.toString(messageIdCounter++)); messageHeaders.put(Frame.ACK, Integer.toString(messageIdCounter++)); JsonObject body = new JsonObject(); body.put("id", message); String encode = body.encode(); StompServerConnection connection = subscriptions.get(subscriptionId).connection; connection.write(new Frame(Frame.Command.MESSAGE, messageHeaders, Buffer.buffer(encode))); }
private void authenticate(Frame frame, StompServerConnection connection, Handler<AsyncResult<Void>> remainingActions) { if (connection.server().options().isSecured()) { String login = frame.getHeader(Frame.LOGIN); String passcode = frame.getHeader(Frame.PASSCODE); connection.handler().onAuthenticationRequest(connection, login, passcode, ar -> { if (ar.result()) { remainingActions.handle(Future.succeededFuture()); } else { connection.write(Frames.createErrorFrame( "Authentication failed", Headers.create( Frame.VERSION, getSupportedVersionsHeaderLine(connection), Frame.CONTENT_TYPE, "text/plain"), "The connection frame does not contain valid credentials.") ); connection.close(); } }); } else { remainingActions.handle(Future.succeededFuture()); } }
private void handleConnect(ServerFrame serverFrame) { recordFrame(serverFrame); serverFrame.connection().write(new Frame(Frame.Command.CONNECTED, Collections.emptyMap(), null)); }
@Override public void handle(ServerFrame serverFrame) { Frame frame = serverFrame.frame(); StompServerConnection connection = serverFrame.connection(); String txId = frame.getHeader(Frame.TRANSACTION); if (txId == null) { Frame error = Frames.createErrorFrame("Missing transaction id", Headers.create(), "BEGIN frames " + "must contain the 'transaction' header."); connection.write(error).close(); return; } if (!Transactions.instance().registerTransaction(connection, txId)) { Frame error = Frames.createErrorFrame("Already existing transaction", Headers.create(Frame.TRANSACTION, txId), "A transaction using the same id is still active."); connection.write(error).close(); return; } Frames.handleReceipt(frame, connection); } }
private void handleSubscribe(ServerFrame serverFrame) { // if ("MySubId2".equals(serverFrame.frame().getId())) { Map<String, String> receiptHeaders = new HashMap<>(); receiptHeaders.put(Frame.RECEIPT_ID, serverFrame.frame().getReceipt()); serverFrame.connection().write(new Frame(Frame.Command.RECEIPT, receiptHeaders, null)); System.out.println("serverFrame.frame().getId()" + serverFrame.frame().getId()); subscriptions.put(serverFrame.frame().getId(), new ServerSubscription(serverFrame.connection())); recordFrame(serverFrame); // } }
@Override public void handle(ServerFrame sf) { String txId = sf.frame().getHeader(Frame.TRANSACTION); if (txId == null) { Frame error = Frames.createErrorFrame("Missing transaction id", Headers.create(), "ABORT frames " + "must contain the 'transaction' header."); sf.connection().write(error).close(); return; } if (! Transactions.instance().unregisterTransaction(sf.connection(), txId)) { Frame error = Frames.createErrorFrame("Unknown transaction", Headers.create(Frame.TRANSACTION, txId), "The transaction id is unknown."); sf.connection().write(error).close(); return; } Frames.handleReceipt(sf.frame(), sf.connection()); } }
@Override public void handle(ServerFrame serverFrame) { Frame frame = serverFrame.frame(); StompServerConnection connection = serverFrame.connection(); String txId = frame.getHeader(Frame.TRANSACTION); if (txId == null) { Frame error = Frames.createErrorFrame("Missing transaction id", Headers.create(), "COMMIT frames " + "must contain the " + "'transaction' header."); connection.write(error).close(); return; } Transaction transaction = Transactions.instance().getTransaction(connection, txId); if (transaction == null) { Frame error = Frames.createErrorFrame("Unknown transaction", Headers.create(Frame.TRANSACTION, txId), "The transaction id is unknown."); connection.write(error).close(); return; } replay(connection, transaction.getFrames()); transaction.clear(); Transactions.instance().unregisterTransaction(connection, txId); Frames.handleReceipt(frame, connection); }
String id = frame.getId(); if (id == null) { connection.write(Frames.createErrorFrame( "Id header missing", Headers.create(frame.getHeaders()), "Invalid ACK frame - the " + Headers.create(Frame.ID, id, Frame.TRANSACTION, txId), "Message delivery failed - unknown transaction id in ACK message"); connection.write(errorFrame); connection.close(); return; "may have been reached"); Transactions.instance().unregisterTransactionsFromConnection(connection); connection.write(errorFrame); connection.close(); return;
parser .errorHandler((exception) -> { connection.write( Frames.createInvalidFrameErrorFrame(exception)); connection.close();