Java Code Examples for org.apache.http.client.methods.HttpPatch#setEntity()

The following examples show how to use org.apache.http.client.methods.HttpPatch#setEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataTestUtils.java    From micro-integrator with Apache License 2.0 7 votes vote down vote up
public static int sendPATCH(String endpoint, String content, Map<String, String> headers) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPatch httpPatch = new HttpPatch(endpoint);
    for (String headerType : headers.keySet()) {
        httpPatch.setHeader(headerType, headers.get(headerType));
    }
    if (null != content) {
        HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
        if (headers.get("Content-Type") == null) {
            httpPatch.setHeader("Content-Type", "application/json");
        }
        httpPatch.setEntity(httpEntity);
    }
    HttpResponse httpResponse = httpClient.execute(httpPatch);
    return httpResponse.getStatusLine().getStatusCode();
}
 
Example 2
Source File: BulkV2Connection.java    From components with Apache License 2.0 6 votes vote down vote up
public JobInfoV2 updateJob(String jobId, JobStateEnum state) throws BulkV2ClientException {
    String endpoint = getRestEndpoint();
    endpoint += "jobs/ingest/" + jobId;
    UpdateJobRequest request = new UpdateJobRequest.Builder(state).build();
    try {
        HttpPatch httpPatch = (HttpPatch) createRequest(endpoint, HttpMethod.PATCH);
        StringEntity entity = new StringEntity(serializeToJson(request), ContentType.APPLICATION_JSON);

        httpPatch.setEntity(entity);
        HttpResponse response = httpclient.execute(httpPatch);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new BulkV2ClientException(response.getStatusLine().getReasonPhrase());
        }
        HttpEntity responseEntity = response.getEntity();
        if (responseEntity != null) {
            return deserializeJsonToObject(responseEntity.getContent(), JobInfoV2.class);
        } else {
            throw new IOException(MESSAGES.getMessage("error.job.info"));
        }
    } catch (BulkV2ClientException bec) {
        throw bec;
    } catch (IOException e) {
        throw new BulkV2ClientException(MESSAGES.getMessage("error.query.job"), e);
    }
}
 
Example 3
Source File: ServerFrontendITest.java    From ldp4j with Apache License 2.0 6 votes vote down vote up
@Test
@Category({
	ExceptionPath.class
})
@OperateOnDeployment(DEPLOYMENT)
public void testNoPatchSupport(@ArquillianResource final URL url) throws Exception {
	LOGGER.info("Started {}",testName.getMethodName());
	HELPER.base(url);
	HELPER.setLegacy(false);

	HttpPatch patch = HELPER.newRequest(MyApplication.ROOT_PERSON_CONTAINER_PATH,HttpPatch.class);
	patch.setEntity(
		new StringEntity(
			TEST_SUITE_BODY,
			ContentType.create("text/turtle", "UTF-8"))
	);
	Metadata patchResponse=HELPER.httpRequest(patch);
	assertThat(patchResponse.status,equalTo(HttpStatus.SC_METHOD_NOT_ALLOWED));
	assertThat(patchResponse.body,notNullValue());
	assertThat(patchResponse.contentType,startsWith("text/plain"));
	assertThat(patchResponse.language,equalTo(Locale.ENGLISH));
}
 
Example 4
Source File: ODataSuperTenantUserTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPatch httpPatch = new HttpPatch(endpoint);
    httpPatch.setHeader("Accept", acceptType);
    if (null != content) {
        HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
        httpPatch.setHeader("Content-Type", "application/json");
        httpPatch.setEntity(httpEntity);
    }
    HttpResponse httpResponse = httpClient.execute(httpPatch);
    return httpResponse.getStatusLine().getStatusCode();
}
 
