@Path("/hardwareInfo") @ChannelHandler.Sharable public class HardwareStatsLogic extends CookiesBaseHttpHandler {
private static HandlerWrapper[] registerHandler(String rootPath, Object handler, GlobalStats globalStats) { Class<?> handlerClass = handler.getClass(); Annotation pathAnnotation = handlerClass.getAnnotation(Path.class); String handlerMainPath = ((Path) pathAnnotation).value(); List<HandlerWrapper> processors = new ArrayList<>(); for (Method method : handlerClass.getMethods()) { Annotation consumes = method.getAnnotation(Consumes.class); String contentType = MediaType.APPLICATION_JSON; if (consumes != null) { contentType = ((Consumes) consumes).value()[0]; } Annotation path = method.getAnnotation(Path.class); if (path != null) { String fullPath = rootPath + handlerMainPath + ((Path) path).value(); UriTemplate uriTemplate = new UriTemplate(fullPath); HandlerWrapper handlerHolder = new HandlerWrapper(uriTemplate, method, handler, globalStats); for (int i = 0; i < method.getParameterCount(); i++) { Parameter parameter = method.getParameters()[i]; handlerHolder.params[i] = resolveParam(parameter, contentType); } processors.add(handlerHolder); } } return processors.toArray(new HandlerWrapper[0]); }
@Path("") @ChannelHandler.Sharable public class AdminAuthHandler extends BaseHttpHandler {
@Path("/ota") @ChannelHandler.Sharable public class OTALogic extends AuthHeadersBaseHttpHandler {
@Path("/config") @ChannelHandler.Sharable public class ConfigsLogic extends CookiesBaseHttpHandler {
@GET @Path("/names/getAll") public Response getAllUserNames() { return ok(userDao.users.keySet()); }
@Path("/stats") @ChannelHandler.Sharable public class StatsLogic extends CookiesBaseHttpHandler {
@Path("/users") @ChannelHandler.Sharable public class UsersLogic extends CookiesBaseHttpHandler {
@Path("/") @ChannelHandler.Sharable public class ResetPasswordHttpLogic extends BaseHttpHandler {
@GET @Path("/realtime") public Response getReatime() { return ok(Collections.singletonList( new Stat(sessionDao, userDao, blockingIOProcessor, globalStats, reportScheduler, false))); }
@Path("/") @ChannelHandler.Sharable public class HttpAPILogic extends TokenBaseHttpHandler {
@GET @Path("/stop") @Metric(HTTP_START_OTA) public Response stopOTA(@Context ChannelHandlerContext ctx) { User initiator = ctx.channel().attr(AuthHeadersBaseHttpHandler.USER).get(); otaManager.stop(initiator); return ok(); }
@GET @Path("restore") public Response getNewResetPage(@QueryParam("token") String token, @QueryParam("email") String email) { //we do not check token here, as we used single host but we may have many servers //ResetPassToken user = tokensPool.getBaseToken(token); //if (user == null) { // return badRequest("Your token was not found or it is outdated. Please try again."); //} log.info("{} landed.", email); String resetUrl = "http://" + resetClickHost + "/restore?token=" + token + "&email=" + email; String body = newResetPage.replace(Placeholders.RESET_URL, resetUrl); return ok(body, MediaType.TEXT_HTML); }
@GET @Path("landing") public Response generateResetPage(@QueryParam("token") String token) { BaseToken baseToken = tokensPool.getBaseToken(token); if (baseToken == null) { return badRequest("Your token was not found or it is outdated. Please try again."); } log.info("{} landed.", baseToken.email); String page = pageContent.replace(Placeholders.EMAIL, baseToken.email).replace(Placeholders.TOKEN, token); return ok(page, MediaType.TEXT_HTML); }
@GET @Path("/requestsPerUser") public Response getRequestPerUser(@QueryParam("_sortField") String sortField, @QueryParam("_sortDir") String sortOrder) { List<RequestPerSecondResponse> res = new ArrayList<>(); for (Map.Entry<UserKey, Session> entry : sessionDao.userSession.entrySet()) { Session session = entry.getValue(); int appReqRate = session.getAppRequestRate(); int hardReqRate = session.getHardRequestRate(); if (appReqRate > 0 || hardReqRate > 0) { res.add(new RequestPerSecondResponse(entry.getKey().email, appReqRate, hardReqRate)); } } return ok(sort(res, sortField, sortOrder)); }
@POST @Path("/logout") public Response logout() { Response response = redirect(rootPath); Cookie cookie = makeDefaultSessionCookie("", 0); response.headers().add(SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); return response; }
@GET @Path("") public Response getConfigs(@QueryParam("_filters") String filterParam, @QueryParam("_page") int page, @QueryParam("_perPage") int size, @QueryParam("_sortField") String sortField, @QueryParam("_sortDir") String sortOrder) { List<Config> configs = new ArrayList<>(); configs.add(new Config(SERVER_PROPERTIES_FILENAME)); configs.add(new Config(MAIL_PROPERTIES_FILENAME)); configs.add(new Config(GCM_PROPERTIES_FILENAME)); configs.add(new Config(DB_PROPERTIES_FILENAME)); configs.add(new Config(TWITTER_PROPERTIES_FILENAME)); configs.add(new Config(TOKEN_MAIL_BODY)); return appendTotalCountHeader( ok(sort(configs, sortField, sortOrder), page, size), configs.size() ); }
@GET @Path("{token}/project") @Metric(HTTP_GET_PROJECT) public Response getDashboard(@PathParam("token") String token) { TokenValue tokenValue = tokenManager.getTokenValueByToken(token); if (tokenValue == null) { log.debug("Requested token {} not found.", token); return badRequest("Invalid token."); } return ok(JsonParser.toJsonRestrictiveDashboardForHTTP(tokenValue.dash)); }
@GET @Path("{token}/data/{pin}") @Metric(HTTP_GET_HISTORY_DATA) public Response getPinHistoryData(@PathParam("token") String token,
@PUT @Consumes(value = MediaType.APPLICATION_JSON) @Path("/{name}") public Response updateConfig(@PathParam("name") String name, Config updatedConfig) { log.info("Updating config {}. New body : ", name); log.info("{}", updatedConfig.body); switch (name) { case TOKEN_MAIL_BODY: textHolder.tokenBody = updatedConfig.body; break; case SERVER_PROPERTIES_FILENAME : Properties properties = readPropertiesFromString(updatedConfig.body); serverProperties.putAll(properties); break; } return ok(updatedConfig.toString()); }