List of usage examples for org.apache.http.util EntityUtils toString
public static String toString(HttpEntity httpEntity) throws IOException, ParseException
From source file:com.mycompany.horus.ServiceListener.java
private String getWsdlParametros() throws IOException { String resp;/*w w w. j a v a 2 s .c o m*/ CloseableHttpClient httpclient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(PARAMETERS_URL); HttpResponse response = httpclient.execute(post); HttpEntity respEntity = response.getEntity(); resp = EntityUtils.toString(respEntity); return resp; }
From source file:org.fcrepo.integration.auth.oauth.api.TokenEndpointIT.java
@Test public void testGetToken() throws Exception { logger.trace("Entering testGetToken()..."); final HttpPost post = new HttpPost( tokenEndpoint + "?grant_type=password&username=foo&password=bar&client_secret=foo&client_id=bar"); post.addHeader("Accept", APPLICATION_JSON); post.addHeader("Content-type", APPLICATION_FORM_URLENCODED); final HttpResponse tokenResponse = client.execute(post); logger.debug("Got a token response: \n{}", EntityUtils.toString(tokenResponse.getEntity())); Assert.assertEquals("Couldn't retrieve a token from token endpoint!", 200, tokenResponse.getStatusLine().getStatusCode()); }
From source file:com.github.mfriedenhagen.artifactorygo.JsonResponseHandler.java
@Override public T handleResponse(HttpResponse response) throws IOException { final HttpEntity entity = returnEntityWhenStatusValid(response); final Gson gson = new GsonBuilder().registerTypeAdapter(DateTime.class, new DateTimeDeserializer()) .registerTypeAdapter(Sha1.class, new Sha1Deserializer()) .registerTypeAdapter(MD5.class, new MD5Deserializer()).create(); final String body = EntityUtils.toString(entity); return gson.fromJson(body, clazz); }
From source file:org.kitodo.data.index.elasticsearch.RestClientImplementation.java
/** * Get information about client server./*from w w w . j a v a2 s . c o m*/ * * @return information about the server */ public String getServerInformation() throws IOException { Response response = restClient.performRequest("GET", "/", Collections.singletonMap("pretty", "true")); return EntityUtils.toString(response.getEntity()); }
From source file:com.hyphenated.pokerplayerclient.network.RestObjectRequestBuilder.java
@Override public JSONObject sendRequest() throws Exception { HttpClient httpClient = new DefaultHttpClient(httpParams); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); String response = EntityUtils.toString(httpResponse.getEntity()); return new JSONObject(response); }
From source file:org.opencastproject.remotetest.util.CaptureUtils.java
/** * Returns <code>true</code> if the capture agent with id <code>captureAgentId</code> is currently capturing. If the * agent is not online, an {@link IllegalStateException} is thrown. * //from w ww .jav a2s. co m * @param captureAgentId * the capture agent * @return <code>true</code> if the agent is capturing * @throws IllegalStateException * if the agent is not online * @throws Exception * if the response can't be parsed */ public static boolean isCapturing(String captureAgentId) throws IllegalStateException, Exception { HttpGet request = new HttpGet(BASE_URL + "/capture-admin/agents/" + captureAgentId); HttpResponse response = Main.getClient().execute(request); if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) throw new IllegalStateException("Capture agent '" + captureAgentId + "' is unexpectedly offline"); String responseBody = EntityUtils.toString(response.getEntity()); return "capturing".equalsIgnoreCase( (String) Utils.xpath(responseBody, "/*[local-name() = 'state']", XPathConstants.STRING)); }
From source file:net.giovannicapuano.galax.util.Utils.java
/** * Perform a HTTP POST request.//from w ww .j a va 2s. c o m */ public static HttpData postData(String path, List<NameValuePair> post, Context context) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 10000); int status = HttpStatus.SC_INTERNAL_SERVER_ERROR; String body = ""; HttpClient httpClient = new DefaultHttpClient(httpParameters); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context)); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); try { HttpPost httpPost = new HttpPost(context.getString(R.string.server) + path); httpPost.setEntity(new UrlEncodedFormEntity(post)); HttpResponse response = httpClient.execute(httpPost, localContext); status = response.getStatusLine().getStatusCode(); body = EntityUtils.toString(response.getEntity()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return new HttpData(status, body); }
From source file:org.forgerock.openam.mobile.commons.ResponseUnwrapper.java
/** * Returns the entity contents of an {@link org.apache.http.HttpResponse} as a String alongside its * status code. Ensures that we cannot pass back an HTTP Response directory to the UI thread, which * would break the Android app as there would be network activity on it. * * @return The String contents of the response's entity * @throws java.io.IOException If anything goes wrong reading the entity *///w w w .j a va 2 s . c o m public UnwrappedResponse unwrapHttpResponse() throws IOException { String contents = EntityUtils.toString(response.getEntity()); return new UnwrappedResponse(response.getStatusLine().getStatusCode(), contents, successAction, failAction); }
From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java
public static OpenIdConfiguration getInstance(String tenantName) throws Exception { if (configMap.containsKey(tenantName.toLowerCase())) { return configMap.get(tenantName.toLowerCase()); }/*from w ww . j av a 2s. co m*/ String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint; System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'"); HttpClient client = ServerUtils.getClient(tenantName); URI uri = new URI(url); HttpGet get = new HttpGet(uri); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpResponse response = client.execute(host, get); try { HttpEntity entity2 = response.getEntity(); String res = EntityUtils.toString(entity2); EntityUtils.consume(entity2); ObjectMapper mapper = new ObjectMapper(); //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com"); OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class); configMap.put(tenantName.toLowerCase(), openIdConfigInstance); return openIdConfigInstance; } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } }