当前位置: 首页>>代码示例>>Java>>正文


Java SockJSHandler类代码示例

本文整理汇总了Java中io.vertx.ext.web.handler.sockjs.SockJSHandler的典型用法代码示例。如果您正苦于以下问题:Java SockJSHandler类的具体用法?Java SockJSHandler怎么用?Java SockJSHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SockJSHandler类属于io.vertx.ext.web.handler.sockjs包,在下文中一共展示了SockJSHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eventBusHandler

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
 	SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
    BridgeOptions boptions = new BridgeOptions()
            .addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.UPDATE_ORDERBOOK+":[A-Z]+-[A-Z]+"))
            .addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.UPDATE_INDICATORS+":[A-Z]+-[A-Z]+"))
            .addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.ORDERBOOK_READY+":[A-Z]+-[A-Z]+"))
    		.addInboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.GET_ORDERBOOK+":[A-Z]+-[A-Z]+"))
    		.addInboundPermitted(new PermittedOptions().setAddressRegex("getMovingAverage:[A-Z]+-[A-Z]+"))
    		.addInboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.REDEPLOYBITTREXVERTICLES));
    return SockJSHandler.create(vertx, options).bridge(boptions, event -> {
         if (event.type() == BridgeEventType.SOCKET_CREATED) {
            System.out.println("A socket was created!");
         } else if (event.type() == BridgeEventType.SOCKET_CLOSED){
        	 System.out.println("A socket was closed!");
         } else if (event.type() == BridgeEventType.UNREGISTER || event.type() == BridgeEventType.REGISTER){
        	 System.out.println(event.getRawMessage().encode());
         }
        event.complete(true);
    });
}
 
开发者ID:AlxGDev,项目名称:BittrexGatherer,代码行数:21,代码来源:BittrexVerticle.java