Example 5
Source File: ODataTenantUserTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPatch httpPatch = new HttpPatch(endpoint);
    httpPatch.setHeader("Accept", acceptType);
    if (null != content) {
        HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
        httpPatch.setHeader("Content-Type", "application/json");
        httpPatch.setEntity(httpEntity);
    }
    HttpResponse httpResponse = httpClient.execute(httpPatch);
    return httpResponse.getStatusLine().getStatusCode();
}
 
Example 6
Source File: GitHubPullRequestCreator.java    From apicurio-studio with Apache License 2.0 5 votes vote down vote up
/**
 * Updates a branch reference to point it at the new commit.
 * @param branchRef
 * @param commit
 */
private GitHubBranchReference updateBranchRef(GitHubBranchReference branchRef, GitHubCommit commit) throws GitHubException {
    String bref = branchRef.getRef();
    if (bref.startsWith("refs/")) {
        bref = bref.substring(5);
    }
    String url = this.endpoint("/repos/:owner/:repo/git/refs/:ref")
            .bind("owner", this.organization)
            .bind("repo", this.repository)
            .bind("ref", bref)
            .toString();
    
    GitHubUpdateReference requestBody = new GitHubUpdateReference();
    requestBody.setSha(commit.getSha());
    
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpPatch request = new HttpPatch(url);
        request.setEntity(new StringEntity(mapper.writeValueAsString(requestBody)));
        request.addHeader("Content-Type", "application/json");
        request.addHeader("Accept", "application/json");
        addSecurityTo(request);

        try (CloseableHttpResponse response = httpClient.execute(request)) {
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new IOException("Invalid response code: " + response.getStatusLine().getStatusCode() + " :: " + response.getStatusLine().getReasonPhrase());
            }
            try (InputStream contentStream = response.getEntity().getContent()) {
                GitHubBranchReference ref = mapper.readValue(contentStream, GitHubBranchReference.class);
                ref.setName(branchRef.getName());
                return ref;
            }
        }
    } catch (IOException e) {
        throw new GitHubException("Error creating a GH commit.", e);
    }
}
 
Example 7
Source File: HttpUtils.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Create Patch Request
 */
