@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } String stateValue = _state.toLowerCase(); if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) { throw new IllegalArgumentException( "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop"); } HttpClient httpClient = new HttpClient(); HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName); url.setQuery("state", stateValue); GetMethod httpGet = new GetMethod(url.getEscapedURI()); int status = httpClient.executeMethod(httpGet); if (status != 200) { throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString()); } return true; }
try { int responseCode = HTTP_CLIENT.executeMethod(httpGet); String response = httpGet.getResponseBodyAsString(); if (responseCode >= 400) {
try { statusCode = httpClient.executeMethod(get); schemaString = get.getResponseBodyAsString(); break; } catch (Exception e) {
try { statusCode = httpClient.executeMethod(get); schemaString = get.getResponseBodyAsString(); } catch (HttpException e) { throw new RuntimeException(e);
try { statusCode = httpClient.executeMethod(get); schemaString = get.getResponseBodyAsString(); } catch (IOException e) { throw new SchemaRegistryException(e);
try { statusCode = httpClient.executeMethod(get); schemaString = get.getResponseBodyAsString(); } catch (IOException e) { throw new SchemaRegistryException(e);
if (getMethod.getStatusCode() >= 300) { ++errors; Assert.assertEquals(getMethod.getResponseBodyAsString(), ERROR_MSG); } else { ++success; Assert.assertEquals(getMethod.getResponseBodyAsString(), SUCCESS_MSG);
try { returnValue = (T)gson.fromJson(gm.getResponseBodyAsString(2048), returnObjectType); } catch (IOException e) { S_LOGGER.error("IOException while retrieving response body", e);
logger.error("Connect failed with error code " + get.getStatusCode() + " and message:\n" + get.getResponseBodyAsString()); throw new ConnectionException("Connect failed, error code " + get.getStatusCode() + " and message: " + get.getResponseBodyAsString()); tableMetaStubs = new ObjectMapper().readValue(get.getResponseBodyAsString(), new TypeReference<List<TableMetaStub>>() { });
return getMethod.getResponseBodyAsString();
String getString() throws IOException { if (get == null) get = execDiffMethod(con, http, url); String res = get.getResponseBodyAsString(); return res; } public void close() throws IOException {
HttpClient client = new HttpClient(); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("test","test")); GetMethod getMethod = new GetMethod("http://www.example.com/mylogin"); client.executeMethod(getMethod); System.out.println(getMethod.getResponseBodyAsString());
private JSONObject executeMethod(HttpClient httpClient, GetMethod method) throws IOException { try { LOGGER.debug(method.getURI()); httpClient.executeMethod(method); JSONObject config = extractConfig(method.getResponseBodyAsString()); LOGGER.debug(config); return config; } finally { method.releaseConnection(); } }
public void doGet(HttpServletRequest req,HttpServletResponse resp){ HttpClient client=new HttpClient() // dont instantiate like this it's a heavyweight ;) GetMethod get=new GetMethod("http://stackoverflow.com/"); int status=client.executeMethod(get); if (status=200){ resp.getWriter().write(get.getResponseBodyAsString().getBytes("UTF-8")); resp.getWriter().flush(); }else{ // handle error } get.releaseConnection(); }
@Override public String getResponseBodyAsString() throws IOException { if (bufferedResponseBody==null) { connect(); bufferedResponseBody = httpGetMethod.getResponseBodyAsString(); release(false); } return bufferedResponseBody; }
HttpClient httpClient = new HttpClient(); GetMethod get = new GetMethod(url); try{ httpClient.executeMethod(get); return get.getResponseBodyAsString(); } catch (HttpException clP_e) { throw new IOException(clP_e); } finally { get.releaseConnection(); }
class Proxy extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Perform a new request to get contents from secured page HttpClient client = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials("user", "pass"); client.getState().setCredentials(authScope, credentials); GetMethod method = new GetMethod("/secure_page.jsp"); client.executeMethod(client.getHostConfiguration();, method); // write result to the outputstream resp.getWriter().write( method.getResponseBodyAsString() ); } }
HttpClient httpClient = new HttpClient() GetMethod get = new GetMethod(adviceGetURL); get.addRequestHeader("Content-Type", "application/json"); try { httpClient.executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); String response = get.getResponseBodyAsString(); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; public static void main(String[] args) throws HttpException, IOException { HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod("http://cetatenie.just.ro/Home/ORDINEANC.aspx"); getMethod.addRequestHeader("Host", "cetatenie.just.ro"); getMethod.addRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"); httpClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); } }
/** * @since 9.7RC1 */ public String executeAndGetBodyAsString(EntityReference reference, Map<String, ?> queryParameters) throws Exception { String url = getURL(reference, "get", toQueryString(queryParameters)); GetMethod getMethod = executeGet(url); String result = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); return result; }