@Test public void doHttpPutTest() throws Exception{ PowerMockito.when(httpClient.execute((HttpPut) any())).thenReturn(httpResponse); assertNotNull(CommonUtils.doHttpPut("url", "{}")); }
public static String doHttpPut(final String url, final String requestBody) throws Exception { try { HttpClient client = HttpClientBuilder.create().build(); HttpPut httpPut = new HttpPut(url); httpPut.setHeader(CONTENT_TYPE, APPLICATION_JSON); StringEntity jsonEntity = null; if (requestBody != null) { jsonEntity = new StringEntity(requestBody); } httpPut.setEntity(jsonEntity); HttpResponse httpresponse = client.execute(httpPut); if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse.getEntity()); } else { if(AuthManager.getToken()!=null){ String accessToken = AuthManager.getToken(); if(!Strings.isNullOrEmpty(accessToken)) { httpPut.setHeader(PacmanSdkConstants.AUTH_HEADER, "Bearer " + accessToken); } } httpPut.setEntity(jsonEntity); HttpResponse httpresponse1 = client.execute(httpPut); if (httpresponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse1.getEntity()); } else { throw new Exception( "unable to execute put request caused by" + EntityUtils.toString(httpresponse1.getEntity())); } } } catch (ParseException parseException) { LOGGER.error("ParseException in getHttpPut :" + parseException.getMessage()); } catch (IOException ioException) { LOGGER.error("IOException in getHttpPut :" + ioException.getMessage()); } return null; }
CommonUtils { public static String doHttpPut(final String url, final String requestBody) throws Exception { try { HttpClient client = HttpClientBuilder.create().build(); HttpPut httpPut = new HttpPut(url); httpPut.setHeader(CONTENT_TYPE, APPLICATION_JSON); StringEntity jsonEntity = null; if (requestBody != null) { jsonEntity = new StringEntity(requestBody); } httpPut.setEntity(jsonEntity); HttpResponse httpresponse = client.execute(httpPut); if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse.getEntity()); } else { if(AuthManager.getToken()!=null){ String accessToken = AuthManager.getToken(); if(!Strings.isNullOrEmpty(accessToken)) { httpPut.setHeader(PacmanSdkConstants.AUTH_HEADER, "Bearer " + accessToken); } } httpPut.setEntity(jsonEntity); HttpResponse httpresponse1 = client.execute(httpPut); if (httpresponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse1.getEntity()); } else { throw new Exception( "unable to execute put request caused by" + EntityUtils.toString(httpresponse1.getEntity())); } } } catch (ParseException parseException) { LOGGER.error("ParseException in getHttpPut :" + parseException.getMessage()); } catch (IOException ioException) { LOGGER.error("IOException in getHttpPut :" + ioException.getMessage()); } return null; } }
CommonUtils { public static String doHttpPut(final String url, final String requestBody) throws Exception { try { HttpClient client = HttpClientBuilder.create().build(); HttpPut httpPut = new HttpPut(url); httpPut.setHeader(CONTENT_TYPE, APPLICATION_JSON); StringEntity jsonEntity = null; if (requestBody != null) { jsonEntity = new StringEntity(requestBody); } httpPut.setEntity(jsonEntity); HttpResponse httpresponse = client.execute(httpPut); if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse.getEntity()); } else { if(AuthManager.getToken()!=null){ String accessToken = AuthManager.getToken(); if(!Strings.isNullOrEmpty(accessToken)) { httpPut.setHeader(PacmanSdkConstants.AUTH_HEADER, "Bearer " + accessToken); } } httpPut.setEntity(jsonEntity); HttpResponse httpresponse1 = client.execute(httpPut); if (httpresponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse1.getEntity()); } else { throw new Exception( "unable to execute put request caused by" + EntityUtils.toString(httpresponse1.getEntity())); } } } catch (ParseException parseException) { LOGGER.error("ParseException in getHttpPut :" + parseException.getMessage()); } catch (IOException ioException) { LOGGER.error("IOException in getHttpPut :" + ioException.getMessage()); } return null; }  }
CommonUtils { public static String doHttpPut(final String url, final String requestBody) throws Exception { try { HttpClient client = HttpClientBuilder.create().build(); HttpPut httpPut = new HttpPut(url); httpPut.setHeader(CONTENT_TYPE, APPLICATION_JSON); StringEntity jsonEntity = null; if (requestBody != null) { jsonEntity = new StringEntity(requestBody); } httpPut.setEntity(jsonEntity); HttpResponse httpresponse = client.execute(httpPut); if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse.getEntity()); } else { if(AuthManager.getToken()!=null){ String accessToken = AuthManager.getToken(); if(!Strings.isNullOrEmpty(accessToken)) { httpPut.setHeader(PacmanSdkConstants.AUTH_HEADER, "Bearer " + accessToken); } } httpPut.setEntity(jsonEntity); HttpResponse httpresponse1 = client.execute(httpPut); if (httpresponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse1.getEntity()); } else { throw new Exception( "unable to execute put request caused by" + EntityUtils.toString(httpresponse1.getEntity())); } } } catch (ParseException parseException) { LOGGER.error("ParseException in getHttpPut :" + parseException.getMessage()); } catch (IOException ioException) { LOGGER.error("IOException in getHttpPut :" + ioException.getMessage()); } return null; }  static Boolean isEnvVariableExists(String envVariableName); static String getEnvVariableValue(String envVariableName); static String doHttpPost(final String url,  String requestBody); static String doHttpPut(final String url, final String requestBody); static boolean isValidResource(String esUrl); static Object buildQueryForExistingIssues(Map<String, Object> filter); static String getIndexNameFromRuleParam(Map<String, String> ruleParam); @SuppressWarnings("unchecked") static Map<String, String> flatNestedMap(String notation, Map<String, Object> nestedMap); static String getUniqueAnnotationId(Annotation annotation); static String getUniqueAnnotationId(String parentId, String ruleId); static String getUniqueIdForString(String inStr); static String hash(String s); static Map<String, String> createParamMap(String ruleParams); static String decrypt(String encryptedText); static Map<String, String> buildMapFromString(String input, String splitOn, String keyValueSeparator); static Long getElapseTimeSince(long startTime); static String getCurrentDateStringWithFormat(String timeZone, String format); static Date getDateFromString(final String dateInString, final String format); static Date dateFormat(final String dateInString, String formatFrom, String formatTo); static int compareDate(final Date firstDate, final Date lastDate); static boolean resourceCreatedBeforeCutoffData(final Date resourceCreationDate); static String doHttpPost(final String url, final String requestBody, final Map<String, String> headers); static String doHttpGet(final String url); static SSLContext createNoSSLContext(); static String getJsonString(final Object annotation); static String encryptB64(String plainText); static String decryptB64(String text); static String encrypt(String plainText, final String key); static String decrypt(String encryptedText, final String key); static String getPropValue(final String keyname); static String getTemplateContent(final String templateName); static String serializeToString(Object object); static Object deSerializeToObject(String jsonString); static Boolean doesAllHaveValue(String...strings ); }
CommonUtils { public static String doHttpPut(final String url, final String requestBody) throws Exception { try { HttpClient client = HttpClientBuilder.create().build(); HttpPut httpPut = new HttpPut(url); httpPut.setHeader(CONTENT_TYPE, APPLICATION_JSON); StringEntity jsonEntity = null; if (requestBody != null) { jsonEntity = new StringEntity(requestBody); } httpPut.setEntity(jsonEntity); HttpResponse httpresponse = client.execute(httpPut); if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse.getEntity()); } else { if(AuthManager.getToken()!=null){ String accessToken = AuthManager.getToken(); if(!Strings.isNullOrEmpty(accessToken)) { httpPut.setHeader(PacmanSdkConstants.AUTH_HEADER, "Bearer " + accessToken); } } httpPut.setEntity(jsonEntity); HttpResponse httpresponse1 = client.execute(httpPut); if (httpresponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toString(httpresponse1.getEntity()); } else { throw new Exception( "unable to execute put request caused by" + EntityUtils.toString(httpresponse1.getEntity())); } } } catch (ParseException parseException) { LOGGER.error("ParseException in getHttpPut :" + parseException.getMessage()); } catch (IOException ioException) { LOGGER.error("IOException in getHttpPut :" + ioException.getMessage()); } return null; }  static Boolean isEnvVariableExists(String envVariableName); static String getEnvVariableValue(String envVariableName); static String doHttpPost(final String url,  String requestBody); static String doHttpPut(final String url, final String requestBody); static boolean isValidResource(String esUrl); static Object buildQueryForExistingIssues(Map<String, Object> filter); static String getIndexNameFromRuleParam(Map<String, String> ruleParam); @SuppressWarnings("unchecked") static Map<String, String> flatNestedMap(String notation, Map<String, Object> nestedMap); static String getUniqueAnnotationId(Annotation annotation); static String getUniqueAnnotationId(String parentId, String ruleId); static String getUniqueIdForString(String inStr); static String hash(String s); static Map<String, String> createParamMap(String ruleParams); static String decrypt(String encryptedText); static Map<String, String> buildMapFromString(String input, String splitOn, String keyValueSeparator); static Long getElapseTimeSince(long startTime); static String getCurrentDateStringWithFormat(String timeZone, String format); static Date getDateFromString(final String dateInString, final String format); static Date dateFormat(final String dateInString, String formatFrom, String formatTo); static int compareDate(final Date firstDate, final Date lastDate); static boolean resourceCreatedBeforeCutoffData(final Date resourceCreationDate); static String doHttpPost(final String url, final String requestBody, final Map<String, String> headers); static String doHttpGet(final String url); static SSLContext createNoSSLContext(); static String getJsonString(final Object annotation); static String encryptB64(String plainText); static String decryptB64(String text); static String encrypt(String plainText, final String key); static String decrypt(String encryptedText, final String key); static String getPropValue(final String keyname); static String getTemplateContent(final String templateName); static String serializeToString(Object object); static Object deSerializeToObject(String jsonString); static Boolean doesAllHaveValue(String...strings );  }