示例2: addRoutes

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
@Override
public SFDCRouterExtension addRoutes(final Router router) {
	// Socket handler
	final SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
	final SockJSHandler sockJSHandler = SockJSHandler.create(this.vertx, options);

	final BridgeOptions bo = new BridgeOptions()
			.addOutboundPermitted(new PermittedOptions().setAddress(this.getWebSocketName()));

	sockJSHandler.bridge(bo, event -> {
		this.logger.info("A websocket event occurred: " + event.type() + "; " + event.getRawMessage());
		event.complete(true);
	});

	final String someURL = this.getConsumerConfig().getUrl();
	this.logger.info("Router listening on " + someURL + " for " + this.getWebSocketName());
	router.route(someURL).handler(sockJSHandler);
	return this;
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:20,代码来源:WebSocketConsumer.java

示例3: configure

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
@Override
public SockJSHandler configure(VertxContext vertxContext, ServerConfiguration<JsonObject, JsonObject[]> config) {

    JsonObject sockJsConfig=config.getJsonObject(CONFIG_KEY, makeDefaultConfig());

    BridgeOptions bridgeOptions = configureBridgeOptions(sockJsConfig);

    SockJSHandler sockJSHandler = configureSockJsHandler(vertxContext, bridgeOptions, sockJsConfig);
    boolean CSRFProteceted=sockJsConfig.getBoolean(CSRF_PROTECTED, false);
    if(CSRFProteceted) {
        if(config.getString(CSRF_SECRET, EMPTY_CSRF_SECRET).isEmpty() || config.getString(CSRF_SECRET,
                EMPTY_CSRF_SECRET).length()<12)
            throw new CsrfProtectionEnabledBuInvalidSecretProvided();
        vertxContext.router().route().path(VertxBusContext.DEFAULT_EVENTBUS_PATH).handler(CookieHandler.create());
        vertxContext.router().route().path(VertxBusContext.DEFAULT_EVENTBUS_PATH).handler(
                CSRFHandler.create(config.getString(CSRF_SECRET, EMPTY_CSRF_SECRET)));
    }
    return sockJSHandler;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:20,代码来源:VertxConfigSockJsConfigurator.java

示例4: configureWithConfigurator

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
private void configureWithConfigurator(VertxContext vertxContext,
                                       ServerConfiguration<JsonObject, JsonObject[]> serverConfiguration) {
    ServiceLoader<EventBusSockJsConfigurator> configurators=ServiceLoader.load(EventBusSockJsConfigurator.class);
    String targetConfigurator=serverConfiguration.getString(SOCKJS_CONFIGURATOR_CONFIG_KEY);
    Iterator<EventBusSockJsConfigurator> configuratorIterator=configurators.iterator();
    while(configuratorIterator.hasNext()){
        EventBusSockJsConfigurator configurator=configuratorIterator.next();
        if(configurator.getClass().getName().equals(targetConfigurator)){
            SockJSHandler sockJSHandler=configurator.configure(vertxContext, serverConfiguration);
            vertxContext.router().route().path(VertxBusContext.DEFAULT_EVENTBUS_PATH).handler(sockJSHandler);
            return;
        }
    }

    throw new SockJsConfiguratorNotFoundInClassPathException(targetConfigurator);
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:17,代码来源:SockJsEntryPoint.java

示例5: initWebSocket

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
private void initWebSocket() {
    Router router = Router.router(vertx);
    SockJSHandlerOptions options = new SockJSHandlerOptions()
            .setHeartbeatInterval(1000 * 60);
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);

    PermittedOptions inboundPermitted = new PermittedOptions().setAddressRegex("server/.*");
    PermittedOptions outboundPermitted = new PermittedOptions().setAddressRegex("client/.*");

    BridgeOptions ops = new BridgeOptions()
            .addInboundPermitted(inboundPermitted)
            .addOutboundPermitted(outboundPermitted);

    sockJSHandler.bridge(ops);

    router.route("/eb/*").handler(sockJSHandler);
    mainRouter.mountSubRouter("/ws", router);
}
 
开发者ID:mpusher,项目名称:mpns,代码行数:19,代码来源:AppServer.java

示例6: start

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
@Override
public void start() {
	// Chat with SockJS
	Router router = Router.router(vertx);
	List<String> ids = new ArrayList<>();
	router.route("/chatSockjs/*").handler(SockJSHandler.create(vertx).socketHandler(socket -> {
		final String id = socket.writeHandlerID();
		ids.add(id); // entering
		socket.endHandler(data -> {
			ids.remove(id); // leaving
		});
		socket.handler(buffer -> { // receiving

			// extra: pojo example
			if (Pojofy.socket(socket, Client.urlPojo, buffer, Dto.class, this::serviceDoSomething)) {
				return;
			}

			ids.forEach(i -> vertx.eventBus().send(i, buffer)); // broadcasting
			// to reply to one: socket.write()

		});
	}));

	AllExamplesServer.start(Client.class, router);
}
 
开发者ID:nielsbaloe,项目名称:vertxui,代码行数:27,代码来源:ExampleChatSockjs.java

示例7: createSockJSServer

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
private void createSockJSServer(final ConfigurationContext context)  throws InitializationException {

        final int port = context.getProperty(PORT).asInteger();
        final String ContextPath = context.getProperty(CONTEXT_PATH).getValue();

        Router router = Router.router(vertx);

        SockJSHandler sockJSHandler = SockJSHandler.create(vertx);

        BridgeOptions options = new BridgeOptions();
        if (context.getProperty(INBOUND_ADDRESS_REGEX).isSet()) {
            options.addInboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(INBOUND_ADDRESS_REGEX).getValue()));
        }
        if (context.getProperty(OUTBOUND_ADDRESS_REGEX).isSet()) {
            options.addOutboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(OUTBOUND_ADDRESS_REGEX).getValue()));
        }

        sockJSHandler.bridge(options);

        router.route(ContextPath).handler(sockJSHandler);
        httpServer = vertx.createHttpServer().requestHandler(router::accept).listen(port);
    }
 
