LOGGER.error(String.format("Failed to execute the first PUT request to upload segment to webhdfs: %s. " + "Expected response code 307, but get %s. Response body: %s", firstPutReqString, firstResponseCode, firstPutReq.getResponseBodyAsString())); return false;
Socket sk = ReflectionUtils.invoke(GET_SOCKET, conn, (Object[]) null); String addr = sk.getLocalAddress().getHostAddress(); log.trace(String.format("Rx %s@[%s] [%s-%s] [%s]", proxyInfo, addr, http.getStatusCode(), HttpStatus.getStatusText(http.getStatusCode()), http.getResponseBodyAsString()));
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://www.google.com"); int responseCode = client.executeMethod(method); if (responseCode != 200) { throw new HttpException("HttpMethod Returned Status Code: " + responseCode + " when attempting: " + url); } String rtn = StringEscapeUtils.unescapeHtml(method.getResponseBodyAsString());
response = get.getResponseBodyAsString(); log.debug("Job " + mrJobId + " get status check result.\n"); } else {
private String readRespone(HttpMethod m) throws IOException { return m.getResponseBodyAsString(); }
private Set<String> getUpdateDataIdsInBody(HttpMethod httpMethod) { try { String modifiedDataIdsString = httpMethod.getResponseBodyAsString(); return DiamondUtils.convertStringToSet(modifiedDataIdsString); } catch (Exception e) { log.error("getUpdateDataIdsInBody error", e); } return new HashSet<>(); }
Set<String> getUpdateDataIdsInBody(HttpMethod httpMethod) { Set<String> modifiedDataIdSet = new HashSet<String>(); try { String modifiedDataIdsString = httpMethod.getResponseBodyAsString(); return convertStringToSet(modifiedDataIdsString); } catch (Exception e) { } return modifiedDataIdSet; }
public String getContentAsString() throws UnsupportedEncodingException { try { return method.getResponseBodyAsString(); } catch (IOException e) { return null; } }
public static String getOverHttp(String url) { HttpClient client = new HttpClient(); String response = null; HttpMethod get = new GetMethod(url); try { client.executeMethod(get); response = get.getResponseBodyAsString(); } catch (Exception e) { e.printStackTrace(); } finally { get.releaseConnection(); } return response; }
void discardResponse(HttpMethod httpMethod) throws IOException { if (log.isDebugEnabled()) { log.debug("Received non-OK response when invoking method on path " + httpMethod.getPath() + ". Response was:\n" + httpMethod.getResponseBodyAsString()); } else { byte[] buf = localBuffer.get(); InputStream responseStream = httpMethod.getResponseBodyAsStream(); while (responseStream.read(buf) != -1); } }
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); // http://www.google.com client.executeMethod(method); String result = method.getResponseBodyAsString();
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(URIget); HostConfiguration hostCfg = new HostConfiguration(); HttpState state = client.getState(); //setting a proxy, for example: state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword())); hostCfg.setProxyHost(new ProxyHost(getProxyHost(), getProxyPort())); //method.getParams().setSoTimeout(timeout); for example a timeout client.executeMethod(hostCfg, method); //calling the server String resp = method.getResponseBodyAsString(); //the response body
private CryptoCurrency readCurrencyViaJson(String key) throws IOException { HttpMethod get = new GetMethod(restEndpoint + "/" + key); get.setRequestHeader("Accept", "application/json"); restClient.executeMethod(get); String json = get.getResponseBodyAsString(); JsonNode jsonNode = new ObjectMapper().readTree(json); JsonNode description = jsonNode.get("description"); JsonNode rank = jsonNode.get("rank"); return new CryptoCurrency(description.asText(), rank.intValue()); }
HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); HttpMethod method = new GetMethod("http://www.aol.com"); method.setFollowRedirects(true); client.executeMethod(method); String responseBody = method.getResponseBodyAsString(); method.releaseConnection();
public ApplicationServerManagerResult start(String appPath) throws IOException { try { start.setQueryString(buildPathQueryArgs(appPath)); client.executeMethod(start); return parseResult(start.getResponseBodyAsString()); } finally { start.releaseConnection(); start.setPath(startPath); } }
public ApplicationServerManagerResult stop(String appPath) throws IOException { try { stop.setQueryString(buildPathQueryArgs(appPath)); client.executeMethod(stop); return parseResult(stop.getResponseBodyAsString()); } finally { stop.releaseConnection(); stop.setPath(stopPath); } }
public ApplicationServerManagerResult undeploy(String appPath) throws IOException { try { undeploy.setQueryString(buildPathQueryArgs(appPath)); client.executeMethod(undeploy); return parseResult(undeploy.getResponseBodyAsString()); } finally { undeploy.releaseConnection(); undeploy.setPath(undeployPath); } }
public void testEmbeddedPutRestHotRodGet() throws Exception { final String key = "2"; // 1. Put with Embedded assertEquals(null, cacheFactory.getEmbeddedCache().put(key, "v1")); // 2. Get with Hot Rod assertEquals("v1", cacheFactory.getHotRodCache().get(key)); // 3. Get with REST HttpMethod get = new GetMethod(cacheFactory.getRestUrl() + "/" + key); get.setRequestHeader("Accept", "text/plain"); cacheFactory.getRestClient().executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); assertEquals("v1", get.getResponseBodyAsString()); }
public void testHotRodPutEmbeddedRestGet() throws Exception { final String key = "3"; // 1. Put with Hot Rod RemoteCache<String, Object> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); // 2. Get with Embedded assertEquals("v1", cacheFactory.getEmbeddedCache().get(key)); // 3. Get with REST HttpMethod get = new GetMethod(cacheFactory.getRestUrl() + "/" + key); get.setRequestHeader("Accept", "text/plain"); cacheFactory.getRestClient().executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); assertEquals("v1", get.getResponseBodyAsString()); }
public void testEmbeddedPutRestHotRodGet() throws Exception { final String key = "2"; // 1. Put with Embedded, bypassing all encodings Cache cache = cacheFactory2.getEmbeddedCache().getAdvancedCache().withEncoding(IdentityEncoder.class); assertEquals(null, cache.put(key, "v1")); // 2. Get with Hot Rod via remote client, will use the configured encoding assertEquals("v1", cacheFactory1.getHotRodCache().get(key)); // 3. Get with REST, specifying the results as 'text' HttpMethod get = new GetMethod(cacheFactory2.getRestUrl() + "/" + key); get.setRequestHeader("Accept", "text/plain"); cacheFactory2.getRestClient().executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); assertEquals("v1", get.getResponseBodyAsString()); }