List of usage examples for org.apache.http.message BasicHttpResponse BasicHttpResponse
public BasicHttpResponse(StatusLine statusLine)
From source file:com.android.net.volley.mock.MockHttpClient.java
@Override public HttpResponse execute(HttpUriRequest request, HttpContext context) { requestExecuted = request;/*from w w w . j a v a 2 s . c o m*/ StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, ""); HttpResponse response = new BasicHttpResponse(statusLine); response.setEntity(mResponseEntity); return response; }
From source file:com.splunk.shuttl.testutil.TUtilsMockito.java
private static HttpClient createHttpClientMockReturningHttpStatus(int httpStatus) { HttpClient httpClient = mock(HttpClient.class); StatusLine statusLine = mock(StatusLine.class); when(statusLine.getStatusCode()).thenReturn(httpStatus); try {/*from w ww . ja v a 2s . c om*/ when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(new BasicHttpResponse(statusLine)); } catch (Exception e) { TUtilsTestNG.failForException("Couldn't assign return value for execute", e); } return httpClient; }
From source file:com.nominanuda.web.mvc.URLStreamer.java
public HttpResponse handle(HttpRequest request) throws IOException { URL url = getURL(request);/* w ww.j a v a 2s .c o m*/ URLConnection conn = url.openConnection(); conn.connect(); int len = conn.getContentLength(); InputStream is = conn.getInputStream(); String ce = conn.getContentEncoding(); String ct = determineContentType(url, conn); if (len < 0) { byte[] content = ioHelper.readAndClose(is); is = new ByteArrayInputStream(content); len = content.length; } StatusLine statusline = httpCoreHelper.statusLine(SC_OK); HttpResponse resp = new BasicHttpResponse(statusline); resp.setEntity(new InputStreamEntity(is, len)); httpCoreHelper.setContentType(resp, ct); httpCoreHelper.setContentLength(resp, len);//TODO not needed ?? if (ce != null) { httpCoreHelper.setContentEncoding(resp, ce); } return resp; }
From source file:com.nominanuda.web.http.SerializeDeserializeTest.java
@Test public void testResponse() throws IOException, HttpException { HttpResponse resp = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); resp.addHeader("h1", "v1"); resp.setEntity(new StringEntity(PAYLOAD, ContentType.create("text/plain", "UTF-8"))); byte[] serialized = HTTP.serialize(resp); //System.err.println(new String(serialized, "UTF-8")); HttpResponse m = (HttpResponse) HTTP.deserialize(new ByteArrayInputStream(serialized)); //System.err.println(new String(HTTP.serialize(m), "UTF-8")); assertEquals(200, m.getStatusLine().getStatusCode()); assertEquals(PAYLOAD.getBytes(HttpProtocol.CS_UTF_8).length, ((ByteArrayEntity) m.getEntity()).getContentLength()); assertEquals("v1", m.getFirstHeader("h1").getValue()); }
From source file:com.thistech.spotlink.AbstractSpotlinkTest.java
protected HttpResponse prepareResponse(int expectedResponseStatus, String expectedResponseBody) { HttpResponse response = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), expectedResponseStatus, "")); response.setStatusCode(expectedResponseStatus); try {/* w w w .ja va2s . c o m*/ response.setEntity(new StringEntity(expectedResponseBody)); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return response; }
From source file:com.intuit.elves.network.mock.MockHttpClient.java
@Override public HttpResponse execute(HttpUriRequest request) throws java.io.IOException, org.apache.http.client.ClientProtocolException { if (mException != null) { throw mException; }//from w w w. j a va 2 s . co m requestExecuted = request; StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, ""); HttpResponse response = new BasicHttpResponse(statusLine); if (mHeader != null) { response.addHeader(mHeader); } if (responseEntity != null) { response.setEntity(responseEntity); } else if (request instanceof HttpPost) { // put the request body back to response response.setEntity(((HttpPost) request).getEntity()); } return response; }
From source file:org.jitsi.jicofo.reservation.HTTPTestUtil.java
/** * Get the <tt>HttpResponse</tt> instance used as return value in http client * mocking/*www . ja v a 2 s . co m*/ * * @param statusCode The status code to be assigned to response * @param reasonPhrase The HTTP reason phrase * @param responseBody The string to be used as response body * @return <tt>HttpResponse</tt> instance * @throws UnsupportedEncodingException When the responseBody */ protected HttpResponse getResponseEntity(final int statusCode, final String reasonPhrase, final String responseBody) throws UnsupportedEncodingException { BasicHttpResponse response = new BasicHttpResponse(getStatusLine(statusCode, reasonPhrase)); StringEntity responseEntity = new StringEntity(responseBody); response.setEntity(responseEntity); return response; }
From source file:org.envirocar.app.test.dao.TrackDecoderTest.java
public void testLocationParsing() throws TrackRetrievalException { HttpResponse resp = new BasicHttpResponse(createStatusLine()); resp.setHeader("Location", "http:/this.is.my.envirocar.server/api/tracks/1337-resource"); String result = new TrackDecoder().resolveLocation(resp); Assert.assertTrue(result.equals("1337-resource")); }
From source file:tech.sirwellington.alchemy.http.VerbAssertions.java
private static org.apache.http.HttpResponse createFakeApacheResponse() { org.apache.http.HttpResponse response; response = new BasicHttpResponse(statusLineWithCode(200)); return response; }
From source file:com.nexmo.client.voice.endpoints.ReadCallMethodTest.java
@Test public void parseResponse() throws Exception { HttpResponse stubResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("1.1", 1, 1), 200, "OK")); String json = " {\n" + " \"uuid\": \"93137ee3-580e-45f7-a61a-e0b5716000ef\",\n" + " \"status\": \"completed\",\n" + " \"direction\": \"outbound\",\n" + " \"rate\": \"0.02400000\",\n" + " \"price\": \"0.00280000\",\n" + " \"duration\": \"7\",\n" + " \"network\": \"23410\",\n" + " \"conversation_uuid\": \"aa17bd11-c895-4225-840d-30dc38c31e50\",\n" + " \"start_time\": \"2017-01-13T13:55:02.000Z\",\n" + " \"end_time\": \"2017-01-13T13:55:09.000Z\",\n" + " \"to\": {\n" + " \"type\": \"phone\",\n" + " \"number\": \"447700900104\"\n" + " },\n" + " \"from\": {\n" + " \"type\": \"phone\",\n" + " \"number\": \"447700900105\"\n" + " },\n" + " \"_links\": {\n" + " \"self\": {\n" + " \"href\": \"/v1/calls/93137ee3-580e-45f7-a61a-e0b5716000ef\"\n" + " }\n" + " }\n" + " }\n"; InputStream jsonStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(jsonStream);//from w w w .j a v a 2 s . co m stubResponse.setEntity(entity); CallInfo record = method.parseResponse(stubResponse); assertEquals("93137ee3-580e-45f7-a61a-e0b5716000ef", record.getUuid()); }