HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(); //You could use PostMethod if servlet accept POST String request ="http://some-remote-server/some-servlet?param1=value1¶m2=value2"; httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); getMethod.setURI(new URI(request, false, null)); ...
private JsonArray sendSearchRequest(String solrQuery, Function<InputStreamReader, JsonArray> function) throws IOException { JsonArray docsJson; GetMethod getMethod = new GetMethod(); HttpClient httpClient = new HttpClient(); try { getMethod.setURI(new URI(solrQuery, false)); int statusCode = httpClient.executeMethod(getMethod); docsJson = function.apply(new InputStreamReader(getMethod.getResponseBodyAsStream())); if (statusCode != HttpStatus.SC_OK) { LOG.warning("Failed to execute query: " + solrQuery); throw new IOException("Search request status is not OK: " + statusCode); } } finally { getMethod.releaseConnection(); } return docsJson; }
private void sendRequestToDeleteSolrIndex() { GetMethod getMethod = new GetMethod(); try { getMethod .setURI(new URI(solrBaseUrl + "/update?wt=json" + "&stream.body=<delete><query>" + SolrSearchProviderImpl.Q + "</query></delete>", false)); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(getMethod); if (statusCode == HttpStatus.SC_OK) { getMethod.setURI(new URI(solrBaseUrl + "/update?wt=json" + "&stream.body=<commit/>", false)); httpClient = new HttpClient(); statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { LOG.warning("failed to clean solr index"); } } else { LOG.warning("failed to clean solr index"); } } catch (Exception e) { LOG.warning("failed to clean solr index", e); } finally { getMethod.releaseConnection(); } } }
method.setURI(new URI(uri, true)); int returnCode = client.executeMethod(method);
getMethod.setURI(new URI(doServiceURL, true));
get.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(get);
get.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(get);
get.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(get);
get.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(get);
get.setURI(new URI(authorizationServerURL, false)); instream = executeHTTPMethod(httpclient, get, authorizationServerURL); JSONObject newJson = (JSONObject) JSONValue.parse(new InputStreamReader(instream));