List of usage examples for org.apache.http.client.methods CloseableHttpResponse getStatusLine
StatusLine getStatusLine();
From source file:org.camunda.bpm.engine.rest.standalone.AbstractEmptyBodyFilterTest.java
private void evaluatePostRequest(HttpEntity reqBody, String reqContentType, int expectedStatusCode, boolean assertResponseBody) throws IOException { HttpPost post = new HttpPost(BASE_URL + START_PROCESS_INSTANCE_BY_KEY_URL); post.setConfig(reqConfig);/*from ww w . ja va2 s .c om*/ if (reqContentType != null) { post.setHeader(HttpHeaders.CONTENT_TYPE, reqContentType); } post.setEntity(reqBody); CloseableHttpResponse response = client.execute(post); assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode()); if (assertResponseBody) { assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, new JSONObject(EntityUtils.toString(response.getEntity(), "UTF-8")).get("id")); } response.close(); }
From source file:org.commonjava.indy.httprox.Propagate404NotFoundTest.java
@Test public void run() throws Exception { final String testRepo = "test"; final String url = server.formatUrl(testRepo, "org/test/foo/1/foo-1.pom"); final HttpGet get = new HttpGet(url); final CloseableHttpClient client = proxiedHttp(); CloseableHttpResponse response = null; final InputStream stream = null; try {//from w w w. java 2 s .com response = client.execute(get, proxyContext(USER, PASS)); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_NOT_FOUND)); } finally { IOUtils.closeQuietly(stream); HttpResources.cleanupResources(get, response, client); } final RemoteRepository remoteRepo = this.client.stores().load( new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class); assertThat(remoteRepo, notNullValue()); assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri())); }
From source file:org.wso2.carbon.ml.project.test.DeleteProjectsTestCase.java
@BeforeClass(alwaysRun = true) public void initTest() throws MLHttpClientException, MLIntegrationBaseTestException { super.init(); mlHttpclient = new MLHttpClient(instance, userInfo); //Check whether the dataset exists. CloseableHttpResponse response = mlHttpclient .doHttpGet("/api/datasets/" + MLIntegrationTestConstants.DATASET_ID); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); // Create a project to delete mlHttpclient.createProject(projectName, MLIntegrationTestConstants.DATASET_NAME); }
From source file:com.apm4all.tracy.TracyCloseableHttpClientPublisher.java
private String extractPostResponse(CloseableHttpResponse response) throws ParseException, IOException { StringBuilder sb = new StringBuilder(1024); HttpEntity entity = response.getEntity(); sb.append(response.getStatusLine()); sb.append(" "); sb.append(EntityUtils.toString(entity, StandardCharsets.UTF_8)); EntityUtils.consume(entity);/*from ww w . jav a 2 s.c o m*/ return sb.toString(); }
From source file:com.mirth.connect.client.core.ConnectServiceUtil.java
public static void registerUser(String serverId, String mirthVersion, User user, String[] protocols, String[] cipherSuites) throws ClientException { CloseableHttpClient httpClient = null; CloseableHttpResponse httpResponse = null; NameValuePair[] params = { new BasicNameValuePair("serverId", serverId), new BasicNameValuePair("version", mirthVersion), new BasicNameValuePair("user", ObjectXMLSerializer.getInstance().serialize(user)) }; HttpPost post = new HttpPost(); post.setURI(URI.create(URL_CONNECT_SERVER + URL_REGISTRATION_SERVLET)); post.setEntity(new UrlEncodedFormEntity(Arrays.asList(params), Charset.forName("UTF-8"))); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build(); try {/*from www . ja v a 2 s . c o m*/ HttpClientContext postContext = HttpClientContext.create(); postContext.setRequestConfig(requestConfig); httpClient = getClient(protocols, cipherSuites); httpResponse = httpClient.execute(post, postContext); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) { throw new Exception("Failed to connect to update server: " + statusLine); } } catch (Exception e) { throw new ClientException(e); } finally { HttpClientUtils.closeQuietly(httpResponse); HttpClientUtils.closeQuietly(httpClient); } }
From source file:org.commonjava.indy.httprox.Propagate500As502ErrorTest.java
@Test public void run() throws Exception { final String testRepo = "test"; final String url = server.formatUrl(testRepo, "org/test/foo/1/foo-1.pom"); server.registerException(url, "Expected error", HttpStatus.SC_INTERNAL_SERVER_ERROR); final HttpGet get = new HttpGet(url); final CloseableHttpClient client = proxiedHttp(); CloseableHttpResponse response = null; final InputStream stream = null; try {//from ww w .j a v a 2 s. c om response = client.execute(get, proxyContext(USER, PASS)); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY)); } finally { IOUtils.closeQuietly(stream); HttpResources.cleanupResources(get, response, client); } final RemoteRepository remoteRepo = this.client.stores() .load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1"), RemoteRepository.class); assertThat(remoteRepo, notNullValue()); assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri())); }
From source file:org.wso2.carbon.ml.analysis.test.AddFeaturesTestCase.java
@BeforeClass(alwaysRun = true) public void initTest() throws Exception { super.init(); mlHttpclient = new MLHttpClient(instance, userInfo); // Check whether the analysis exists. CloseableHttpResponse response = mlHttpclient .doHttpGet("/api/analyses/" + MLIntegrationTestConstants.ANALYSIS_NAME); if (Response.Status.OK.getStatusCode() != response.getStatusLine().getStatusCode()) { throw new SkipException("Skipping tests becasue an analysis is not available"); }/*from ww w . jav a 2 s. com*/ }
From source file:org.wso2.carbon.ml.analysis.test.SetHyperparametersTestCase.java
@BeforeClass(alwaysRun = true) public void initTest() throws MLHttpClientException, MLIntegrationBaseTestException { super.init(); mlHttpclient = new MLHttpClient(instance, userInfo); // Check whether the analysis exists. CloseableHttpResponse response = mlHttpclient .doHttpGet("/api/analyses/" + MLIntegrationTestConstants.ANALYSIS_NAME); if (Response.Status.OK.getStatusCode() != response.getStatusLine().getStatusCode()) { throw new SkipException("Skipping tests becasue an analysis is not available"); }/* ww w . ja v a 2 s . c o m*/ }
From source file:ar.edu.ubp.das.src.chat.actions.EliminarMensajeAction.java
@Override public ForwardConfig execute(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, RuntimeException { try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { //get request data String id_mensaje = form.getItem("id_mensaje"); String authToken = String.valueOf(request.getSession().getAttribute("token")); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("25.136.78.82").setPort(8080).setPath("/mensajes/" + id_mensaje); HttpDelete delete = new HttpDelete(); delete.setURI(builder.build());/* w w w . ja v a 2s. c o m*/ delete.addHeader("Authorization", "BEARER " + authToken); delete.addHeader("accept", "application/json"); CloseableHttpResponse deleteResponse = httpClient.execute(delete); HttpEntity responseEntity = deleteResponse.getEntity(); StatusLine responseStatus = deleteResponse.getStatusLine(); String restResp = EntityUtils.toString(responseEntity); if (responseStatus.getStatusCode() != 200) { throw new RuntimeException(restResp); } return mapping.getForwardByName("success"); } catch (IOException | URISyntaxException | RuntimeException e) { String id_mensaje = form.getItem("id_mensaje"); request.setAttribute("message", "Error al intentar eliminar mensaje " + id_mensaje + "; " + e.getMessage()); response.setStatus(400); return mapping.getForwardByName("failure"); } }
From source file:com.enioka.jqm.tools.JettyTest.java
@Test public void testSslClientCert() throws Exception { Helpers.setSingleParam("enableWsApiSsl", "true", em); Helpers.setSingleParam("disableWsApi", "false", em); Helpers.setSingleParam("enableWsApiAuth", "false", em); addAndStartEngine();/*from w ww . j a v a 2s . c om*/ // Launch a job so as to be able to query its status later CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, em); JobRequest j = new JobRequest("MarsuApplication", "TestUser"); int i = JqmClientFactory.getClient().enqueue(j); TestHelpers.waitFor(1, 10000, em); // Server auth against trusted CA root certificate KeyStore trustStore = KeyStore.getInstance("JKS"); FileInputStream instream = new FileInputStream(new File("./conf/trusted.jks")); try { trustStore.load(instream, "SuperPassword".toCharArray()); } finally { instream.close(); } // Client auth JpaCa.prepareClientStore(em, "CN=testuser", "./conf/client.pfx", "SuperPassword", "client-cert", "./conf/client.cer"); KeyStore clientStore = KeyStore.getInstance("PKCS12"); instream = new FileInputStream(new File("./conf/client.pfx")); try { clientStore.load(instream, "SuperPassword".toCharArray()); } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore) .loadKeyMaterial(clientStore, "SuperPassword".toCharArray()).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient cl = HttpClients.custom().setSSLSocketFactory(sslsf).build(); int port = em.createQuery("SELECT q.port FROM Node q WHERE q.id = :i", Integer.class) .setParameter("i", TestHelpers.node.getId()).getSingleResult(); HttpUriRequest rq = new HttpGet( "https://" + TestHelpers.node.getDns() + ":" + port + "/ws/simple/status?id=" + i); CloseableHttpResponse rs = cl.execute(rq); Assert.assertEquals(200, rs.getStatusLine().getStatusCode()); rs.close(); cl.close(); }