Refine search
break; case GET: http = (request.body() == null ? new GetMethod() : new GetMethodWithBody()); break; case POST: throw new EsHadoopInvalidRequest("URI has query portion on it: [" + uri + "]"); http.setURI(new URI(escapeUri(uri.toString(), sslEnabled), false)); http.setPath(path); uri = http.getURI().toString(); } catch (URIException uriex) { throw new EsHadoopTransportException("Invalid target URI " + request, uriex); client.executeMethod(http); } finally { stats.netTotalTime += (System.currentTimeMillis() - start);
try { getMethod = completionService.take().get(); URI uri = getMethod.getURI(); String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort()); if (getMethod.getStatusCode() >= 300) { LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode()); continue;
throws RedirectException { Header locationHeader = method.getResponseHeader("location"); if (locationHeader == null) { currentUri = new URI( this.conn.getProtocol().getScheme(), null, this.conn.getHost(), this.conn.getPort(), method.getPath() ); String charset = method.getParams().getUriCharset(); redirectUri = new URI(location, true, charset); if (redirectUri.isRelativeURI()) { if (this.params.isParameterTrue(HttpClientParams.REJECT_RELATIVE_REDIRECT)) { LOG.warn("Relative redirect location '" + location + "' not allowed"); redirectUri = new URI(currentUri, redirectUri); if(redirectUri.hasQuery()) { redirectUri.setQuery(null); LOG.debug("Redirecting from '" + currentUri.getEscapedURI() + "' to '" + redirectUri.getEscapedURI());
/** * Compare this URI to another object. * * @param obj the object to be compared. * @return 0, if it's same, * -1, if failed, first being compared with in the authority component * @throws ClassCastException not URI argument */ public int compareTo(Object obj) throws ClassCastException { URI another = (URI) obj; if (!equals(_authority, another.getRawAuthority())) { return -1; } return toString().compareTo(another.toString()); }
private static int httpNotification(String uri) throws IOException { URI url = new URI(uri, false); HttpClient m_client = new HttpClient(); HttpMethod method = new GetMethod(url.getEscapedURI()); method.setRequestHeader("Accept", "*/*"); return m_client.executeMethod(method); }
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; }
activeMethod = new GetMethod(url); activeMethod.setRequestHeader("Range", rangeHeader); activeMethod.setRequestHeader("Connection", "close"); int code = http.executeMethod(activeMethod); connectedUrl = activeMethod.getURI().toString(); connectedUrl = activeMethod.getURI().toString(); doClose(); throw io;
protected static String retrieveXML(String url) { HttpClient httpClient = new HttpClient(); String responseXML = ""; GetMethod get = null; try { URI uri = new URI(url, false); String escapedUrl = uri.getEscapedURI(); get = new GetMethod(escapedUrl); httpClient.executeMethod(get); responseXML = get.getResponseBodyAsString(); } catch (Exception e) { responseXML = "<errors><error>Error retreiving XML.</error></errors>"; // *** need i18n here } finally { get.releaseConnection(); } return responseXML; }
String uriStr; try { URI uriObj = new URI(uri, isUrlEncoded(uri)); uriStr = uriObj.toString(); } catch (URIException e) { throw new IllegalArgumentException("Invalid IRI string.", e); method = new GetMethod(uriStr); method.setFollowRedirects(true); client.executeMethod(method); _contentLength = method.getResponseContentLength(); final Header contentTypeHeader = method.getResponseHeader("Content-Type"); contentType = contentTypeHeader == null ? null : contentTypeHeader.getValue(); ); actualDocumentIRI = method.getURI().toString(); byte[] response = method.getResponseBody();
/** * @param method * @return the http status code of the execution * @throws IOException * @throws HttpException */ private int executeMethod(HttpMethod method) throws IOException, HttpException { String host = method.getURI().getHost(); if (host != null && nonProxyHosts.contains(host.toLowerCase())) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Bypassing proxy config due to nonProxyHosts for " + method.getURI().toString()); } return client.executeMethod(hostConfigNoProxy, method); } return client.executeMethod(method); }
/** * Execute method, redirect once if returned status is redirect. * * @param httpClient http client * @param method http method * @return status * @throws IOException on error */ protected static int executeMethodFollowRedirectOnce(HttpClient httpClient, HttpMethod method) throws IOException { int status = httpClient.executeMethod(method); // need to follow redirects (once) on public folders if (isRedirect(status)) { method.releaseConnection(); URI targetUri = new URI(method.getResponseHeader("Location").getValue(), true); checkExpiredSession(targetUri.getQuery()); method.setURI(targetUri); status = httpClient.executeMethod(method); } return status; }
hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false)); } catch (IOException ex) { throw new EsHadoopTransportException("Invalid target URI " + host, ex); client = new HttpClient(params, new SocketTrackingConnectionManager()); client.setHostConfiguration(hostConfig); HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
/** * Executes a passed HttpMethod (Method type is either PUT, POST, GET or * DELETE) and returns a HttpResponseMessage * * @param method Method to execute * @return HttpResponseMessage which contains all information about the * execution */ public static HttpResponseMessage executeHttpMethod(HttpMethod method) { HttpResponseMessage responseMessage = null; try { System.out.println("Method invocation on URI: \n"); System.out.println(method.getURI().toString()); // Execute Request LowLevelRestApi.httpClient.executeMethod(method); responseMessage = LowLevelRestApi.extractResponseInformation(method); } catch (Exception e) { e.printStackTrace(); } finally { // Release Connection anyway method.releaseConnection(); } // Extract response information and return return responseMessage; }
/** * Execute a transaction method given a complete URI. * @param method the transaction method * @param headers HTTP header values to send * @param uri a properly urlencoded URI * @return the HTTP response code * @throws IOException */ public int executeURI(HttpMethod method, Header[] headers, String uri) throws IOException { method.setURI(new URI(uri, true)); for (Map.Entry<String, String> e: extraHeaders.entrySet()) { method.addRequestHeader(e.getKey(), e.getValue()); } if (headers != null) { for (Header header: headers) { method.addRequestHeader(header); } } long startTime = System.currentTimeMillis(); int code = httpClient.executeMethod(method); long endTime = System.currentTimeMillis(); if (LOG.isDebugEnabled()) { LOG.debug(method.getName() + " " + uri + " " + code + " " + method.getStatusText() + " in " + (endTime - startTime) + " ms"); } return code; }
private static String createUrl(String url, List<NameValuePair> pairs) throws URIException { HttpMethod method = new GetMethod(url); NameValuePair[] nameValuePairs = pairs.toArray(new NameValuePair[pairs.size()]); method.setQueryString(nameValuePairs); return method.getURI().getEscapedURI(); } }
@Autowired public OpenMrsHttpClientImpl(@Value("${openmrs.url}") String openmrsUrl) throws URIException { Validate.notEmpty( openmrsUrl, "Did not find property for OpenMRS Url (openmrs.url). Cannot use the Motech Atom Feed module until this property is set"); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); URI uri = new URI(openmrsUrl, false); openmrsPath = uri.getPath(); httpClient.getHostConfiguration().setHost(uri); }
org.apache.commons.httpclient.HttpMethod httpMethod = null; try { URI uri = new URI(request.getURI().toString(), false, Consts.UTF_8.name()); if (method == HttpMethod.GET) { httpMethod = new GetMethod(); } else if (method == HttpMethod.HEAD) { httpMethod = new HeadMethod(); httpMethod = new OptionsMethod(); } else if (method == HttpMethod.TRACE) { return new TraceMethod(uri.getEscapedURI()); } else { throw new HttpClientException("unknown request method " + method + " for " + uri); httpMethod.setURI(uri); } catch (IOException e) { throw new HttpClientException("I/O error on " + method.name()
/** * Send Request to the repository */ protected HttpMethod sendRemoteRequest(Request req) throws AuthenticationException, IOException { if (logger.isDebugEnabled()) { logger.debug(""); logger.debug("* Request: " + req.getMethod() + " " + req.getFullUri() + (req.getBody() == null ? "" : "\n" + new String(req.getBody(), "UTF-8"))); } HttpMethod method = createMethod(req); // execute method executeMethod(method); // Deal with redirect if(isRedirect(method)) { Header locationHeader = method.getResponseHeader("location"); if (locationHeader != null) { String redirectLocation = locationHeader.getValue(); method.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(method); } } return method; }