List of usage examples for org.apache.http.client.methods CloseableHttpResponse getEntity
HttpEntity getEntity();
From source file:org.neo4j.ogm.session.response.JsonResponse.java
public JsonResponse(CloseableHttpResponse response) { try {//from w w w. j a v a2 s . co m this.response = response; this.results = response.getEntity().getContent(); this.scanner = new Scanner(results, "UTF-8"); } catch (IOException ioException) { throw new RuntimeException(ioException); } }
From source file:com.ritesh.idea.plugin.util.HttpRequestBuilder.java
public String asString() throws IOException, URISyntaxException { try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig) .build()) {//from w ww .j a v a 2 s .co m HttpRequestBase request = getHttpRequest(); CloseableHttpResponse response = client.execute(request); return CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); } }
From source file:com.erudika.para.security.LinkedInAuthFilter.java
/** * Handles an authentication request.//from w w w . j av a 2s . c o m * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { final String requestURI = request.getRequestURI(); UserAuthentication userAuth = null; if (requestURI.endsWith(LINKEDIN_ACTION)) { String authCode = request.getParameter("code"); if (!StringUtils.isBlank(authCode)) { String url = Utils.formatMessage(TOKEN_URL, authCode, request.getRequestURL().toString(), Config.LINKEDIN_APP_ID, Config.LINKEDIN_SECRET); HttpPost tokenPost = new HttpPost(url); CloseableHttpResponse resp1 = httpclient.execute(tokenPost); if (resp1 != null && resp1.getEntity() != null) { Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent()); if (token != null && token.containsKey("access_token")) { userAuth = getOrCreateUser(null, (String) token.get("access_token")); } EntityUtils.consumeQuietly(resp1.getEntity()); } } } User user = SecurityUtils.getAuthenticatedUser(userAuth); if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.getActive()) { throw new LockedException("Account is locked."); } return userAuth; }
From source file:net.liuxuan.Tools.signup.SignupQjvpn.java
public void check() throws IOException { HttpPost httppost = new HttpPost("http://www.qjvpn.com/ajax2.php?fun=sign"); CloseableHttpResponse response1 = httpclient.execute(httppost); try {/*from ww w . j av a2 s . com*/ HttpEntity entity = response1.getEntity(); String content = EntityUtils.toString(entity); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } System.out.println("-----------------content---------------------"); System.out.println(content); EntityUtils.consume(entity); } finally { response1.close(); } }
From source file:com.adobe.ags.curly.model.ActionResult.java
private Optional<ParsedResponseMessage> extractHtmlMessage(CloseableHttpResponse httpResponse) throws IOException { if (httpResponse == null || httpResponse.getEntity() == null) { return Optional.empty(); }// ww w . j av a 2s .co m InputStreamReader reader = new InputStreamReader(httpResponse.getEntity().getContent()); Stream<String> lines = new BufferedReader(reader).lines(); if (debugMode) { responseMessage = lines.collect(Collectors.toList()); lines = responseMessage.stream(); } return lines.map(this::parseMessagePatterns).filter(Optional::isPresent).findFirst() .orElse(Optional.empty()); }
From source file:com.meplato.store2.ApacheHttpResponse.java
/** * Instantiates a new instance of ApacheHttpResponse, * then close the response.//from w ww . ja v a2 s.c o m * * @param response the HTTP response from the ApacheHttpClient. * @throws ServiceException if e.g. serialization of the response fails. */ public ApacheHttpResponse(CloseableHttpResponse response) throws ServiceException { this.statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (entity != null) { try { ContentType contentType = ContentType.getOrDefault(entity); Charset charset = contentType.getCharset(); this.body = EntityUtils.toString(entity, charset); } catch (IOException e) { EntityUtils.consumeQuietly(entity); throw new ServiceException("Error deserializing data", null, e); } finally { try { response.close(); } catch (IOException e) { } } } else { this.body = null; } }
From source file:org.apache.hive.service.server.TestHS2HttpServer.java
@Test public void testConfStrippedFromWebUI() throws Exception { String pwdValFound = null;/*from www . java 2 s .com*/ String pwdKeyFound = null; CloseableHttpClient httpclient = null; try { httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://localhost:" + webUIPort + "/conf"); CloseableHttpResponse response1 = httpclient.execute(httpGet); try { HttpEntity entity1 = response1.getEntity(); BufferedReader br = new BufferedReader(new InputStreamReader(entity1.getContent())); String line; while ((line = br.readLine()) != null) { if (line.contains(metastorePasswd)) { pwdValFound = line; } if (line.contains(ConfVars.METASTOREPWD.varname)) { pwdKeyFound = line; } } EntityUtils.consume(entity1); } finally { response1.close(); } } finally { if (httpclient != null) { httpclient.close(); } } assertNotNull(pwdKeyFound); assertNull(pwdValFound); }
From source file:com.microsoft.applicationinsights.internal.channel.simplehttp.SimpleHttpChannel.java
@Override public void send(Telemetry item) { try {/*from w w w.ja va2 s .c om*/ // Establish the payload. StringWriter writer = new StringWriter(); // item.serialize(new JsonWriter(writer)); item.serialize(new JsonTelemetryDataSerializer(writer)); // Send it. String payload = writer.toString(); if (developerMode) { InternalLogger.INSTANCE.trace("SimpleHttpChannel, payload: %s", payload); } HttpPost request = new HttpPost(DEFAULT_SERVER_URI); StringEntity body = new StringEntity(payload, ContentType.create("application/x-json-stream")); request.setEntity(body); CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; try { response = httpClient.execute(request); HttpEntity respEntity = response.getEntity(); if (respEntity != null) respEntity.getContent().close(); if (developerMode) { InternalLogger.INSTANCE.trace("SimpleHttpChannel, response: %s", response.getStatusLine()); } } catch (IOException ioe) { try { if (response != null) { response.close(); } } catch (IOException ioeIn) { } } } catch (IOException ioe) { } }