List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:ste.web.http.beanshell.BugFreeBeanShellHandler.java
@Before public void setUp() throws Exception { request = new BasicHttpRequest("GET", TEST_URI_PARAMETERS); context = new HttpSessionContext(); context.setAttribute(HttpCoreContext.HTTP_CONNECTION, getConnection()); context.setAttribute(TEST_REQ_ATTR_NAME1, TEST_VALUE1); context.setAttribute(TEST_REQ_ATTR_NAME2, TEST_VALUE2); context.setAttribute(TEST_REQ_ATTR_NAME3, TEST_VALUE3); response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK")); handler = new BeanShellHandler(new File(ROOT).getAbsolutePath()); }
From source file:org.eluder.coveralls.maven.plugin.httpclient.CoverallsClientTest.java
@Test public void testSubmit() throws Exception { StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"); when(httpResponseMock.getStatusLine()).thenReturn(statusLine); when(httpClientMock.execute(any(HttpUriRequest.class))).thenReturn(httpResponseMock); when(httpResponseMock.getEntity()).thenReturn(httpEntityMock); when(httpEntityMock.getContent())/*www . j a v a2 s.c o m*/ .thenReturn(coverallsResponse(new CoverallsResponse("success", false, ""))); CoverallsClient client = new CoverallsClient("http://test.com/coveralls", httpClientMock, new ObjectMapper()); client.submit(file); }
From source file:com.thoughtworks.go.agent.service.AgentUpgradeServiceTest.java
@BeforeEach void setUp() throws Exception { systemEnvironment = mock(SystemEnvironment.class); URLService urlService = mock(URLService.class); GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class); jvmExitter = mock(AgentUpgradeService.JvmExitter.class); agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter)); HttpGet httpMethod = mock(HttpGet.class); doReturn(httpMethod).when(agentUpgradeService).getAgentLatestStatusGetMethod(); closeableHttpResponse = mock(CloseableHttpResponse.class); when(closeableHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); when(httpClient.execute(httpMethod)).thenReturn(closeableHttpResponse); }
From source file:org.apache.trafficcontrol.client.trafficops.TOSessionTest.java
@Test public void deliveryServices() throws Throwable { final HttpResponse resp = Mockito.mock(HttpResponse.class); Mockito.doReturn(new BasicStatusLine(HttpVersion.HTTP_1_0, 200, "Ok")).when(resp).getStatusLine(); Mockito.doReturn(new StringEntity(DeliveryService_Good_Response)).when(resp).getEntity(); final CompletableFuture<HttpResponse> f = new CompletableFuture<>(); f.complete(resp);/*from ww w . j ava 2 s. co m*/ Mockito.doReturn(f).when(sessionMock).execute(Mockito.any(RequestBuilder.class)); final TOSession session = TOSession.builder().fromURI(baseUri).setRestClient(sessionMock).build(); CollectionResponse cResp = session.getDeliveryServices().get(); assertNotNull(cResp); assertNotNull(cResp.getResponse()); assertEquals(1, cResp.getResponse().size()); final Map<String, ?> service = cResp.getResponse().get(0); assertEquals("us-co-denver", service.get("cachegroup")); LOG.debug("Service: {}", service); }
From source file:com.seleritycorp.common.base.http.client.HttpResponseStreamTest.java
private HttpResponseStream createHttpResponseStream(int status, byte[] body, Charset charset) throws Exception { StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, status, "ReasonFoo"); org.apache.http.HttpResponse backendResponse = new BasicHttpResponse(statusLine); if (body != null) { backendResponse.setEntity(new ByteArrayEntity(body, ContentType.create("foo", charset))); } else {/* ww w. j a v a2s .c o m*/ backendResponse.setEntity(null); } return new HttpResponseStream(backendResponse); }
From source file:com.nexmo.client.voice.endpoints.ModifyCallMethodTest.java
@Test public void parseResponse() throws Exception { HttpWrapper wrapper = new HttpWrapper(); ModifyCallMethod methodUnderTest = new ModifyCallMethod(wrapper); HttpResponse stubResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("1.1", 1, 1), 200, "OK")); String json = "{\"message\":\"Received\"}"; InputStream jsonStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(jsonStream);//from w w w. j a v a2s . c om stubResponse.setEntity(entity); ModifyCallResponse response = methodUnderTest.parseResponse(stubResponse); assertEquals("Received", response.getMessage()); }
From source file:com.android.volley.toolbox.BaseHttpStack.java
/** * @deprecated use {@link #executeRequest} instead to avoid a dependency on the deprecated * Apache HTTP library. Nothing in Volley's own source calls this method. However, since * {@link BasicNetwork#mHttpStack} is exposed to subclasses, we provide this implementation in * case legacy client apps are dependent on that field. This method may be removed in a future * release of Volley.//from w w w. j a v a 2 s . co m */ @Deprecated @Override public final org.apache.http.HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpResponse response = executeRequest(request, additionalHeaders); ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); StatusLine statusLine = new BasicStatusLine(protocolVersion, response.getStatusCode(), "" /* reasonPhrase */); BasicHttpResponse apacheResponse = new BasicHttpResponse(statusLine); List<org.apache.http.Header> headers = new ArrayList<>(); for (Header header : response.getHeaders()) { headers.add(new BasicHeader(header.getName(), header.getValue())); } apacheResponse.setHeaders(headers.toArray(new org.apache.http.Header[headers.size()])); InputStream responseStream = response.getContent(); if (responseStream != null) { BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(responseStream); entity.setContentLength(response.getContentLength()); apacheResponse.setEntity(entity); } return apacheResponse; }
From source file:com.basho.riak.client.raw.http.HTTPRiakClientFactoryTest.java
/** * Test method for// ww w. ja va 2 s. co m * {@link com.basho.riak.client.raw.http.HTTPRiakClientFactory#newClient(com.basho.riak.client.raw.config.Configuration)} * . * * @throws IOException */ @Test public void newClientIsConfigured() throws IOException { HTTPClientConfig.Builder b = new HTTPClientConfig.Builder(); HttpClient httpClient = mock(HttpClient.class); HttpParams httpParams = mock(HttpParams.class); HttpResponse response = mock(HttpResponse.class); HttpEntity entity = mock(HttpEntity.class); when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(response); when(response.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(response.getEntity()).thenReturn(entity); when(httpClient.getParams()).thenReturn(httpParams); HTTPClientConfig conf = b.withUrl("http://www.google.com/notriak").withHttpClient(httpClient) .withMapreducePath("/notAPath").withMaxConnctions(200).withTimeout(9000).build(); HTTPClientAdapter client = (HTTPClientAdapter) HTTPRiakClientFactory.getInstance().newClient(conf); verify(httpParams).setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 9000); verify(httpParams).setIntParameter(AllClientPNames.SO_TIMEOUT, 9000); client.delete("b", "k"); verify(httpClient).execute(any(HttpDelete.class)); }
From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolverTest.java
@Test public void testNotSoSimpleGET() throws IOException { HTTPClientResponseResolver resolver = new TestableResolver(); HttpResponse mockedResponse = mock(HttpResponse.class); when(mockedResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[] { new BasicHeader("Date", HeaderUtils.toHttpDate("Date", new DateTime()).getValue()) }); when(mockedResponse.getStatusLine()).thenReturn(new BasicStatusLine(new HttpVersion(1, 1), 200, "OK")); when(mockedResponse.getEntity()).thenReturn(new InputStreamEntity(new NullInputStream(1), 1)); when(client.execute(Mockito.<HttpUriRequest>anyObject())).thenReturn(mockedResponse); HTTPResponse response = resolver.resolve(new HTTPRequest(URI.create("http://www.vg.no"))); assertNotNull("Response was null", response); assertEquals("Wrong header size", 1, response.getHeaders().size()); assertTrue("Response did not have payload", response.hasPayload()); }
From source file:com.microsoft.live.UploadRequestTest.java
/** * WinLive 633441: Make sure the query parameters on path get sent to * the HTTP PUT part of the upload./*w w w. j a v a 2 s . c om*/ */ public void testSendPathQueryParameterToHttpPut() throws Throwable { JSONObject jsonResponseBody = new JSONObject(); jsonResponseBody.put(JsonKeys.UPLOAD_LOCATION, "http://test.com/location"); InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes()); MockHttpEntity responseEntity = new MockHttpEntity(responseStream); BasicStatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""); final MockHttpResponse uploadLocationResponse = new MockHttpResponse(responseEntity, ok); HttpClient client = new HttpClient() { /** the first request to the client is the upload location request. */ boolean uploadLocationRequest = true; @Override public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException { if (uploadLocationRequest) { uploadLocationRequest = false; return uploadLocationResponse; } // This is really the only part we care about in this test. // That the 2nd request's uri has foo=bar in the query string. URI uri = request.getURI(); assertEquals("foo=bar&overwrite=choosenewname", uri.getQuery()); // for the test it doesn't matter what it contains, as long as it has valid json. // just return the previous reponse. return uploadLocationResponse; } @Override public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1, HttpContext arg2) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2, HttpContext arg3) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public ClientConnectionManager getConnectionManager() { throw new UnsupportedOperationException(); } @Override public HttpParams getParams() { throw new UnsupportedOperationException(); } }; LiveConnectSession session = TestUtils.newMockLiveConnectSession(); HttpEntity entity = new MockHttpEntity(); String path = Paths.ME_SKYDRIVE + "?foo=bar"; String filename = "filename"; UploadRequest uploadRequest = new UploadRequest(session, client, path, entity, filename, OverwriteOption.Rename); uploadRequest.execute(); }