List of usage examples for org.apache.http.client.methods HttpUriRequest getMethod
String getMethod();
From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java
@Test public void state() { HttpUriRequest request = builder.createRequest("state", "depId"); assertCommonParts(request);//from w ww. ja va2 s .c o m assertEquals("GET", request.getMethod()); assertEquals("/dcc/depId/state", request.getURI().getPath()); }
From source file:org.ecloudmanager.tmrk.cloudapi.CloudapiRequestAuhtorization.java
private String signature(HttpUriRequest request, String apiPrivateKey) { StringBuilder sb = new StringBuilder(); String verb = request.getMethod().toUpperCase(); String date = request.getFirstHeader(HttpHeaderNames.DATE).getValue(); Header contentTypeHeader = request.getFirstHeader(HttpHeaderNames.CONTENT_TYPE); String contentType = contentTypeHeader != null ? contentTypeHeader.getValue() : null; Header contentLengthHeader = request.getFirstHeader(HttpHeaderNames.CONTENT_LENGTH); String contentLength = contentLengthHeader != null ? contentLengthHeader.getValue() : null; sb.append(verb).append("\n"); sb.append(contentLength != null ? contentLength.trim() : "").append("\n"); sb.append(contentType != null ? contentType.trim() : "").append("\n"); sb.append(date).append("\n"); HeaderIterator hit = request.headerIterator(); Headers<Object> headers = new Headers<>(); while (hit.hasNext()) { Header hdr = hit.nextHeader();/*from w ww. j a v a 2 s. c o m*/ headers.add(hdr.getName(), hdr.getValue()); } sb.append(canonicalizedHeaders(headers)); sb.append(canonicalizedResource(new ResteasyUriInfo(request.getURI()))); String sigstr = sb.toString(); try { Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(getBytes(apiPrivateKey), "HmacSHA256"); sha256_HMAC.init(secret_key); return Base64.encodeBytes(sha256_HMAC.doFinal(getBytes(sigstr))); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java
@Test public void logs() { HttpUriRequest request = builder.createRequest("logs/logId", null); assertCommonParts(request);//from ww w .j a v a 2 s .co m assertEquals("GET", request.getMethod()); assertEquals("/dcc/logs/logId", request.getURI().getPath()); }
From source file:com.louding.frame.http.download.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // ??//from w w w . j a v a2s . c om boolean retry = true; // ? Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // ???? retry = false; } else if (isInList(exceptionBlacklist, exception)) { // ?????? retry = false; } else if (isInList(exceptionWhitelist, exception)) { // ???? retry = true; } else if (!sent) { // ????? retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:org.fcrepo.integration.SanityCheckIT.java
private HttpResponse executeAndVerify(final HttpUriRequest method, final int statusCode) throws IOException { logger.debug("Executing: " + method.getMethod() + " to " + method.getURI()); final HttpResponse response = client.execute(method); assertEquals(statusCode, response.getStatusLine().getStatusCode()); return response; }
From source file:com.vmware.photon.controller.nsxclient.RestClientTest.java
@Test public void testPerformPut() { String payload = "{name: DUMMY}"; ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.PUT, new StringEntity(payload, ContentType.APPLICATION_JSON)); HttpUriRequest request = argumentCaptor.getValue(); assertNotNull(request);//from w w w . jav a 2 s. c o m assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.PUT.toString())); assertEquals(request.getURI().toString(), target + path); HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request; String actualPayload = null; try { actualPayload = IOUtils.toString(httpEntityEnclosingRequest.getEntity().getContent()); } catch (IOException e) { fail(e.getMessage()); } assertEquals(actualPayload, payload); }
From source file:com.vmware.photon.controller.nsxclient.RestClientTest.java
@Test public void testPerformPost() { String payload = "{name: DUMMY}"; ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.POST, new StringEntity(payload, ContentType.APPLICATION_JSON)); HttpUriRequest request = argumentCaptor.getValue(); assertNotNull(request);/*from w ww . jav a 2 s .c o m*/ assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.POST.toString())); assertEquals(request.getURI().toString(), target + path); HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request; String actualPayload = null; try { actualPayload = IOUtils.toString(httpEntityEnclosingRequest.getEntity().getContent()); } catch (IOException e) { fail(e.getMessage()); } assertEquals(actualPayload, payload); }
From source file:com.lurencun.cfuture09.androidkit.http.async.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // ??// www . j a v a2 s .c o m boolean retry = true; // ? Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // ???? retry = false; } else if (isInList(exceptionBlacklist, exception)) { // ?????? retry = false; } else if (isInList(exceptionWhitelist, exception)) { // ???? retry = true; } else if (!sent) { // ????? retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); log.w(exception); } return retry; }