private void deregisterHandler(final int portNumber) {
   final HttpServer httpServer = findHttpServer(portNumber);
   if (httpServer != null) {
     httpServer.close();
     servers.remove(portNumber);
   }
 }
示例#2
0
  public DefaultSockJSServer(final VertxInternal vertx, final HttpServer httpServer) {
    this.vertx = vertx;
    this.sessions = vertx.sharedData().getMap("_vertx.sockjssessions");
    // Any previous request and websocket handlers will become default handlers
    // if nothing else matches
    rm.noMatch(httpServer.requestHandler());
    wsMatcher.noMatch(
        new Handler<WebSocketMatcher.Match>() {
          Handler<ServerWebSocket> wsHandler = httpServer.websocketHandler();

          public void handle(WebSocketMatcher.Match match) {
            if (wsHandler != null) {
              wsHandler.handle(match.ws);
            }
          }
        });
    httpServer.requestHandler(
        new Handler<HttpServerRequest>() {
          @Override
          public void handle(HttpServerRequest req) {
            if (log.isTraceEnabled()) {
              log.trace("Got request in sockjs server: " + req.uri);
            }
            rm.handle(req);
          }
        });
    httpServer.websocketHandler(wsMatcher);
  }
示例#3
0
  public void start() {
    server = new HttpServer();

    server.requestHandler(
        new Handler<HttpServerRequest>() {
          public void handle(HttpServerRequest req) {
            if (req.path.equals("/")) req.response.sendFile("sockjs/index.html"); // Serve the html
          }
        });

    SockJSServer sockServer = new SockJSServer(server);

    sockServer.installApp(
        new AppConfig().setPrefix("/testapp"),
        new Handler<SockJSSocket>() {
          public void handle(final SockJSSocket sock) {
            sock.dataHandler(
                new Handler<Buffer>() {
                  public void handle(Buffer data) {
                    sock.writeBuffer(data); // Echo it back
                  }
                });
          }
        });

    server.listen(8080);
  }
