List of usage examples for org.apache.http.message BasicHttpResponse BasicHttpResponse
public BasicHttpResponse(ProtocolVersion protocolVersion, int i, String str)
From source file:com.comcast.cim.rest.client.xhtml.TestXhtmlResponseHandler.java
@Test public void testReturnsNullDocumentWithNoBody() throws Exception { HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_TEMPORARY_REDIRECT, "Temporary Redirect"); resp.setHeader("Location", "http://www.example.com/foo"); XhtmlApplicationState result = impl.handleResponse(resp); Assert.assertNotNull(result);//from w w w . ja v a 2 s .c o m Assert.assertNull(result.getDocument()); Assert.assertSame(resp, result.getHttpResponse()); }
From source file:org.esigate.http.HttpClientRequestExecutorTest.java
private HttpResponse createMockResponse(int statusCode, String entity) throws Exception { HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), statusCode, "OK"); if (entity != null) { HttpEntity httpEntity = new StringEntity(entity); response.setEntity(httpEntity);//from w w w. j a v a2s .com } return response; }
From source file:org.chaplib.TestHttpResource.java
@Test public void nullValueIfNoContent() throws Exception { response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"); when(mockHttpClient.execute(any(HttpUriRequest.class))).thenReturn(response); assertNull(impl.value(mockParser));//from w w w. java2 s.c o m }
From source file:com.amazonaws.http.AmazonHttpClientTest.java
@Test public void testRetryIOExceptionFromHandler() throws Exception { final IOException exception = new IOException("BOOM"); HttpResponseHandler<AmazonWebServiceResponse<Object>> handler = EasyMock .createMock(HttpResponseHandler.class); EasyMock.expect(handler.needsConnectionLeftOpen()).andReturn(false).anyTimes(); EasyMock.expect(handler.handle(EasyMock.<HttpResponse>anyObject())).andThrow(exception).times(4); EasyMock.replay(handler);//from www. ja v a2 s .co m BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); BasicHttpResponse response = new BasicHttpResponse(new ProtocolVersion("http", 1, 1), 200, "OK"); response.setEntity(entity); EasyMock.reset(httpClient); EasyMock.expect(httpClient.getConnectionManager()).andReturn(null).anyTimes(); EasyMock.expect(httpClient.execute(EasyMock.<HttpUriRequest>anyObject(), EasyMock.<HttpContext>anyObject())) .andReturn(response).times(4); EasyMock.replay(httpClient); ExecutionContext context = new ExecutionContext(); Request<?> request = new DefaultRequest<Object>(null, "testsvc"); request.setEndpoint(java.net.URI.create("http://testsvc.region.amazonaws.com")); request.setContent(new java.io.ByteArrayInputStream(new byte[0])); try { client.execute(request, handler, null, context); Assert.fail("No exception when request repeatedly fails!"); } catch (AmazonClientException e) { Assert.assertSame(exception, e.getCause()); } // Verify that we called execute 4 times. EasyMock.verify(httpClient); }
From source file:org.fishwife.jrugged.httpclient.TestFailureExposingHttpClient.java
@Test(expected = UnsuccessfulResponseException.class) public void exposesFailureIfAssessorSaysTo() throws Exception { resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); backend.setResponse(resp);// w ww. j av a 2s . c o m impl = new FailureExposingHttpClient(backend, new ResponseFailureAssessor() { public boolean isFailure(HttpResponse response) { return true; } }); impl.execute(host, req, ctx); }
From source file:com.telefonica.iot.cygnus.backends.ckan.CKANBackendImplTest.java
/** * Sets up tests by creating a unique instance of the tested class, and by defining the behaviour of the mocked * classes.//from ww w .j a va 2s . c om * * @throws Exception */ @Before public void setUp() throws Exception { // set up the instance of the tested class backend = new CKANBackendImpl(apiKey, host, port, orionURL, ssl); // set up the behaviour of the mocked classes when(mockCache.isCachedOrg(orgName)).thenReturn(true); when(mockCache.isCachedPkg(orgName, pkgName)).thenReturn(true); when(mockCache.isCachedRes(orgName, pkgName, resName)).thenReturn(true); when(mockCache.getOrgId(orgName)).thenReturn("org_id"); when(mockCache.getPkgId(pkgName)).thenReturn("pkg_id"); when(mockCache.getResId(resName)).thenReturn("res_id"); BasicHttpResponse response = new BasicHttpResponse(new ProtocolVersion("http", 1, 1), 200, "ok"); response.setEntity(new StringEntity("{\"result\": {\"whatever\":\"whatever\"}}")); when(mockHttpClient.execute(Mockito.any(HttpUriRequest.class))).thenReturn(response); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CachedHttpResponseGenerator.java
/** * Generate a 304 - Not Modified response from a {@link CacheEntry}. This * should be used to respond to conditional requests, when the entry exists * or has been revalidated.//from www . ja v a 2 s .co m * * @param entry * @return */ HttpResponse generateNotModifiedResponse(HttpCacheEntry entry) { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified"); // The response MUST include the following headers // (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) // - Date, unless its omission is required by section 14.8.1 Header dateHeader = entry.getFirstHeader("Date"); if (dateHeader == null) { dateHeader = new BasicHeader("Date", DateUtils.formatDate(new Date())); } response.addHeader(dateHeader); // - ETag and/or Content-Location, if the header would have been sent // in a 200 response to the same request Header etagHeader = entry.getFirstHeader("ETag"); if (etagHeader != null) { response.addHeader(etagHeader); } Header contentLocationHeader = entry.getFirstHeader("Content-Location"); if (contentLocationHeader != null) { response.addHeader(contentLocationHeader); } // - Expires, Cache-Control, and/or Vary, if the field-value might // differ from that sent in any previous response for the same // variant Header expiresHeader = entry.getFirstHeader("Expires"); if (expiresHeader != null) { response.addHeader(expiresHeader); } Header cacheControlHeader = entry.getFirstHeader("Cache-Control"); if (cacheControlHeader != null) { response.addHeader(cacheControlHeader); } Header varyHeader = entry.getFirstHeader("Vary"); if (varyHeader != null) { response.addHeader(varyHeader); } return response; }
From source file:org.paolomoz.zehnkampf.utils.GenHTTPResponse.java
public HttpResponse setCreated(File requestedFile) throws UnsupportedEncodingException { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CREATED, "Created"); HttpEntity entity = getDirectoryEntity(requestedFile); response.setEntity(entity);/*from w ww.ja v a 2 s.c o m*/ return response; }
From source file:org.fishwife.jrugged.httpclient.TestPerHostServiceWrappedHttpClient.java
@Test public void reusesWrapperForRequestsFromSameHost() throws Exception { ServiceWrapper wrapper = new NullWrapper(); HttpUriRequest req1 = new HttpGet("http://foo.example.com/bar"); HttpUriRequest req2 = new HttpGet("http://foo.example.com/baz"); HttpResponse resp1 = resp;//from w w w . j a v a 2 s .c o m HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); expect(mockFactory.getWrapperWithName(isA(String.class))).andReturn(wrapper); expect(mockBackend.execute(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpContext.class))) .andReturn(resp1); expect(mockBackend.execute(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpContext.class))) .andReturn(resp2); replayMocks(); impl.execute(req1, ctx); impl.execute(req2, ctx); verifyMocks(); }