Java Code Examples for org.apache.commons.httpclient.methods.GetMethod#setURI()
The following examples show how to use
org.apache.commons.httpclient.methods.GetMethod#setURI() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrSearchProviderImpl.java From swellrt with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: SolrSearchProviderImpl.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: AbstractSolrAdminHTTPClient.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Executes an action or a command in SOLR using REST API * * @param httpClient HTTP Client to be used for the invocation * @param url Complete URL of SOLR REST API Endpoint * @return A JSON Object including SOLR response * @throws UnsupportedEncodingException */ protected JSONObject getOperation(HttpClient httpClient, String url) throws UnsupportedEncodingException { GetMethod get = new GetMethod(url); try { httpClient.executeMethod(get); if(get.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || get.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { Header locationHeader = get.getResponseHeader("location"); if (locationHeader != null) { String redirectLocation = locationHeader.getValue(); get.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(get); } } if (get.getStatusCode() != HttpServletResponse.SC_OK) { throw new LuceneQueryParserException("Request failed " + get.getStatusCode() + " " + url.toString()); } Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet())); JSONObject json = new JSONObject(new JSONTokener(reader)); return json; } catch (IOException | JSONException e) { throw new AlfrescoRuntimeException(e.getMessage(), e); } finally { get.releaseConnection(); } }
Example 4
Source File: Hc3HttpUtils.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Create an HTTP GET Method. * * @param url URL of the request. * @param properties Properties to drive the API. * @return GET Method * @throws URIException Exception if the URL is not correct. */ private static GetMethod createHttpGetMethod( String url, Map<String, String> properties) throws URIException { // Initialize GET Method org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(url, false, "UTF8"); GetMethod method = new GetMethod(); method.setURI(uri); method.getParams().setSoTimeout(60000); method.getParams().setContentCharset("UTF-8"); method.setRequestHeader("Accept-Encoding", "gzip"); // Manager query string StringBuilder debugUrl = (DEBUG_URL) ? new StringBuilder("GET " + url) : null; List<NameValuePair> params = new ArrayList<NameValuePair>(); if (properties != null) { boolean first = true; Iterator<Map.Entry<String, String>> iter = properties.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> property = iter.next(); String key = property.getKey(); String value = property.getValue(); params.add(new NameValuePair(key, value)); first = fillDebugUrl(debugUrl, first, key, value); } } if (DEBUG_URL && (debugUrl != null)) { debugText(debugUrl.toString()); } NameValuePair[] tmpParams = new NameValuePair[params.size()]; method.setQueryString(params.toArray(tmpParams)); return method; }