示例#4
0
 // For debug only
 public static void main(String[] args) throws Exception {
   Vertx vertx = Vertx.newVertx();
   HttpServer httpServer = vertx.createHttpServer();
   DefaultSockJSServer sjsServer = (DefaultSockJSServer) vertx.createSockJSServer(httpServer);
   sjsServer.installTestApplications();
   httpServer.listen(8081);
   Thread.sleep(Long.MAX_VALUE);
 }
 private HttpServer registerHandler(
     final int portNumber, final Handler<HttpServerRequest> handler) {
   final HttpServer httpServer = getHttpServer(portNumber);
   try {
     if (handler != null) {
       httpServer.requestHandler(handler);
     }
     return httpServer;
   } catch (final Exception e) {
     return null;
   }
 }
 private void listen(final HttpServer httpServer, final int portNumber) {
   try {
     httpServer.listen(portNumber);
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }
示例#7
0
  public DefaultSockJSServer(final VertxInternal vertx, final HttpServer httpServer) {
    this.vertx = vertx;
    this.sessions = vertx.sharedData().getMap("_vertx.sockjssessions");
    // Any previous request and websocket handlers will become default handlers
    // if nothing else matches
    rm.noMatch(httpServer.requestHandler());
    wsMatcher.noMatch(
        new Handler<WebSocketMatcher.Match>() {
          Handler<ServerWebSocket> wsHandler = httpServer.websocketHandler();

          public void handle(WebSocketMatcher.Match match) {
            wsHandler.handle(match.ws);
          }
        });

    httpServer.requestHandler(rm);
    httpServer.websocketHandler(wsMatcher);
  }
 public void stop() {
   server.close(
       new SimpleHandler() {
         public void handle() {
           tu.checkContext();
           tu.appStopped();
         }
       });
 }
示例#9
0
  public void startup(@Observes ProviderStartupEvent event) {
    server = westtyVertx.createHttpServer();
    JsonArray permitted = new JsonArray();
    // Let everything through
    permitted.add(new JsonObject());

    SockJSServer sockJSServer = westtyVertx.createSockJSServer(server);
    sockJSServer.bridge(new JsonObject().putString("prefix", "/eventbus"), permitted, permitted);
    server.listen(config.getHttpPort());
    log.info("SockJs started on port " + config.getHttpPort());
    endpoints.start(bus);
    log.info("EventBus started on port " + config.getEventBusPort());
  }
示例#10
0
 public void shutdown(@Observes ProviderShutdownEvent event) {
   log.info("Shutdown SockJs");
   if (server != null) {
     server.close();
   }
 }
示例#11
0
  public void start() {
    port = 8080;
    HttpServer server = vertx.createHttpServer();

    io = new DefaultSocketIOServer(vertx, server);
    io.sockets()
        .onConnection(
            new Handler<SocketIOSocket>() {
              public void handle(final SocketIOSocket socket) {
                socket.on(
                    "message",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("roomid");
                        event.removeField("roomid");
                        socket.broadcast().to(roomid).emit("message", event);
                      }
                    });
                socket.on(
                    "create",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        int rtcMax = event.getInteger("rtcMax");
                        int isOpen = Integer.parseInt(event.getString("isOpen"));

                        if (db.setRtcMax(roomid, rtcMax, isOpen)) {
                          System.out.println("RTC준비 완료");
                        }
                      }
                    });
                socket.on(
                    "trysignal",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        String host = db.get_Host(roomid);
                        int successLv;

                        event.putString("to", host);

                        // rtc접속 인원 관리
                        successLv = db.upRtcNow(roomid);
                        if (successLv != 0) socket.broadcast().to(roomid).emit("message", event);

                        if (successLv == 0) {
                          event.putBoolean("result", false);
                          event.putBoolean("available", false);
                        } else if (successLv == 1) {
                          event.putBoolean("result", true);
                          event.putBoolean("available", false);
                        } else {
                          event.putBoolean("result", true);
                          event.putBoolean("available", true);
                        }

                        event.removeField("to");
                        event.removeField("participationRequest");
                        io.sockets().in(roomid).emit("signalFlag", event); // 방안에 나포함 전체한테 보내는거
                      }
                    });
                socket.on(
                    "leave",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        boolean available = false; //
                        String userid = event.getString("userid");
                        String host = db.get_Host(roomid); // 방장 u_id

                        event.removeField("to");

                        if (host.equals(
                            userid)) { // 방장이 나간 경우(데이터베이스를 다 지워주고, 서버에서 폴더와 파일 삭제, 참여자들은 첫 페이지로 이동
                          ArrayList<User_Entity> list = db.get_User(roomid);
                          db.del_Access_All(roomid);
                          db.del_Files(roomid);
                          db.del_Room(roomid);

                          for (int i = 0; i < list.size(); i++) {
                            db.del_User(list.get(i).getU_id()); // user_list 테이블에서 유저 삭제
                          }
                          event.putBoolean("maintain", false); // 방 유지 여부(false면 방 아웃)

                          String uploadPath = realPath + "\\" + roomid;
                          File tempDir = new File(uploadPath);
                          String[] files = tempDir.list();

                          if (files != null) {
                            for (int i = 0; i < files.length; i++) {
                              File f = new File(tempDir, files[i]);
                              f.delete();
                            }
                          }

                          tempDir.delete();
                        } else { // 참여자가 나간 경우, 자신의 정보를 회의방 사람들에게 알려줌.
                          db.leave_room(userid); // access_list 테이블에서 유저 삭제
                          db.del_User(userid); // user_list 테이블에서 유저 삭제

                          // rtc접속 인원 관리
                          if (event.getBoolean("rtc")) {
                            available = db.downRtcNow(roomid);
                          }

                          // event.putString("host", host);
                          event.putBoolean("maintain", true);
                        }

                        // 2. 참여자가 나간 경우 먼저 access_list 테이블에서 참여자 정보 삭제하기.

                        event.putBoolean("available", available);
                        socket
                            .broadcast()
                            .to(roomid)
                            .emit("message", event); // 나를 제외한 나머지에게, 새로 들어온 정보만
                        socket.leave(roomid);
                      }
                    });

                // 회의방 입장
                socket.on(
                    "enter_room",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        JsonObject message = new JsonObject();

                        String roomid = event.getString("to");
                        String userid = event.getString("userid");
                        String host = db.get_Host(roomid);

                        JsonArray users = new JsonArray(); // 참여자 목록을 담기위한 JSONArray
                        event = new JsonObject();

                        ArrayList<User_Entity> list = db.get_User(roomid);

                        for (int i = 0; i < list.size(); i++) {

                          if (list.get(i).getU_id().equals(host)) {
                            event.putString("hostname", list.get(i).getName()); // 방장 이름
                            event.putString("host", host); // 방장 아이디
                          }

                          if (list.get(i).getU_id().equals(userid)) {
                            event.putString("username", list.get(i).getName()); // 자기 자신 이름
                            event.putString("userid", userid); // 자기 자신 아이디
                            message.putString("user_name", list.get(i).getName());
                            message.putString("userid", userid);
                          } else {
                            JsonObject user = new JsonObject();
                            user.putString("user_name", list.get(i).getName());
                            user.putString("user_id", list.get(i).getU_id());

                            users.add(user);
                          }
                        }

                        event.putArray("user_list", users);

                        socket.join(roomid);
                        socket
                            .broadcast()
                            .to(roomid)
                            .emit("enter", message); // 나를 제외한 나머지에게, 새로 들어온 정보만
                        socket.emit("enter", event);
                      }
                    });

                // 슬라이드 페이지 관리
                socket.on(
                    "slide_control",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        socket.broadcast().to(roomid).emit("page_control", event);
                      }
                    });

                // 선택한 파일 변경
                socket.on(
                    "selectfile",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드
                        String file = event.getString("file"); // 파일 이름

                        event.removeField("to");
                        int slide_count = db.get_SlideNum(roomid, file);

                        event.putNumber("count", slide_count);

                        socket.emit("select_file", event);
                      }
                    });

                // 슬라이드쇼 시작 / 종료
                socket.on(
                    "slide_show",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드
                        String file = event.getString("file"); // 파일 이름
                        boolean show = event.getBoolean("show");
                        System.out.println("show : " + show);
                        event.removeField("show");
                        // 슬라이드쇼 시작
                        if (show) {
                          int count = db.get_SlideNum(roomid, file);
                          event.putNumber("count", count);
                          socket.broadcast().to(roomid).emit("show_start", event);
                        }
                        // 슬라이드쇼 종료
                        else {
                          io.sockets().in(roomid).emit("show_stop", event); // 방안에 나포함 전체한테 보내는거
                        }
                      }
                    });

                // 채팅
                socket.on(
                    "chat",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        event.removeField("to");
                        socket.broadcast().to(roomid).emit("chat", event);
                      }
                    });

                // 포인터 동기화
                socket.on(
                    "syncPoint",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to");
                        event.removeField("to");

                        socket.broadcast().to(roomid).emit("syncPoint", event);
                      }
                    });

                // 권한 요청
                socket.on(
                    "c_request",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드

                        event.removeField("to");
                        socket.broadcast().to(roomid).emit("c_request", event);
                      }
                    });

                // 수락
                socket.on(
                    "c_accept",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드

                        event.removeField("to");
                        socket.broadcast().to(roomid).emit("c_accept", event);
                      }
                    });

                // 권한 요청 중지
                socket.on(
                    "request_stop",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드

                        event.removeField("to");
                        io.sockets().in(roomid).emit("request_stop", event); // 방안에 나포함 전체한테 보내는거		
                      }
                    });

                // 권한 요청 중지
                socket.on(
                    "request_cancel",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드

                        event.removeField("to");
                        io.sockets().in(roomid).emit("request_cancel", event);
                      }
                    });

                // 권한 거절하기
                socket.on(
                    "refuse",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드

                        event.removeField("to");
                        socket.broadcast().to(roomid).emit("refuse", event);
                      }
                    });

                // 방 초기화 정보
                socket.on(
                    "tryRoomInfo",
                    new Handler<JsonObject>() {
                      public void handle(JsonObject event) {
                        String roomid = event.getString("to"); // 엑세스 코드
                        event.removeField("to");

                        socket.broadcast().to(roomid).emit("tryRoomInfo", event);
                      }
                    });
              }
            });

    server.listen(port);
  }
