PublicRestApi { @GET @Path("/{app_id}/metrics") @Produces (MediaType.APPLICATION_JSON) public Response getMetrics(@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 service_id; String request_url; Map<String, String> service_info; try{ service_info = getserverinfo(app_id); server_url = service_info.get("server_url"); service_id = service_info.get("service_id"); } 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 newerThan=0, timeRange=0; if (!ValidateUtil.isNull(startTime)){ newerThan = Long.parseLong(startTime); } if (!ValidateUtil.isNull(endTime)){ timeRange = (Long.parseLong(endTime) - newerThan)/(60*1000); } long now = new Date().getTime(); if (timeRange <= 0) timeRange = Constants.DASHBORAD_TIME_RANGE; if (newerThan == 0) { newerThan = now - timeRange * 60 * 1000; if (newerThan <= 0) newerThan = 0; } request_url = server_url + "/services/metrics/" + service_id + "/"+ app_id + "?newerThan=" + newerThan + "&timeRange=" + timeRange ; 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_METRICS_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_Metric_Data_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_Metric_Data_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 metric : " + e.getMessage()); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_Get_Metric_Data_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 getMetricsTest(){ WebResource webResource = resource(); ClientResponse response = webResource.path("/apps/" + TESTAPPID + "/metrics").type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(response.getStatus(), STATUS200); }