PublicRestApi { @GET @Path("/{app_id}/scalinghistory") @Produces (MediaType.APPLICATION_JSON) public Response getHistory(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, @QueryParam ("startTime") String startTime, @QueryParam ("endTime") String endTime) { Client client = RestUtil.getHTTPSRestClient(); String server_url; String request_url; Map<String, String> service_info; try{ service_info = getserverinfo(app_id); server_url = service_info.get("server_url"); } catch (CloudException e) { return RestApiResponseHandler.getResponseCloudError(e, LocaleUtil.getLocale(httpServletRequest)); } catch (AppNotFoundException e){ return RestApiResponseHandler.getResponseAppNotFound(e, LocaleUtil.getLocale(httpServletRequest)); } catch (ServiceNotFoundException e){ return RestApiResponseHandler.getResponseServiceNotFound(e, LocaleUtil.getLocale(httpServletRequest)); } catch (InternalAuthenticationException e) { return RestApiResponseHandler.getResponseInternalAuthenticationFail(e, LocaleUtil.getLocale(httpServletRequest)); } catch (Exception e) { logger.info("error in getserverinfo: " + e.getMessage()); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_retrieve_application_service_information_context, e), LocaleUtil.getLocale(httpServletRequest)); } try{ long now = new Date().getTime(); long new_start_time=0, new_end_time=0; if (!ValidateUtil.isNull(startTime)){ new_start_time = Long.parseLong(startTime); } if (!ValidateUtil.isNull(endTime)){ new_end_time = Long.parseLong(endTime); } if ((new_start_time <= 0) && (new_end_time <= 0)){ new_start_time = now - Constants.DASHBORAD_TIME_RANGE * 60 * 1000 * 100; new_end_time = now; } else if((new_start_time > 0) && (new_end_time <= 0)) { new_end_time = new_start_time + Constants.DASHBORAD_TIME_RANGE * 60 * 1000 * 100; } else if((new_start_time <= 0) && (new_end_time > 0)) { new_start_time = new_end_time - Constants.DASHBORAD_TIME_RANGE * 60 * 1000 * 100; if (new_start_time < 0) new_start_time = 0; } long time_range = new_end_time - new_start_time; if (time_range <= 0) { if (new_start_time < now) { new_end_time = now; } else { new_start_time = now - Constants.DASHBORAD_TIME_RANGE * 60 * 1000 * 100; new_end_time = now; } } request_url = server_url + "/resources/history/" + "?appId=" + app_id + "&startTime=" + new_start_time + "&endTime=" + new_end_time; WebResource webResource = client.resource(request_url); String authorization = ConfigManager.getInternalAuthToken(); ClientResponse response = webResource.header("Authorization", "Basic " + authorization).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); if (response.getStatus() == HttpServletResponse.SC_OK) { String result = response.getEntity(String.class); Map<String, String> check_result = ValidateUtil.handleOutput(DataType.GET_HISTORY_RESPONSE, result, new HashMap<String, String>(), service_info, httpServletRequest); if (check_result.get("result") != "OK") return RestApiResponseHandler.getResponseBadRequest(check_result.get("error_message")); return RestApiResponseHandler.getResponseJsonOk(check_result.get("json")); } else{ String response_body = response.getEntity(String.class); if (response.getStatus() == HttpServletResponse.SC_BAD_REQUEST) { logger.info("Get back-end server bad request error : " + response.getStatus() + " with response body: " + response_body); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_Get_Scaling_History_context), LocaleUtil.getLocale(httpServletRequest)); }else{ logger.info("Get back-end server error : " + response.getStatus() + " with response body: " + response_body); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_Get_Scaling_History_context), LocaleUtil.getLocale(httpServletRequest)); } } } catch (OutputJSONParseErrorException e){ return RestApiResponseHandler.getResponseOutputJsonParseError(e, LocaleUtil.getLocale(httpServletRequest)); } catch (OutputJSONFormatErrorException e){ return RestApiResponseHandler.getResponseOutputJsonFormatError(e, LocaleUtil.getLocale(httpServletRequest)); } catch (Exception e){ logger.info("error in get history : " + e.getMessage()); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_Get_Scaling_History_context, e), LocaleUtil.getLocale(httpServletRequest)); } }  static PublicRestApi getInstance(); @PUT @Path("/{app_id}/policy") @Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response createPolicy(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, String jsonString); @DELETE @Path("/{app_id}/policy") // @Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response deletePolicy(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, String jsonString); @GET @Path("/{app_id}/policy") //@Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response getPolicy(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id); @PUT @Path("/{app_id}/policy/status") @Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response enablePolicy(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, String jsonString); @GET @Path("/{app_id}/policy/status") //@Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response getPolicyStatus(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id); @GET @Path("/{app_id}/scalinghistory") //@Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response getHistory(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, 
    		@QueryParam ("startTime") String startTime, @QueryParam ("endTime") String endTime); @GET @Path("/{app_id}/metrics") //@Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) Response getMetrics(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, 
    		@QueryParam ("startTime") String startTime, @QueryParam ("endTime") String endTime); Map<String, String> getserverinfo(String app_id);  }
@Test public void getHistoryTest(){ WebResource webResource = resource(); ClientResponse response = webResource.path("/apps/" + TESTAPPID + "/scalinghistory").type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(response.getStatus(), STATUS200); }