2017-09-15 8 views
0

Vert.xで実行することはできますか:残りのapiではvertx-jersey、SockJSHandlerでは1つのポートでVert.x Webを実行できますか?ジャーナル、静的リソース、およびsockjsを使用してVert.xの残りのAPIでサービスする方法

私は残念ながら "localhost:8080/api"、 "localhost:8080/ebus"はsockjs公開メッセージ、 "localhost:8080 /"はjavascriptフロントエンドを提供したいと考えています。

答えて

0

あなただけでなく、それはそれが行われている通常の方法です。

final Pattern chatUrlPattern = Pattern.compile("/ebus/(\\w+)"); 
    final EventBus eventBus = this.vertx.eventBus(); 

    final Router router = Router.router(this.vertx); 

    // Or wherever your static content is 
    router.route("web/*").handler(StaticHandler.create());   

    this.vertx.createHttpServer().websocketHandler(ws -> { 
     final Matcher m = chatUrlPattern.matcher(ws.path()); 
     if (!m.matches()) { 
      ws.reject(); 
      return; 
     } 
     /* Your code here */ 
    } 

    // Your Jersey code here, for example: 
    vertx.runOnContext(aVoid -> { 

     // Set up the jersey configuration 
     // The minimum config required is a package to inspect for JAX-RS endpoints 
     vertx.getOrCreateContext().config() 
       .put("jersey", new JsonObject() 
         .put("port", 8080) 
         .put("packages", new JsonArray() 
           .add(HelloWorldEndpoint.class.getPackage().getName()))); 

     // Use a service locator (HK2 or Guice are supported by default) to create the jersey server 
     ServiceLocator locator = ServiceLocatorUtilities.bind(new HK2JerseyBinder(), new HK2VertxBinder(vertx)); 
     JerseyServer server = locator.getService(JerseyServer.class); 

     // Start the server which simply returns "Hello World!" to each GET request. 
     server.start(); 

    }); 
+0

ありがとう、私はJerseyVerticleと積み重ねられました、あなたは私に良い方向を指摘しました。 –

関連する問題