@Override public Response getApiInfo(UriInfo uriInfo, String protocol) { logger.debug("ApiInfoVO requested"); ApiInfoVO apiInfo = new ApiInfoVO(); String version = Constants.class.getPackage().getImplementationVersion(); if(version == null) { apiInfo.setApiVersion(appVersion); } else { apiInfo.setApiVersion(version); } apiInfo.setServerTimestamp(timestampService.getDate()); // Generate websocket url based on current request url int port = uriInfo.getBaseUri().getPort(); String wsScheme = "https".equals(protocol) ? "wss" : "ws"; if (port == -1) { apiInfo.setWebSocketServerUrl(wsScheme + "://" + uriInfo.getBaseUri().getHost() + contextPath + "/websocket"); } else { apiInfo.setWebSocketServerUrl(wsScheme + "://" + uriInfo.getBaseUri().getHost() + ":" + uriInfo.getBaseUri().getPort() + contextPath + "/websocket"); } return ResponseFactory.response(Response.Status.OK, apiInfo, JsonPolicyDef.Policy.REST_SERVER_INFO); }
@HiveWebsocketAuth @PreAuthorize("permitAll") public void processServerInfo(JsonObject request, WebSocketSession session) { logger.debug("server/info action started. Session " + session.getId()); ApiInfoVO apiInfo = new ApiInfoVO(); apiInfo.setApiVersion(Constants.class.getPackage().getImplementationVersion()); session.getHandshakeHeaders().get("Host").stream() .findFirst() .ifPresent(host -> apiInfo.setRestServerUrl("http://" + host + contextPath + "/rest")); apiInfo.setServerTimestamp(timestampService.getDate()); WebSocketResponse response = new WebSocketResponse(); response.addValue(INFO, apiInfo, WEBSOCKET_SERVER_INFO); logger.debug("server/info action completed. Session {}", session.getId()); clientHandler.sendMessage(request, response, session); }