@Test public void testHookSocketClosed() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SOCKET_CLOSED) { assertNotNull(be.socket()); assertNull(be.getRawMessage()); be.complete(true); testComplete(); } else { be.complete(true); } }); client.websocket(websocketURI, WebSocketBase::close); await(); }
@Test public void testHookPublishMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "publish").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
/** * Set the result. Any handler will be called, if there is one, and the future will be marked as completed. * @param result the result */ public void complete(Boolean result) { delegate.complete(result); }
/** * Get the raw JSON message for the event. This will be null for SOCKET_CREATED or SOCKET_CLOSED events as there is * no message involved. * @param message the raw message * @return this reference, so it can be used fluently */ public io.vertx.rxjava.ext.web.handler.sockjs.BridgeEvent setRawMessage(JsonObject message) { delegate.setRawMessage(message); return this; }
public static <U>io.vertx.core.Future<java.lang.Object> map(io.vertx.ext.web.handler.sockjs.BridgeEvent j_receiver, java.util.function.Function<java.lang.Boolean, java.lang.Object> mapper) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.map(mapper != null ? new java.util.function.Function<java.lang.Boolean, java.lang.Object>() { public java.lang.Object apply(java.lang.Boolean t) { java.lang.Boolean o = t; java.lang.Object p = mapper.apply(o); return io.vertx.core.impl.ConversionHelper.toObject(p); } } : null)); } public static io.vertx.ext.web.handler.sockjs.BridgeEvent setRawMessage(io.vertx.ext.web.handler.sockjs.BridgeEvent j_receiver, java.util.Map<String, Object> message) {
/** * Get the SockJSSocket instance corresponding to the event * @return the SockJSSocket instance */ public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket socket() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(delegate.socket()); cached_1 = ret; return ret; }
/** * @return an handler completing this future */ public Handler<AsyncResult<Boolean>> completer() { if (cached_0 != null) { return cached_0; } Handler<AsyncResult<Boolean>> ret = delegate.completer(); cached_0 = ret; return ret; }
@Test public void testHookSendRejected() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { be.complete(false); testComplete(); } else { be.complete(true); } }); testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foobar"), "rejected"); await(); }
@Test public void testHookUnregisterMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.UNREGISTER) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "unregister").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
/** * Set the result. Any handler will be called, if there is one, and the future will be marked as completed. * @param result the result */ public void complete(Boolean result) { delegate.complete(result); }
/** * Get the raw JSON message for the event. This will be null for SOCKET_CREATED or SOCKET_CLOSED events as there is * no message involved. * @param message the raw message * @return this reference, so it can be used fluently */ public io.vertx.rxjava.ext.web.handler.sockjs.BridgeEvent setRawMessage(JsonObject message) { delegate.setRawMessage(message); return this; }
/** * Apply a <code>mapper</code> function on this future.<p> * * When this future succeeds, the <code>mapper</code> will be called with the completed value and this mapper * returns a value. This value will complete the future returned by this method call.<p> * * If the <code>mapper</code> throws an exception, the returned future will be failed with this exception.<p> * * When this future fails, the failure will be propagated to the returned future and the <code>mapper</code> * will not be called. * @param mapper the mapper function * @return the mapped future */ public <U> io.vertx.rxjava.core.Future<U> map(Function<Boolean, U> mapper) { io.vertx.rxjava.core.Future<U> ret = io.vertx.rxjava.core.Future.newInstance(delegate.map(mapper), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Get the SockJSSocket instance corresponding to the event * @return the SockJSSocket instance */ public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket socket() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket ret = io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket.newInstance(delegate.socket()); cached_1 = ret; return ret; }
/** * @return an handler completing this future */ public Handler<AsyncResult<Boolean>> completer() { if (cached_0 != null) { return cached_0; } Handler<AsyncResult<Boolean>> ret = delegate.completer(); cached_0 = ret; return ret; }
@Test public void testHookPublishHeaders() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { assertNotNull(be.socket()); JsonObject raw = be.getRawMessage(); assertEquals(addr, raw.getString("address")); assertEquals("foobar", raw.getString("body")); raw.put("headers", new JsonObject().put("hdr1", "val1").put("hdr2", "val2")); be.setRawMessage(raw); be.complete(true); testComplete(); } else { be.complete(true); } }); testPublish(addr, "foobar", true); await(); }
@Test public void testHookPubRejected() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { be.complete(false); testComplete(); } else { be.complete(true); } }); testError(new JsonObject().put("type", "publish").put("address", addr).put("body", "foobar"), "rejected"); await(); }
@Test public void testHookRegisterMissingAddress() throws Exception { sockJSHandler.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.REGISTER) { be.getRawMessage().remove("address"); testComplete(); } be.complete(true); }); testError(new JsonObject().put("type", "register").put("address", addr).put("body", "foobar"), "missing_address"); await(); }
private SockJSHandler configureSockJsHandler(VertxContext vertxContext, BridgeOptions bridgeOptions, JsonObject config) { SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx()); sockJSHandler.bridge(bridgeOptions, event -> event.complete(true)); JsonArray jsonArray=config.getJsonArray(ALLOWED_ORIGINS); sockJSHandler.socketHandler(event -> jsonArray.forEach(o -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, (String)o))); return sockJSHandler; }
public static io.vertx.ext.web.handler.sockjs.BridgeEvent setRawMessage(io.vertx.ext.web.handler.sockjs.BridgeEvent j_receiver, java.util.Map<String, Object> message) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.setRawMessage(message != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(message) : null)); return j_receiver; } }