PublicRestApi { @PUT @Path("/{app_id}/policy/status") @Consumes(MediaType.APPLICATION_JSON) @Produces (MediaType.APPLICATION_JSON) public Response enablePolicy(@Context final HttpServletRequest httpServletRequest, @PathParam("app_id") String app_id, String jsonString) { logger.info("Received JSON String of policy content: "+jsonString); Client client = RestUtil.getHTTPSRestClient(); String policyId; String server_url; String request_url; Map<String, String> service_info; try{ service_info = getserverinfo(app_id); server_url = service_info.get("server_url"); policyId = service_info.get("policyId"); } 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)); } Map<String, String> check_result; try { check_result = ValidateUtil.handleInput(DataType.ENABLE_REQUEST, jsonString, service_info, httpServletRequest); if (check_result.get("result") != "OK") return RestApiResponseHandler.getResponseBadRequest(check_result.get("error_message")); } catch (InputJSONParseErrorException e){ return RestApiResponseHandler.getResponseInputJsonParseError(e, LocaleUtil.getLocale(httpServletRequest)); } catch (InputJSONFormatErrorException e){ return RestApiResponseHandler.getResponseInputJsonFormatError(e, LocaleUtil.getLocale(httpServletRequest)); } catch (Exception e){ return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_parse_input_json_context, e), LocaleUtil.getLocale(httpServletRequest)); } String new_json = check_result.get("json"); if ((policyId != null) && !(policyId.equals("null")) && (policyId.length() > 0)) { try{ request_url = server_url + "/resources/apps/" + app_id; WebResource webResource = client.resource(request_url); JSONObject json = new JSONObject(new_json); json.put("policyId", policyId); String authorization = ConfigManager.getInternalAuthToken(); ClientResponse response = webResource.header("Authorization", "Basic " + authorization).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).put(ClientResponse.class, json.toString()); if (response.getStatus() == HttpServletResponse.SC_OK) { return RestApiResponseHandler.getResponseJsonOk("{}"); } 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_Enable_Policy_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_Enable_Policy_context), LocaleUtil.getLocale(httpServletRequest)); } } } catch (Exception e){ logger.info("error in enable policy : " + e.getMessage()); return RestApiResponseHandler.getResponseInternalServerError(new InternalServerErrorException(MessageUtil.RestResponseErrorMsg_Enable_Policy_context, e), LocaleUtil.getLocale(httpServletRequest)); } } else { return RestApiResponseHandler.getResponsePolicyNotExistError(new PolicyNotFoundException(app_id), 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 enablePolicyTest(){ WebResource webResource = resource(); ClientResponse response = webResource.path("/apps/" + TESTAPPID + "/policy/status").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,"{ \"enable\": true}"); assertEquals(response.getStatus(), STATUS200); }