Search in sources :

Example 6 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example49.

public void example49(Vertx vertx) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderMgr' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.someService");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted);
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.RECEIVE) {
            if (be.getRawMessage().getString("body").equals("armadillos")) {
                // Reject it
                be.complete(false);
                return;
            }
        }
        be.complete(true);
    }));
}
Also used : LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) GithubAuth(io.vertx.ext.auth.oauth2.providers.GithubAuth) RoutingContextInternal(io.vertx.ext.web.impl.RoutingContextInternal) io.vertx.ext.auth.webauthn(io.vertx.ext.auth.webauthn) Function(java.util.function.Function) EventBus(io.vertx.core.eventbus.EventBus) RoleBasedAuthorization(io.vertx.ext.auth.authorization.RoleBasedAuthorization) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) BridgeEventType(io.vertx.ext.bridge.BridgeEventType) JsonObject(io.vertx.core.json.JsonObject) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) AuthorizationProvider(io.vertx.ext.auth.authorization.AuthorizationProvider) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) Future(io.vertx.core.Future) io.vertx.core.http(io.vertx.core.http) KeyStoreOptions(io.vertx.ext.auth.KeyStoreOptions) JsonArray(io.vertx.core.json.JsonArray) JWTOptions(io.vertx.ext.auth.JWTOptions) io.vertx.ext.web(io.vertx.ext.web) io.vertx.ext.web.handler(io.vertx.ext.web.handler) List(java.util.List) User(io.vertx.ext.auth.User) Buffer(io.vertx.core.buffer.Buffer) SessionStore(io.vertx.ext.web.sstore.SessionStore) TotpAuth(io.vertx.ext.auth.otp.totp.TotpAuth) DataObject(io.vertx.codegen.annotations.DataObject) PermissionBasedAuthorization(io.vertx.ext.auth.authorization.PermissionBasedAuthorization) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 7 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example48_1.

public void example48_1(Vertx vertx) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderService' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted);
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.SEND) {
            // Add some headers
            JsonObject headers = new JsonObject().put("header1", "val").put("header2", "val2");
            JsonObject rawMessage = be.getRawMessage();
            rawMessage.put("headers", headers);
            be.setRawMessage(rawMessage);
        }
        be.complete(true);
    }));
}
Also used : LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) GithubAuth(io.vertx.ext.auth.oauth2.providers.GithubAuth) RoutingContextInternal(io.vertx.ext.web.impl.RoutingContextInternal) io.vertx.ext.auth.webauthn(io.vertx.ext.auth.webauthn) Function(java.util.function.Function) EventBus(io.vertx.core.eventbus.EventBus) RoleBasedAuthorization(io.vertx.ext.auth.authorization.RoleBasedAuthorization) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) BridgeEventType(io.vertx.ext.bridge.BridgeEventType) JsonObject(io.vertx.core.json.JsonObject) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) AuthorizationProvider(io.vertx.ext.auth.authorization.AuthorizationProvider) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) Future(io.vertx.core.Future) io.vertx.core.http(io.vertx.core.http) KeyStoreOptions(io.vertx.ext.auth.KeyStoreOptions) JsonArray(io.vertx.core.json.JsonArray) JWTOptions(io.vertx.ext.auth.JWTOptions) io.vertx.ext.web(io.vertx.ext.web) io.vertx.ext.web.handler(io.vertx.ext.web.handler) List(java.util.List) User(io.vertx.ext.auth.User) Buffer(io.vertx.core.buffer.Buffer) SessionStore(io.vertx.ext.web.sstore.SessionStore) TotpAuth(io.vertx.ext.auth.otp.totp.TotpAuth) DataObject(io.vertx.codegen.annotations.DataObject) PermissionBasedAuthorization(io.vertx.ext.auth.authorization.PermissionBasedAuthorization) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) JsonObject(io.vertx.core.json.JsonObject) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Aggregations

SockJSBridgeOptions (io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions)7 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)6 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)6 JsonObject (io.vertx.core.json.JsonObject)4 DataObject (io.vertx.codegen.annotations.DataObject)3 Future (io.vertx.core.Future)3 Handler (io.vertx.core.Handler)3 Vertx (io.vertx.core.Vertx)3 VertxOptions (io.vertx.core.VertxOptions)3 Buffer (io.vertx.core.buffer.Buffer)3 EventBus (io.vertx.core.eventbus.EventBus)3 io.vertx.core.http (io.vertx.core.http)3 JsonArray (io.vertx.core.json.JsonArray)3 JWTOptions (io.vertx.ext.auth.JWTOptions)3 KeyStoreOptions (io.vertx.ext.auth.KeyStoreOptions)3 User (io.vertx.ext.auth.User)3 AuthenticationProvider (io.vertx.ext.auth.authentication.AuthenticationProvider)3 AuthorizationProvider (io.vertx.ext.auth.authorization.AuthorizationProvider)3 PermissionBasedAuthorization (io.vertx.ext.auth.authorization.PermissionBasedAuthorization)3 RoleBasedAuthorization (io.vertx.ext.auth.authorization.RoleBasedAuthorization)3