public HttpPatch createPatch(String url, JSON data) {
    HttpPatch patch = new HttpPatch(url);
    patch.setHeader("Content-Type", "application/json");

    String string = data.toString(1);
    try {
        patch.setEntity(new StringEntity(string, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return patch;
}
 
Example 8
Source File: DigitalOceanClient.java    From digitalocean-api-java with MIT License 5 votes vote down vote up
private String doPatch(URI uri, HttpEntity entity)
    throws DigitalOceanException, RequestUnsuccessfulException {
  HttpPatch patch = new HttpPatch(uri);
  patch.setHeaders(requestHeaders);

  if (null != entity) {
    patch.setEntity(entity);
  }

  return executeHttpRequest(patch);
}
 
Example 9
Source File: ConfigServerRestExecutorImpl.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static HttpRequestBase createHttpBaseRequest(Method method, URI url, InputStream data) {
    switch (method) {
        case GET:
            return new HttpGet(url);
        case POST:
            HttpPost post = new HttpPost(url);
            if (data != null) {
                post.setEntity(new InputStreamEntity(data));
            }
            return post;
        case PUT:
            HttpPut put = new HttpPut(url);
            if (data != null) {
                put.setEntity(new InputStreamEntity(data));
            }
            return put;
        case DELETE:
            return new HttpDelete(url);
        case PATCH:
            HttpPatch patch = new HttpPatch(url);
            if (data != null) {
                patch.setEntity(new InputStreamEntity(data));
            }
            return patch;
    }
    throw new IllegalArgumentException("Refusing to proxy " + method + " " + url + ": Unsupported method");
}
 
Example 10
Source File: RestEndPointMockerTest.java    From zerocode with Apache License 2.0 5 votes vote down vote up
@Test
public void willMockAPATCHRequest() throws Exception {

    final MockStep mockPatch = mockSteps.getMocks().get(2);
    String jsonBodyResponse = mockPatch.getResponse().get("body").toString(); // { "id": "cust345", "message": "email updated"  }

    final String bodyJson = mockPatch.getRequest().get("body").toString(); // { "email": "[email protected]" }
    stubFor(patch(urlEqualTo(mockPatch.getUrl()))
            .withRequestBody(equalToJson(bodyJson))
            .willReturn(aResponse()
                    .withStatus(mockPatch.getResponse().get("status").asInt())
                    .withHeader("Content-Type", APPLICATION_JSON)
                    .withBody(jsonBodyResponse)));

    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPatch request = new HttpPatch("http://localhost:9073" + mockPatch.getUrl());
    request.addHeader("Content-Type", "application/json");
    StringEntity entity = new StringEntity(bodyJson);
    request.setEntity(entity);
    HttpResponse response = httpClient.execute(request);

    final String responseBodyActual = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
    System.out.println("### response: \n" + responseBodyActual);

    assertThat(response.getStatusLine().getStatusCode(), is(200));
    JSONAssert.assertEquals(jsonBodyResponse, responseBodyActual, true);

}
 
Example 11
Source File: ODataTenantUserTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException {
	HttpClient httpClient = new DefaultHttpClient();
	HttpPatch httpPatch = new HttpPatch(endpoint);
	httpPatch.setHeader("Accept", acceptType);
	if (null != content) {
		HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
		httpPatch.setHeader("Content-Type", "application/json");
		httpPatch.setEntity(httpEntity);
	}
	HttpResponse httpResponse = httpClient.execute(httpPatch);
	return httpResponse.getStatusLine().getStatusCode();
}
 
Example 12
Source File: RestExecutor.java    From rest-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Executes PATCH req and returns response json.
 * 
 * @param path
 * @param headers
 * @param xmlContent
 * @param contentType
 * @return
 */
public RestValidator patch(String path, HashMap<String, String> headers, String xmlContent, String contentType) {
	HttpPatch post = new HttpPatch(url + path);
	RestResponse resResponse = new RestResponse();
	StringBuffer responseString = new StringBuffer();
	try {
		if (headers != null)
			post.setEntity(getEntities(headers));

		StringEntity input = new StringEntity(xmlContent);
		input.setContentType(contentType);
		post.setEntity(input);

		HttpResponse response = client.execute(post);
		BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
		String line = "";
		while ((line = rd.readLine()) != null) {
			responseString.append(line);
		}
		resResponse.setResponseBody(responseString.toString());
		resResponse.setResponseCode(response.getStatusLine().getStatusCode());
		resResponse.setResponseMessage(response.getStatusLine().getReasonPhrase());
		Header[] rheaders = response.getAllHeaders();
		for (Header header : rheaders) {
			resResponse.setHeader(header.getName(), header.getValue());
		}
	} catch (Exception e) {
		e.printStackTrace(); // handle
	}
	return new RestValidator(resResponse);
}
 
Example 13
Source File: HttpSBControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int patch(DeviceId device, String request, InputStream payload, MediaType mediaType) {

    try {
        log.debug("Url request {} ", getUrlString(device, request));
        HttpPatch httprequest = new HttpPatch(getUrlString(device, request));
        if (deviceMap.get(device).authentication() == AuthenticationScheme.BASIC) {
            String pwd = deviceMap.get(device).password() == null ? "" : COLON + deviceMap.get(device).password();
            String userPassword = deviceMap.get(device).username() + pwd;
            String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8));
            httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string);
        } else if (deviceMap.get(device).authentication() == AuthenticationScheme.OAUTH2) {
            String token = deviceMap.get(device).token();
            // TODO: support token types other then bearer of OAuth2 authentication
            httprequest.addHeader(AUTHORIZATION_PROPERTY, OAUTH2_BEARER_AUTH_PREFIX + token);
        }
        if (payload != null) {
            StringEntity input = new StringEntity(IOUtils.toString(payload, StandardCharsets.UTF_8));
            input.setContentType(mediaType.toString());
            httprequest.setEntity(input);
        }
        CloseableHttpClient httpClient;
        if (deviceMap.containsKey(device) && deviceMap.get(device).protocol().equals(HTTPS)) {
            httpClient = getApacheSslBypassClient();
        } else {
            httpClient = HttpClients.createDefault();
        }
        return httpClient.execute(httprequest).getStatusLine().getStatusCode();
    } catch (IOException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        log.error("Cannot do PATCH {} request on device {}", request, device, e);
    }
    return Status.BAD_REQUEST.getStatusCode();
}
 
Example 14
Source File: ODataSuperTenantUserTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException {
	HttpClient httpClient = new DefaultHttpClient();
	HttpPatch httpPatch = new HttpPatch(endpoint);
	httpPatch.setHeader("Accept", acceptType);
	if (null != content) {
		HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
		httpPatch.setHeader("Content-Type", "application/json");
		httpPatch.setEntity(httpEntity);
	}
	HttpResponse httpResponse = httpClient.execute(httpPatch);
	return httpResponse.getStatusLine().getStatusCode();
}
 
Example 15
Source File: SpringBreakCve20178046.java    From java-examples with MIT License 4 votes vote down vote up
/**
 * HTTP PATCH operation on the target passing the malicious payload.
 *
 * @param payload
 *            The malicious payload.
 * @return The response as a string.
 * @throws IOException
 *             If something bad occurs during HTTP GET.
 */
private String httpPatch(String payload) throws IOException {
    System.out.println("[*] Sending payload.");

    // Preparing PATCH operation.
    HttpClient client = HttpClientBuilder.create().build();
    HttpPatch patch = new HttpPatch(this.url);
    patch.setHeader("User-Agent", "Mozilla/5.0");
    patch.setHeader("Accept-Language", "en-US,en;q=0.5");
    patch.setHeader("Content-Type", "application/json-patch+json"); // This is a JSON Patch.
    if (!isEmpty(this.cookies)) {
        patch.setHeader("Cookie", this.cookies);
    }
    System.out.println(new StringEntity(payload));
    patch.setEntity(new StringEntity(payload));

    // Response string.
    StringBuffer response = new StringBuffer();

    // Executing PATCH operation.
    HttpResponse httpResponse = client.execute(patch);
    if (httpResponse != null) {

        // Reading response code.
        if (httpResponse.getStatusLine() != null) {
            int responseCode = httpResponse.getStatusLine().getStatusCode();
            System.out.println("[*] HTTP " + responseCode);
        } else {
            System.out.println("[!] HTTP response code can't be read.");
        }

        // Reading response content.
        if (httpResponse.getEntity() != null && httpResponse.getEntity().getContent() != null) {
            BufferedReader in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
                response.append(System.getProperty("line.separator"));
            }
            in.close();
        } else {
            System.out.println("[!] HTTP response content can't be read.");
        }

    } else {
        System.out.println("[!] HTTP response is null.");
    }

    return response.toString();
}
 
Example 16
Source File: BasicHttpClient.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public void setPatchEntity(String jsonStr, HttpPatch httppatch) throws UnsupportedEncodingException {
    StringEntity input = new StringEntity(jsonStr);
    input.setContentType("application/json");
    httppatch.setEntity(input);
}
 
