List of usage examples for org.apache.http.client.methods HttpRequestBase getMethod
public abstract String getMethod();
From source file:org.gradle.internal.resource.transport.http.HttpClientHelper.java
public HttpResponse performHttpRequest(HttpRequestBase request) throws IOException { // Without this, HTTP Client prohibits multiple redirects to the same location within the same context httpContext.removeAttribute(DefaultRedirectStrategy.REDIRECT_LOCATIONS); LOGGER.debug("Performing HTTP {}: {}", request.getMethod(), request.getURI()); return client.execute(request, httpContext); }
From source file:org.gradle.internal.resource.transport.http.HttpResourceAccessor.java
/** * Same as #getResource except that it always gives access to the response body, * irrespective of the returned HTTP status code. Never returns {@code null}. *//*from ww w . j ava 2 s .c om*/ public HttpResponseResource getRawResource(final URI uri) throws IOException { abortOpenResources(); String location = uri.toString(); LOGGER.debug("Constructing external resource: {}", location); HttpRequestBase request = new HttpGet(uri); HttpResponse response; try { response = http.performHttpRequest(request); } catch (IOException e) { throw new HttpRequestException( String.format("Could not %s '%s'.", request.getMethod(), request.getURI()), e); } HttpResponseResource resource = wrapResponse(uri, response); return recordOpenGetResource(resource); }
From source file:com.gistlabs.mechanize.PageRequest.java
public HttpResponse consume(final HttpClient client, final HttpRequestBase request) throws Exception { if (!wasExecuted) { this.client = client; this.request = request; if (!request.getMethod().equalsIgnoreCase(httpMethod)) throw new IllegalArgumentException( String.format("Expected %s, but was %s", httpMethod, request.getMethod())); if (request.getURI().toString().equals(uri)) { HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK"); BasicHttpEntity entity = new BasicHttpEntity(); if (contentLocation != null) response.addHeader(new BasicHeader("Content-Location", contentLocation)); entity.setContentEncoding(charset); entity.setContentType(this.contentType); entity.setContent(this.body); response.setEntity(new BufferedHttpEntity(entity)); assertParameters(request);// www . ja va 2s .co m assertHeaders(request); this.wasExecuted = true; return response; } else { assertEquals("URI of the next PageRequest does not match", uri, request.getURI().toString()); return null; } } else throw new UnsupportedOperationException("Request already executed"); }
From source file:com.android.idtt.http.SyncHttpHandler.java
public ResponseStream sendRequest(HttpRequestBase request) throws HttpException { boolean retry = true; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { IOException exception = null; try {//from w w w.jav a 2 s .c o m if (request.getMethod().equals(HttpRequest.HttpMethod.GET.toString())) { _getRequestUrl = request.getURI().toString(); } else { _getRequestUrl = null; } if (_getRequestUrl != null) { String result = HttpUtils.sHttpGetCache.get(_getRequestUrl); if (result != null) { // get return new ResponseStream(result); } } HttpResponse response = client.execute(request, context); return handleResponse(response); } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (NullPointerException e) { exception = new IOException(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (HttpException e) { throw e; } catch (Exception e) { exception = new IOException(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } finally { if (!retry && exception != null) { throw new HttpException(exception); } } } return null; }
From source file:com.threatconnect.sdk.conn.HttpRequestExecutor.java
/** * Execute an HTTP request and return the raw input stream. <i>Caller is responsible for closing InputStream.</i> * * @param path url to issue request to//from w ww.j a v a 2s . com * @return raw input stream from response * @throws IOException On error */ @Override public InputStream executeDownloadByteStream(String path) throws IOException { if (this.conn.getConfig() == null) { throw new IllegalStateException("Can't execute HTTP request when configuration is undefined."); } InputStream stream = null; String fullPath = this.conn.getConfig().getTcApiUrl() + path.replace("/api/", "/"); logger.trace("Calling GET: " + fullPath); HttpRequestBase httpBase = getBase(fullPath, HttpMethod.GET); String headerPath = httpBase.getURI().getRawPath() + "?" + httpBase.getURI().getRawQuery(); ConnectionUtil.applyHeaders(this.conn.getConfig(), httpBase, httpBase.getMethod(), headerPath, conn.getConfig().getContentType(), ContentType.APPLICATION_OCTET_STREAM.toString()); logger.trace("Request: " + httpBase.getRequestLine()); logger.trace("Headers: " + Arrays.toString(httpBase.getAllHeaders())); CloseableHttpResponse response = this.conn.getApiClient().execute(httpBase); logger.trace(response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); if (entity != null) { stream = entity.getContent(); logger.trace(String.format("Result stream size: %d, encoding: %s", entity.getContentLength(), entity.getContentEncoding())); } return stream; }
From source file:org.apache.zeppelin.notebook.repo.zeppelinhub.rest.HttpProxyClient.java
private FutureCallback<HttpResponse> getCallback(final HttpRequestBase request) { return new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { request.releaseConnection(); LOG.info("Note {} completed with {} status", request.getMethod(), response.getStatusLine()); }/*from ww w . jav a 2 s.c om*/ public void failed(final Exception ex) { request.releaseConnection(); LOG.error("Note {} failed with {} message", request.getMethod(), ex.getMessage()); } public void cancelled() { request.releaseConnection(); LOG.info("Note {} was canceled", request.getMethod()); } }; }
From source file:com.machinepublishers.jbrowserdriver.StreamConnectionClient.java
CloseableHttpResponse execute(HttpRequestBase req, HttpClientContext context) throws ClientProtocolException, IOException { return !SettingsManager.settings().cache() || nonCachedMethods.contains(req.getMethod()) ? client.execute(req, context) : cachingClient.execute(req, context); }
From source file:com.youzu.android.framework.http.HttpHandler.java
private ResponseInfo<T> sendRequestForCache(HttpRequestBase request) { requestMethod = request.getMethod(); boolean isEnableCache = com.youzu.android.framework.HttpUtils.sHttpCache.isEnabled(requestMethod); // Log.e("APP", "requestMethod" + requestMethod + " isEnableCache:" + isEnableCache); if (isEnableCache) { String result = com.youzu.android.framework.HttpUtils.sHttpCache.get(requestUrl + request.toString()); if (result != null) { return new ResponseInfo<T>(null, (T) result, true); }/* w w w. j a va 2 s .c om*/ } return null; }
From source file:com.youzu.android.framework.http.SyncHttpHandler.java
public ResponseStream sendRequest(HttpRequestBase request) throws HttpException { HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (true) { boolean retry = true; IOException exception = null; try {/*www . j a v a 2s . co m*/ requestUrl = request.toString(); requestMethod = request.getMethod(); if (HttpUtils.sHttpCache.isEnabled(requestMethod)) { String result = HttpUtils.sHttpCache.get(requestUrl + request.toString()); if (result != null) { return new ResponseStream(result); } } HttpResponse response = client.execute(request, context); return handleResponse(response); } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (NullPointerException e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (HttpException e) { throw e; } catch (Throwable e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } if (!retry) { throw new HttpException(exception); } } }
From source file:cn.isif.util_plus.http.SyncHttpHandler.java
public ResponseStream sendRequest(HttpRequestBase request) throws HttpException { HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (true) { boolean retry = true; IOException exception = null; try {//from w ww .jav a2 s.co m requestUrl = request.getURI().toString(); requestMethod = request.getMethod(); if (HttpUtils.sHttpCache.isEnabled(requestMethod)) { String result = HttpUtils.sHttpCache.get(requestUrl); if (result != null) { return new ResponseStream(result); } } HttpResponse response = client.execute(request, context); return handleResponse(response); } catch (UnknownHostException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (IOException e) { exception = e; retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (NullPointerException e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } catch (HttpException e) { throw e; } catch (Throwable e) { exception = new IOException(e.getMessage()); exception.initCause(e); retry = retryHandler.retryRequest(exception, ++retriedTimes, context); } if (!retry) { throw new HttpException(exception); } } }