Java Code Examples for org.apache.http.client.methods.HttpPatch#setHeader()
The following examples show how to use
org.apache.http.client.methods.HttpPatch#setHeader() .
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 |
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: ODataTestUtils.java From product-ei with Apache License 2.0 | 6 votes |
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 3
Source File: ODataSuperTenantUserTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
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 4
Source File: ODataTenantUserTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
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: AbstractDatabricksRestClientImpl.java From databricks-rest-client with Apache License 2.0 | 5 votes |
protected HttpPatch makePatchMethod(String path, Map<String, Object> data) throws UnsupportedEncodingException, JsonProcessingException { HttpPatch method = new HttpPatch(url + path); logger.info(method.toString()); StringEntity requestEntity = makeStringRequestEntity(data); method.setEntity(requestEntity); method.setHeader("Accept", "application/json"); method.setHeader("Content-type", "application/json"); return method; }
Example 6
Source File: HttpUtils.java From jmeter-bzm-plugins with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: HttpUtil.java From sunbird-lms-service with MIT License | 5 votes |
/** * Set the header for request. * * @param httpPatch HttpURLConnection * @param headers Map<String,String> */ private static void setHeaders(HttpPatch httpPatch, Map<String, String> headers) { Iterator<Entry<String, String>> itr = headers.entrySet().iterator(); while (itr.hasNext()) { Entry<String, String> entry = itr.next(); httpPatch.setHeader(entry.getKey(), entry.getValue()); } }
Example 8
Source File: ODataSuperTenantUserTestCase.java From product-ei with Apache License 2.0 | 5 votes |
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 9
Source File: ODataTenantUserTestCase.java From product-ei with Apache License 2.0 | 5 votes |
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 10
Source File: RequestContentTypeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void unsupportedContentTypeParameter() throws Exception { HttpPatch patch = new HttpPatch(URI.create(getEndpoint().toString() + "Rooms('1')")); patch.setHeader(HttpHeaders.CONTENT_TYPE, HttpContentType.APPLICATION_JSON + ";illegal=wrong"); final HttpResponse response = getHttpClient().execute(patch); assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), response.getStatusLine().getStatusCode()); }
Example 11
Source File: BrocadeVcsApi.java From cloudstack with Apache License 2.0 | 5 votes |
protected <T> boolean executeUpdateObject(T newObject, String uri) throws BrocadeVcsApiException { final boolean result = true; if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) { throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } final HttpPatch pm = (HttpPatch)createMethod("patch", uri); pm.setHeader("Accept", "application/vnd.configuration.resource+xml"); pm.setEntity(new StringEntity(convertToString(newObject), ContentType.APPLICATION_XML)); final HttpResponse response = executeMethod(pm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { s_logger.error("Failed to update object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage()); } pm.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new BrocadeVcsApiException("Failed to update object : " + errorMessage); } pm.releaseConnection(); return result; }
Example 12
Source File: RequestContentTypeTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void unsupportedContentTypeParameter() throws Exception { HttpPatch patch = new HttpPatch(URI.create(getEndpoint().toString() + "Rooms('1')")); patch.setHeader(HttpHeaders.CONTENT_TYPE, HttpContentType.APPLICATION_JSON + ";illegal=wrong"); final HttpResponse response = getHttpClient().execute(patch); assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), response.getStatusLine().getStatusCode()); }
Example 13
Source File: SpringBreakCve20178046.java From java-examples with MIT License | 4 votes |
/** * 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 14
Source File: ZephyrHttpClient.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
@Override public void setHeader(HttpPatch httppatch) { httppatch.setHeader("Authorization", "Basic " + TOKEN); httppatch.setHeader("Content-Type", "application/json"); }
Example 15
Source File: VStsHttpClient.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
@Override public void setHeader(HttpPatch httppatch) { httppatch.setHeader("Authorization", "Basic " + encodedToken); httppatch.setHeader("Content-Type", "application/json"); }