Example 17
Source File: RestFidoActionsOnPolicy.java    From fido2 with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void patch(String REST_URI,
                        String did,
                        String accesskey,
                        String secretkey,
                        String sidpid,
                        Long startdate,
                        Long enddate,
                        Integer version,
                        String status,
                        String notes,
                        String policy) throws Exception
{
    System.out.println("Patch policy test");
    System.out.println("******************************************");

    String apiversion = "2.0";

    //  Make API rest call and get response from the server
    String resourceLoc = REST_URI + Constants.REST_SUFFIX + did + Constants.PATCH_POLICY_ENDPOINT + "/" + sidpid;
    System.out.println("\nCalling update @ " + resourceLoc);

    PatchFidoPolicyRequest pfpr = new PatchFidoPolicyRequest();
    pfpr.setStartDate(startdate);
    if (enddate != null)
        pfpr.setEndDate(enddate);
    pfpr.setVersion(version);
    pfpr.setStatus(status);
    pfpr.setNotes(notes);
    pfpr.setPolicy(policy);

    ObjectWriter ow = new ObjectMapper().writer();
    String json = ow.writeValueAsString(pfpr);

    ContentType mimetype = ContentType.create("application/merge-patch+json");
    StringEntity body = new StringEntity(json, mimetype);

    String currentDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z").format(new Date());
    String contentSHA = common.calculateSha256(json);

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPatch httpPatch = new HttpPatch(resourceLoc);
    httpPatch.setEntity(body);
    String requestToHmac = httpPatch.getMethod() + "\n"
            + contentSHA + "\n"
            + mimetype.getMimeType() + "\n"
            + currentDate + "\n"
            + apiversion + "\n"
            + httpPatch.getURI().getPath();

    String hmac = common.calculateHMAC(secretkey, requestToHmac);
    httpPatch.addHeader("Authorization", "HMAC " + accesskey + ":" + hmac);
    httpPatch.addHeader("strongkey-content-sha256", contentSHA);
    httpPatch.addHeader("Content-Type", mimetype.getMimeType());
    httpPatch.addHeader("Date", currentDate);
    httpPatch.addHeader("strongkey-api-version", apiversion);
    CloseableHttpResponse response = httpclient.execute(httpPatch);
    String result;
    try {
        StatusLine responseStatusLine = response.getStatusLine();
        HttpEntity entity = response.getEntity();
        result = EntityUtils.toString(entity);
        EntityUtils.consume(entity);

        switch (responseStatusLine.getStatusCode()) {
            case 200:
                break;
            case 401:
                System.out.println("Error during patch fido policy : 401 HMAC Authentication Failed");
                return;
            case 404:
                System.out.println("Error during patch fido policy : 404 Resource not found");
                return;
            case 400:
            case 500:
            default:
                System.out.println("Error during patch fido policy : " + responseStatusLine.getStatusCode() + " " + result);
                return;
        }

    } finally {
        response.close();
    }

    System.out.println(" Response : " + result);

    System.out.println("\nPatch policy test complete.");
    System.out.println("******************************************");
}
 
Example 18
Source File: HttpUtil.java    From sunbird-lms-service with MIT License 4 votes vote down vote up
/**
 * @description this method will send the patch request and in response it will return Map of
 *     status code with patch method response in String format
 * @param requestURL
 * @param params
 * @param headers (Map<String,String>)
 * @return HttpUtilResponse
 * @throws IOException
 */
public static HttpUtilResponse doPatchRequest(
    String requestURL, String params, Map<String, String> headers) throws IOException {
  long startTime = System.currentTimeMillis();
  Map<String, Object> logInfo = genarateLogInfo(JsonKey.API_CALL, "API CALL : " + requestURL);
  ProjectLogger.log(
      "HttpUtil sendPatchRequest method started at =="
          + startTime
          + " for requestURL "
          + requestURL,
      LoggerEnum.PERF_LOG);

  HttpPatch patch = new HttpPatch(requestURL);
  setHeaders(patch, headers);
  StringEntity entity = new StringEntity(params);
  patch.setEntity(entity);
  try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
    ProjectLogger.log("response code for Patch Resques");
    HttpResponse httpResponse = httpClient.execute(patch);
    HttpUtilResponse response = null;
    String body = "";
    try {
      body = generateResponse(httpResponse);
    } catch (Exception ex) {
      ProjectLogger.log("Exception occurred while reading body" + ex);
    }
    response = new HttpUtilResponse(body, httpResponse.getStatusLine().getStatusCode());
    long stopTime = System.currentTimeMillis();
    long elapsedTime = stopTime - startTime;
    ProjectLogger.log(
        "HttpUtil doPatchRequest method end at =="
            + stopTime
            + " for requestURL "
            + requestURL
            + " ,Total time elapsed = "
            + elapsedTime,
        LoggerEnum.PERF_LOG);
    //            telemetryProcessingCall(logInfo);
    return response;
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    throw e;
  }
}
 
Example 19
Source File: ServiceNowExecution.java    From service-now-plugin with MIT License 4 votes vote down vote up
public CloseableHttpResponse updateChange() throws IOException {
    HttpPatch requestBase = new HttpPatch(serviceNowConfiguration.getPatchUrl(serviceNowItem));
    setJsonContentType(requestBase);
    requestBase.setEntity(buildEntity(serviceNowItem.getBody()));
    return sendRequest(requestBase);
}
 
Example 20
Source File: RestFidoActionsOnPolicy.java    From fido2 with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void patch(String REST_URI,
                        String did,
                        String accesskey,
                        String secretkey,
                        String sidpid,
                        Long startdate,
                        Long enddate,
                        Integer version,
                        String status,
                        String notes,
                        String policy) throws Exception
{
    System.out.println("Patch policy test");
    System.out.println("******************************************");

    String apiversion = "2.0";

    //  Make API rest call and get response from the server
    String resourceLoc = REST_URI + Constants.REST_SUFFIX + did + Constants.PATCH_POLICY_ENDPOINT + "/" + sidpid;
    System.out.println("\nCalling update @ " + resourceLoc);

    PatchFidoPolicyRequest pfpr = new PatchFidoPolicyRequest();
    pfpr.setStartDate(startdate);
    if (enddate != null)
        pfpr.setEndDate(enddate);
    pfpr.setVersion(version);
    pfpr.setStatus(status);
    pfpr.setNotes(notes);
    pfpr.setPolicy(policy);

    ObjectWriter ow = new ObjectMapper().writer();
    String json = ow.writeValueAsString(pfpr);

    ContentType mimetype = ContentType.create("application/merge-patch+json");
    StringEntity body = new StringEntity(json, mimetype);

    String currentDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z").format(new Date());
    String contentSHA = common.calculateSha256(json);

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPatch httpPatch = new HttpPatch(resourceLoc);
    httpPatch.setEntity(body);
    String requestToHmac = httpPatch.getMethod() + "\n"
            + contentSHA + "\n"
            + mimetype.getMimeType() + "\n"
            + currentDate + "\n"
            + apiversion + "\n"
            + httpPatch.getURI().getPath();

    String hmac = common.calculateHMAC(secretkey, requestToHmac);
    httpPatch.addHeader("Authorization", "HMAC " + accesskey + ":" + hmac);
    httpPatch.addHeader("strongkey-content-sha256", contentSHA);
    httpPatch.addHeader("Content-Type", mimetype.getMimeType());
    httpPatch.addHeader("Date", currentDate);
    httpPatch.addHeader("strongkey-api-version", apiversion);
    CloseableHttpResponse response = httpclient.execute(httpPatch);
    String result;
    try {
        StatusLine responseStatusLine = response.getStatusLine();
        HttpEntity entity = response.getEntity();
        result = EntityUtils.toString(entity);
        EntityUtils.consume(entity);

        switch (responseStatusLine.getStatusCode()) {
            case 200:
                break;
            case 401:
                System.out.println("Error during patch fido policy : 401 HMAC Authentication Failed");
                return;
            case 404:
                System.out.println("Error during patch fido policy : 404 Resource not found");
                return;
            case 400:
            case 500:
            default:
                System.out.println("Error during patch fido policy : " + responseStatusLine.getStatusCode() + " " + result);
                return;
        }

    } finally {
        response.close();
    }

    System.out.println(" Response : " + result);

    System.out.println("\nPatch policy test complete.");
    System.out.println("******************************************");
}