示例#12
0
  @Override
  public void stop() {

    if (sharedHttpServers != null) {
      for (HttpServer server : sharedHttpServers.values()) {
        server.close();
      }
      sharedHttpServers = null;
    }

    if (sharedNetServers != null) {
      for (NetServer server : sharedNetServers.values()) {
        server.close();
      }
      sharedNetServers = null;
    }

    if (timer != null) {
      timer.stop();
      timer = null;
    }

    if (eventBus != null) {
      eventBus.close(null);
    }

    if (backgroundPool != null) {
      backgroundPool.shutdown();
    }

    if (acceptorPool != null) {
      acceptorPool.shutdown();
    }

    try {
      if (backgroundPool != null) {
        backgroundPool.awaitTermination(20, TimeUnit.SECONDS);
        backgroundPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    try {
      if (acceptorPool != null) {
        acceptorPool.awaitTermination(20, TimeUnit.SECONDS);
        acceptorPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    // log.info("Release external resources from worker pool");
    if (corePool != null) {
      corePool.releaseExternalResources();
      corePool = null;
    }
    // log.info("Release external resources: done");

    setContext(null);
  }
示例#13
0
 public void stop() {
   server.close();
 }
示例#14
0
  public void request(
      final String method,
      final String url,
      final MultiMap headers,
      final Buffer body,
      final Handler<Response> handler) {
    try {
      final URI uri = new URI(url);
      final boolean urlEncoded =
          "application/x-www-form-urlencoded".equalsIgnoreCase(headers.get("content-type"));

      final Response response = new Response(vertx, handler);

      // start yoke
      fakeServer
          .requestHandler()
          .handle(
              new HttpServerRequest() {

                MultiMap params = null;
                MultiMap attributes = null;

                @Override
                public HttpVersion version() {
                  return HttpVersion.HTTP_1_1;
                }

                @Override
                public String method() {
                  return method.toUpperCase();
                }

                @Override
                public String uri() {
                  return uri.getPath() + "?" + uri.getQuery() + "#" + uri.getFragment();
                }

                @Override
                public String path() {
                  return uri.getPath();
                }

                @Override
                public String query() {
                  return uri.getQuery();
                }

                @Override
                public HttpServerResponse response() {
                  return response;
                }

                @Override
                public MultiMap headers() {
                  return headers;
                }

                @Override
                public MultiMap params() {
                  if (params == null) {
                    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri());
                    Map<String, List<String>> prms = queryStringDecoder.parameters();
                    params = new CaseInsensitiveMultiMap();

                    if (!prms.isEmpty()) {
                      for (Map.Entry<String, List<String>> entry : prms.entrySet()) {
                        params.add(entry.getKey(), entry.getValue());
                      }
                    }
                  }
                  return params;
                }

                @Override
                public InetSocketAddress remoteAddress() {
                  return new InetSocketAddress("127.0.0.1", 80);
                }

                @Override
                public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException {
                  return null;
                }

                @Override
                public URI absoluteURI() {
                  return uri;
                }

                @Override
                public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
                  bodyHandler.handle(body);
                  return this;
                }

                @Override
                public HttpServerRequest dataHandler(Handler<Buffer> handler) {
                  handler.handle(body);
                  return this;
                }

                @Override
                public HttpServerRequest pause() {
                  throw new UnsupportedOperationException("This mock does not support pause");
                }

                @Override
                public HttpServerRequest resume() {
                  throw new UnsupportedOperationException("This mock does not support resume");
                }

                @Override
                public HttpServerRequest endHandler(Handler<Void> endHandler) {
                  endHandler.handle(null);
                  return this;
                }

                @Override
                public NetSocket netSocket() {
                  throw new UnsupportedOperationException("This mock does not support netSocket");
                }

                @Override
                public HttpServerRequest expectMultiPart(boolean expect) {
                  // NOOP
                  return this;
                }

                @Override
                public HttpServerRequest uploadHandler(
                    Handler<HttpServerFileUpload> uploadHandler) {
                  throw new UnsupportedOperationException(
                      "This mock does not support uploadHandler");
                }

                @Override
                public MultiMap formAttributes() {
                  if (attributes == null) {
                    attributes = new CaseInsensitiveMultiMap();
                    if (urlEncoded) {
                      QueryStringDecoder queryStringDecoder =
                          new QueryStringDecoder(body.toString(), false);

                      Map<String, List<String>> prms = queryStringDecoder.parameters();

                      if (!prms.isEmpty()) {
                        for (Map.Entry<String, List<String>> entry : prms.entrySet()) {
                          attributes.add(entry.getKey(), entry.getValue());
                        }
                      }
                    }
                  }
                  return attributes;
                }

                @Override
                public HttpServerRequest exceptionHandler(Handler<Throwable> handler) {
                  throw new UnsupportedOperationException(
                      "This mock does not support exceptionHandler");
                }
              });
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
  }
示例#15
0
 public YokeTester(Verticle verticle, boolean fakeSSL) {
   super(verticle);
   this.vertx = verticle.getVertx();
   fakeServer.setSSL(fakeSSL);
   listen(fakeServer);
 }