开发者ID:xmlking,项目名称:nifi-websocket,代码行数:23,代码来源:VertxService.java

示例8: visit

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
public void visit() {
  sockJSHandler = SockJSHandler.create(config.getVertx(), config.getSockJSOptions());
  try {
    instance = clazz.newInstance();
    injectServices();
  } catch (Exception e) {
    throw new VertxException("Could not instanciate socket controller : " + clazz.getName(), e);
  }
  createHandlers();
  sockJSHandler.socketHandler(ws -> {
    openHandlers.forEach(handler -> tryToInvoke(instance, handler, ws, null));
    ws.handler(buff -> messageHandlers.forEach(messageHandler -> tryToInvoke(instance, messageHandler, ws, buff)));
    ws.endHandler(voidz -> closeHandlers.forEach(closeHandler -> tryToInvoke(instance, closeHandler, ws, null)));
  });
  normalizePath();
  router.route(path).handler(sockJSHandler);
}
 
开发者ID:aesteve,项目名称:nubes,代码行数:18,代码来源:SockJSVisitor.java

示例9: serviceAndSockJS

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
public void serviceAndSockJS(Vertx vertx) {
  SomeDatabaseService service = new SomeDatabaseServiceImpl();
  ProxyHelper.registerService(SomeDatabaseService.class, vertx, service,
      "database-service-address");


  Router router = Router.router(vertx);
  // Allow events for the designated addresses in/out of the event bus bridge
  BridgeOptions opts = new BridgeOptions()
      .addInboundPermitted(new PermittedOptions()
          .setAddress("database-service-address"))
      .addOutboundPermitted(new PermittedOptions()
          .setAddress("database-service-address"));

  // Create the event bus bridge and add it to the router.
  SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts);
  router.route("/eventbus/*").handler(ebHandler);

  vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:21,代码来源:Examples.java

示例10: example48_1

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
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);
    BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);

    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);
    });

    router.route("/eventbus/*").handler(sockJSHandler);


  }
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:WebExamples.java

示例11: example49

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
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);
    BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);

    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);
    });

    router.route("/eventbus/*").handler(sockJSHandler);


  }
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:WebExamples.java

示例12: handleSocketIdle

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
public void handleSocketIdle(Vertx vertx, PermittedOptions inboundPermitted) {
  Router router = Router.router(vertx);

  // Initialize SockJS handler
  SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
  BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted).setPingTimeout(5000);

  sockJSHandler.bridge(options, be -> {
    if (be.type() == BridgeEventType.SOCKET_IDLE) {
      // Do some custom handling...
    }

    be.complete(true);
  });

  router.route("/eventbus/*").handler(sockJSHandler);
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:WebExamples.java

示例13: eventBusHandler

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
  SockJSHandler handler = SockJSHandler.create(vertx);
  BridgeOptions options = new BridgeOptions();
  // open access
  PermittedOptions permitted = new PermittedOptions();
  options.addOutboundPermitted(permitted);
  handler.bridge(options);
  return handler;
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:10,代码来源:WebServerVerticle.java

示例14: configureSockJsHandler

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
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, new JsonArray().add("*"));

    sockJSHandler.socketHandler(event -> jsonArray.forEach(o -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, (String)o)));
    return sockJSHandler;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:10,代码来源:VertxConfigSockJsConfigurator.java

示例15: configure

import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入依赖的package包/类
@Override
public SockJSHandler configure(VertxContext vertxContext, ServerConfiguration<JsonObject, JsonObject[]> config) {
    BridgeOptions bridgeOptions=new BridgeOptions();
    bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddress(VertxBusContext.DEFAULT_SOCKJS_ADDRESS));

    SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx());
    sockJSHandler.bridge(bridgeOptions, event -> event.complete(true));

    sockJSHandler.socketHandler(event -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL));
    return sockJSHandler;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:12,代码来源:DefaultEventBusSockJsConfigurator.java


注:本文中的io.vertx.ext.web.handler.sockjs.SockJSHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。