List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine
public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str)
From source file:com.smartling.cms.gateway.client.CmsGatewayClientTest.java
private HttpResponse mockHttpResponse(int statusCode, String bodyJson) { HttpResponse response = mock(HttpResponse.class); when(response.getStatusLine())/*from w w w . jav a 2 s . c om*/ .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, "Status " + statusCode)); HttpEntity entity = EntityBuilder.create().setContentType(ContentType.APPLICATION_JSON).setText(bodyJson) .build(); when(response.getEntity()).thenReturn(entity); return response; }
From source file:com.microsoft.live.unittest.UploadTest.java
protected void loadUploadLocationResponseBody() throws Exception { /* create folder response */ JSONObject folder = new JSONObject(); folder.put(JsonKeys.UPLOAD_LOCATION, "https://upload.location.com/some/path"); InputStream uploadLocationStream = new ByteArrayInputStream(folder.toString().getBytes()); MockHttpEntity uploadLocationEntity = new MockHttpEntity(uploadLocationStream); StatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""); MockHttpResponse uploadLocationResponse = new MockHttpResponse(uploadLocationEntity, ok); this.mockClient.setHttpResponse(uploadLocationResponse); }
From source file:se.kodapan.io.http.wayback.Wayback.java
private HttpResponse httpResponseFactory(final WaybackResponse waybackResponse) { ProtocolVersion protocolVersion = new ProtocolVersion( waybackResponse.getStatusLine().getProtocolVersion().getProtocol(), waybackResponse.getStatusLine().getProtocolVersion().getMajor(), waybackResponse.getStatusLine().getProtocolVersion().getMinor()); StatusLine statusLine = new BasicStatusLine(protocolVersion, waybackResponse.getStatusLine().getStatusCode(), waybackResponse.getStatusLine().getReasonPhrase()); HttpResponse httpResponse = new BasicHttpResponse(statusLine); for (WaybackHeader header : waybackResponse.getHeaders()) { httpResponse.setHeader(new BasicHeader(header.getName(), header.getValue())); }/* ww w . j ava 2 s . c o m*/ if (waybackResponse.getLocale() != null) { httpResponse.setLocale(new Locale(waybackResponse.getLocale())); } httpResponse.setEntity(new HttpEntity() { @Override public boolean isRepeatable() { return true; } @Override public boolean isChunked() { return false; } @Override public long getContentLength() { return waybackResponse.getContentLength(); } @Override public Header getContentType() { return waybackResponse.getFirstHeader("Content-Type"); } @Override public Header getContentEncoding() { return waybackResponse.getFirstHeader("Content-Encoding"); } @Override public InputStream getContent() throws IOException, IllegalStateException { return new ByteArrayInputStream(waybackContents.get(waybackResponse.getContent()).getContent()); } @Override public void writeTo(OutputStream outstream) throws IOException { throw new UnsupportedOperationException(); } @Override public boolean isStreaming() { return false; } @Override public void consumeContent() throws IOException { } }); return httpResponse; }
From source file:com.microsoft.live.unittest.ApiTest.java
License:asdf
@Override protected void setUp() throws Exception { super.setUp(); // Set up the MockClient this.mockEntity = new MockHttpEntity(); StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); this.mockResponse = new MockHttpResponse(this.mockEntity, statusLine); this.mockClient = new MockHttpClient(this.mockResponse); this.loadLiveLibraryHeaderChecker(); this.exceptionQueue = new LinkedBlockingQueue<LiveOperationException>(); this.liveConnectClient = TestUtils.newLiveConnectClient(this.mockClient); }
From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java
private CloseableHttpResponse getDCRResponse() throws IOException { CloseableHttpResponse mockDCRResponse = new MockHttpResponse(); String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("dcr-response.json"); BasicHttpEntity responseEntity = new BasicHttpEntity(); responseEntity.setContent(/*from ww w. j a v a 2 s.c o m*/ new ByteArrayInputStream(getContent(dcrResponseFile).getBytes(StandardCharsets.UTF_8.name()))); responseEntity.setContentType(TestUtils.CONTENT_TYPE); mockDCRResponse.setEntity(responseEntity); mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK")); return mockDCRResponse; }
From source file:com.gooddata.http.client.GoodDataHttpClient.java
@Override public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException { notNull(request, "Request can't be null"); final boolean logoutRequest = isLogoutRequest(target, request); final Lock lock = logoutRequest ? rwLock.writeLock() : rwLock.readLock(); lock.lock();//from w w w.j a v a 2 s .co m final HttpResponse resp; try { if (tt != null) { // this adds TT header to EVERY request to ALL hosts made by this HTTP client // however the server performs additional checks to ensure client is not using forged TT request.setHeader(TT_HEADER, tt); if (logoutRequest) { try { sstStrategy.logout(httpClient, target, request.getRequestLine().getUri(), sst, tt); tt = null; sst = null; return new BasicHttpResponse(new BasicStatusLine(request.getProtocolVersion(), HttpStatus.SC_NO_CONTENT, "Logout successful")); } catch (GoodDataLogoutException e) { return new BasicHttpResponse(new BasicStatusLine(request.getProtocolVersion(), e.getStatusCode(), e.getStatusText())); } } } resp = this.httpClient.execute(target, request, context); } finally { lock.unlock(); } return handleResponse(target, request, resp, context); }
From source file:org.finra.herd.tools.downloader.DownloaderWebClientTest.java
@Test public void testGetBusinessObjectDataAssertNoAuthorizationHeaderWhenNoSsl() throws Exception { HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class); HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils .getField(downloaderWebClient, "httpClientOperations"); ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations); try {//from w w w . j a va 2 s . c om CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class); when(mockHttpClientOperations.execute(any(), any())).thenReturn(closeableHttpResponse); when(closeableHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); when(closeableHttpResponse.getEntity()) .thenReturn(new StringEntity(xmlHelper.objectToXml(new BusinessObjectData()))); DownloaderInputManifestDto manifest = new DownloaderInputManifestDto(); downloaderWebClient.getRegServerAccessParamsDto().setUseSsl(false); downloaderWebClient.getBusinessObjectData(manifest); verify(mockHttpClientOperations).execute(any(), argThat(httpUriRequest -> httpUriRequest.getFirstHeader("Authorization") == null)); } finally { ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations); } }
From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java
private CloseableHttpResponse getAccessTokenReponse() throws IOException { CloseableHttpResponse mockDCRResponse = new MockHttpResponse(); String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("accesstoken-response.json"); BasicHttpEntity responseEntity = new BasicHttpEntity(); responseEntity.setContent(//w ww . j av a 2 s . com new ByteArrayInputStream(getContent(dcrResponseFile).getBytes(StandardCharsets.UTF_8.name()))); responseEntity.setContentType(TestUtils.CONTENT_TYPE); mockDCRResponse.setEntity(responseEntity); mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK")); return mockDCRResponse; }
From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackCore.java
public synchronized HttpResponse listStacks(String endpoint) throws IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpResponse response = null;/*from w w w .j a v a2s . co m*/ HttpGet listStacks = null; if (this.isAuthenticated) { StringBuilder buildUrl = new StringBuilder(); buildUrl.append("http://"); buildUrl.append(endpoint); buildUrl.append(":"); buildUrl.append(Constants.HEAT_PORT.toString()); buildUrl.append(String.format("/%s/%s/stacks", Constants.HEAT_VERSION.toString(), this.tenant_id)); System.out.println(buildUrl); System.out.println(this.token_id); listStacks = new HttpGet(buildUrl.toString()); listStacks.addHeader(Constants.AUTHTOKEN_HEADER.toString(), this.token_id); response = httpClient.execute(listStacks); int status_code = response.getStatusLine().getStatusCode(); return (status_code == 200) ? response : factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, status_code, "List Failed with Status: " + status_code), null); } else { throw new IOException("You must Authenticate before issuing this request, please re-authenticate. "); } }
From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java
private CloseableHttpResponse getValidationResponse() throws UnsupportedEncodingException { ValidationResponce response = new ValidationResponce(); response.setDeviceId("1234"); response.setDeviceType("testdevice"); response.setJWTToken("1234567788888888"); response.setTenantId(-1234);//w w w .j av a2s . co m Gson gson = new Gson(); String jsonReponse = gson.toJson(response); CloseableHttpResponse mockDCRResponse = new MockHttpResponse(); BasicHttpEntity responseEntity = new BasicHttpEntity(); responseEntity.setContent(new ByteArrayInputStream(jsonReponse.getBytes(StandardCharsets.UTF_8.name()))); responseEntity.setContentType(TestUtils.CONTENT_TYPE); mockDCRResponse.setEntity(responseEntity); mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK")); return mockDCRResponse; }