List of usage examples for org.apache.http.client.methods HttpRequestBase getURI
public URI getURI()
From source file:org.opencommercesearch.CloudSearchServerUnitTest.java
@Test public void testReloadCollections() throws Exception { cloudSearchServer.reloadCollections(); ArgumentCaptor<HttpRequestBase> argument = ArgumentCaptor.forClass(HttpRequestBase.class); verify(httpClient, times(2)).execute(argument.capture()); List<String> requestUrls = new ArrayList<String>(argument.getAllValues().size()); for (HttpRequestBase request : argument.getAllValues()) { requestUrls.add(request.getURI().toString()); }/* w ww . j av a 2s. c o m*/ assertThat(requestUrls, containsInAnyOrder( "http://node1.opencommercesearch.org/admin/cores?action=RELOAD&core=" + cloudSearchServer.getCatalogCollection(getLocale()) + "&indexInfo=true", "http://node1.opencommercesearch.org/admin/cores?action=RELOAD&core=" + cloudSearchServer.getRulesCollection(getLocale()) + "&indexInfo=true")); }
From source file:org.onehippo.forge.camel.demo.rest.services.AbstractRestUpdateResource.java
/** * Invokes Solr Update Service REST service with the given <code>payload</code>. * @param action Update action name. It should be either 'addOrReplace' or 'delete'. * @param payload JSON payload to be used as HTTP POST message body. * @return//from w ww . j ava2s .co m * @throws ClientProtocolException * @throws IOException */ protected HttpResponse invokeUpdateService(final String action, final JSONObject payload) throws ClientProtocolException, IOException { HttpClient client = getHttpClient(); HttpRequestBase request = createHttpRequest(action, payload); log.info("Invoking Search Engine Updater Service: '{}', '{}'.", request.getURI(), payload); HttpResponse response = client.execute(request); log.info("Response Status: {}", response.getStatusLine()); HttpEntity entity = response.getEntity(); if (entity != null) { log.info("Response Entity: {}", EntityUtils.toString(entity)); } return response; }
From source file:HybridIT.com.fourspaces.couchdb.CouchResponse.java
/** * C-tor parses the method results to build the CouchResponse object. * First, it reads the body (hence the IOException) from the method * Next, it checks the status codes to determine if the request was successful. * If there was an error, it parses the error codes. * @param method/*from ww w.jav a2 s.c om*/ * @throws IOException */ CouchResponse(HttpRequestBase req, HttpResponse response) throws IOException { headers = response.getAllHeaders(); HttpEntity entity = response.getEntity(); body = EntityUtils.toString(entity); path = req.getURI().getPath(); statusCode = response.getStatusLine().getStatusCode(); boolean isGet = (req instanceof HttpGet); boolean isPut = (req instanceof HttpPut); boolean isPost = (req instanceof HttpPost); boolean isDelete = (req instanceof HttpDelete); if ((isGet && statusCode == 404) || (isPut && statusCode == 409) || (isPost && statusCode == 404) || (isDelete && statusCode == 404)) { JSONObject jbody = JSONObject.fromObject(body); error_id = jbody.getString("error"); error_reason = jbody.getString("reason"); } else if ((isPut && statusCode == 201) || (isPost && statusCode == 201) || (isDelete && statusCode == 202) || (isDelete && statusCode == 200)) { if (path.endsWith("_bulk_docs")) { // Handle bulk doc update differently ok = JSONArray.fromObject(body).size() > 0; } else { ok = JSONObject.fromObject(body).getBoolean("ok"); } } else if ((req instanceof HttpGet) || ((req instanceof HttpPost) && statusCode == 200)) { ok = true; } log.debug(toString()); }
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: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 w w.j ava 2s .com 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); } } }
From source file:org.georchestra.security.RemoveXForwardedHeaders.java
@Override public boolean filter(String headerName, HttpServletRequest originalRequest, HttpRequestBase proxyRequest) { if (!headerName.equalsIgnoreCase(HOST) && !headerName.equalsIgnoreCase(PORT) && !headerName.equalsIgnoreCase(PROTOCOL) && !headerName.equalsIgnoreCase(FOR)) { return false; }//from w w w . j a va 2 s. c o m final String url = proxyRequest.getURI().toString(); boolean removeHeader = false; if (!includes.isEmpty()) { logger.debug("Checking requestURL: '" + url + "' against include patterns: " + this.includes); removeHeader = false; for (Pattern include : includes) { if (include.matcher(url).matches()) { removeHeader = true; break; } } } else if (!excludes.isEmpty()) { logger.debug("Checking requestURL: '" + url + "' against exclude patterns: " + this.excludes); removeHeader = true; for (Pattern exclude : excludes) { if (exclude.matcher(url).matches()) { removeHeader = false; } } } if (removeHeader) { logger.debug("Removing header: " + headerName); } else { logger.debug("Keeping header: " + headerName); } return removeHeader; }
From source file:org.mule.modules.constantcontact.RequestExecutor.java
private void logRequest(HttpRequestBase httpRequest) throws IOException { if (LOGGER.isDebugEnabled()) { if (httpRequest instanceof HttpEntityEnclosingRequest) { LOGGER.debug("Executing HTTP request: method = " + httpRequest.getMethod() + " - URI = " + httpRequest.getURI() + " - body = " + IOUtils.toString(((HttpEntityEnclosingRequest) httpRequest).getEntity().getContent())); } else {//from ww w . j a va 2 s . co m LOGGER.debug("Executing HTTP request: method = " + httpRequest.getMethod() + " - URI = " + httpRequest.getURI()); } } }
From source file:com.gsma.mobileconnect.utils.RestClient.java
/** * Make the specified request with the specified client context. * <p>/* w w w.j ava 2s.co m*/ * The specified cookies will be added to the request. A request will be aborted if it exceeds the specified timeout. * Non Json responses are converted and thrown as RestExceptions. * <p> * Ensures that all closable resources are closed. * * @param httpRequest The request to execute. * @param context The context to use when executing the request. * @param timeout The maximum time in milliseconds the request is allowed to take. * @param cookiesToProxy The cookies to add to the request. * @return The Rest response. * @throws RestException Thrown if the request exceeds the specified timeout, or a non Json response is received. * @throws IOException */ public RestResponse callRestEndPoint(HttpRequestBase httpRequest, HttpClientContext context, int timeout, List<KeyValuePair> cookiesToProxy) throws RestException, IOException { CookieStore cookieStore = buildCookieStore(httpRequest.getURI().getHost(), cookiesToProxy); CloseableHttpClient closeableHttpClient = getHttpClient(cookieStore); try { CloseableHttpResponse closeableHttpResponse = executeRequest(closeableHttpClient, httpRequest, context, timeout); try { RestResponse restResponse = buildRestResponse(httpRequest, closeableHttpResponse); checkRestResponse(restResponse); return restResponse; } finally { closeableHttpResponse.close(); } } finally { closeableHttpClient.close(); } }
From source file:com.smartling.api.sdk.FileApiClientAdapterTest.java
@Test public void testRenameFile() throws ApiException, IOException { when(response.getContents()).thenReturn(EMPTY_SUCESS_RESPONSE); ApiResponse<EmptyResponse> apiResponse = fileApiClientAdapter.renameFile(FILE_URI, FILE_URI2); // Validate the request HttpRequestBase request = requestCaptor.getValue(); List<NameValuePair> params = URLEncodedUtils.parse(request.getURI(), "UTF-8"); assertRenameFileParams(params);/*from ww w . j av a 2 s .c o m*/ assertEquals(HOST, request.getURI().getHost()); // Validate the response assertEquals("SUCCESS", apiResponse.getCode()); assertNull(apiResponse.getData()); }