HttpClientStack implements HttpStack { @SuppressWarnings("deprecation") static HttpUriRequest createHttpRequest( Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader( HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } } HttpClientStack(HttpClient client); @Override HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders);  }
@Test public void createDeprecatedGetRequest() throws Exception { TestRequest.DeprecatedGet request = new TestRequest.DeprecatedGet(); assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpGet); }
@Test public void createDeprecatedPostRequest() throws Exception { TestRequest.DeprecatedPost request = new TestRequest.DeprecatedPost(); assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPost); }
@Test public void createGetRequest() throws Exception { TestRequest.Get request = new TestRequest.Get(); assertEquals(request.getMethod(), Method.GET); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpGet); }
@Test public void createPostRequest() throws Exception { TestRequest.Post request = new TestRequest.Post(); assertEquals(request.getMethod(), Method.POST); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPost); }
@Test public void createPostRequestWithBody() throws Exception { TestRequest.PostWithBody request = new TestRequest.PostWithBody(); assertEquals(request.getMethod(), Method.POST); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPost); }
@Test public void createPutRequest() throws Exception { TestRequest.Put request = new TestRequest.Put(); assertEquals(request.getMethod(), Method.PUT); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPut); }
@Test public void createPutRequestWithBody() throws Exception { TestRequest.PutWithBody request = new TestRequest.PutWithBody(); assertEquals(request.getMethod(), Method.PUT); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPut); }
@Test public void createDeleteRequest() throws Exception { TestRequest.Delete request = new TestRequest.Delete(); assertEquals(request.getMethod(), Method.DELETE); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpDelete); }
@Test public void createHeadRequest() throws Exception { TestRequest.Head request = new TestRequest.Head(); assertEquals(request.getMethod(), Method.HEAD); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpHead); }
@Test public void createOptionsRequest() throws Exception { TestRequest.Options request = new TestRequest.Options(); assertEquals(request.getMethod(), Method.OPTIONS); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpOptions); }
@Test public void createTraceRequest() throws Exception { TestRequest.Trace request = new TestRequest.Trace(); assertEquals(request.getMethod(), Method.TRACE); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpTrace); }
@Test public void createPatchRequest() throws Exception { TestRequest.Patch request = new TestRequest.Patch(); assertEquals(request.getMethod(), Method.PATCH); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPatch); }
@Test public void createPatchRequestWithBody() throws Exception { TestRequest.PatchWithBody request = new TestRequest.PatchWithBody(); assertEquals(request.getMethod(), Method.PATCH); HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); assertTrue(httpRequest instanceof HttpPatch); }