List of usage examples for org.apache.http.client.methods HttpUriRequest getURI
URI getURI();
From source file:org.fishwife.jrugged.httpclient.AbstractHttpClientDecorator.java
protected HttpHost getHttpHost(HttpUriRequest req) { URI uri = req.getURI(); String scheme = uri.getScheme(); if ("HTTPS".equalsIgnoreCase(scheme)) { return new HttpHost(uri.getScheme() + "://" + uri.getAuthority()); } else {/*www. j a v a 2 s. c om*/ return new HttpHost(uri.getAuthority()); } }
From source file:scouter.xtra.httpclient.HttpClient43.java
public String getURI(Object o) { if (o instanceof HttpUriRequest) { HttpUriRequest req = (HttpUriRequest) o; return req.getURI().getPath(); } else if (o instanceof HttpGet) { HttpGet req = (HttpGet) o;/*from www.j av a2 s .co m*/ return req.getURI().getPath(); } else if (o instanceof HttpPut) { HttpPut req = (HttpPut) o; return req.getURI().getPath(); } else if (o instanceof HttpRequest) { HttpRequest req = (HttpRequest) o; return req.getRequestLine().getUri(); } return o.toString(); }
From source file:fakingXmocking.CurrencyConversionHttpClientFake.java
@Mock public HttpResponse execute(HttpUriRequest req) { URI uri = req.getURI(); final String response; if ("www.jhall.demon.co.uk".equals(uri.getHost())) { response = "<h3>Currency Data</h3>\r\n" + "<table><tr>\r\n" + " <td valign=top>USD</td>\r\n" + " <td valign=top>EUR</td>\r\n" + " <td valign=top>BRL</td>\r\n" + " <td valign=top>CNY</td>\r\n" + "</tr></table>"; } else {/* w w w .jav a 2 s . co m*/ String[] params = uri.getQuery().split("&"); response = formatResultContainingCurrencyConversion(params); } return new BasicHttpResponse(req.getProtocolVersion(), 200, "OK") { @Override public HttpEntity getEntity() { return createHttpResponse(response); } }; }
From source file:guru.nidi.ramltester.httpcomponents.HttpComponentsRamlRequest.java
public HttpComponentsRamlRequest(HttpUriRequest request) { this.request = request; path = request.getURI().getPath(); url = request.getURI().toString(); }
From source file:com.netflix.http4.NFHttpMethodRetryHandler.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ICAST_INTEGER_MULTIPLY_CAST_TO_LONG") public boolean retryRequest(final IOException exception, int executionCount, HttpContext context) { if (super.retryRequest(exception, executionCount, context)) { HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String methodName = request.getRequestLine().getMethod(); String path = "UNKNOWN_PATH"; if (request instanceof HttpUriRequest) { HttpUriRequest uriReq = (HttpUriRequest) request; path = uriReq.getURI().toString(); }//ww w .ja v a 2s . c o m try { Thread.sleep(executionCount * this.sleepTimeFactorMs); } catch (InterruptedException e) { logger.warn("Interrupted while sleep before retrying http method " + methodName + " " + path, e); } DynamicCounter.increment(RETRY_COUNTER + methodName + ":" + path); return true; } return false; }
From source file:com.cloud.utils.rest.BasicRestClient.java
private void logRequestExecution(final HttpUriRequest request) { final URI uri = request.getURI(); String query = uri.getQuery(); query = query != null ? "?" + query : ""; s_logger.debug("Executig " + request.getMethod() + " request on " + clientContext.getTargetHost() + uri.getPath() + query);// w ww. ja v a2 s.c om }
From source file:com.android.mms.service.http.NetworkAwareHttpClient.java
/** * Generates a cURL command equivalent to the given request. *///w w w . java 2s . c om private static String toCurl(HttpUriRequest request, boolean logAuthToken) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("curl "); // add in the method builder.append("-X "); builder.append(request.getMethod()); builder.append(" "); for (Header header : request.getAllHeaders()) { if (!logAuthToken && (header.getName().equals("Authorization") || header.getName().equals("Cookie"))) { continue; } builder.append("--header \""); builder.append(header.toString().trim()); builder.append("\" "); } URI uri = request.getURI(); // If this is a wrapped request, use the URI from the original // request instead. getURI() on the wrapper seems to return a // relative URI. We want an absolute URI. if (request instanceof RequestWrapper) { HttpRequest original = ((RequestWrapper) request).getOriginal(); if (original instanceof HttpUriRequest) { uri = ((HttpUriRequest) original).getURI(); } } builder.append("\""); builder.append(uri); builder.append("\""); if (request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request; HttpEntity entity = entityRequest.getEntity(); if (entity != null && entity.isRepeatable()) { if (entity.getContentLength() < 1024) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); entity.writeTo(stream); if (isBinaryContent(request)) { String base64 = Base64.encodeToString(stream.toByteArray(), Base64.NO_WRAP); builder.insert(0, "echo '" + base64 + "' | base64 -d > /tmp/$$.bin; "); builder.append(" --data-binary @/tmp/$$.bin"); } else { String entityString = stream.toString(); builder.append(" --data-ascii \"").append(entityString).append("\""); } } else { builder.append(" [TOO MUCH DATA TO INCLUDE]"); } } } return builder.toString(); }
From source file:org.fcrepo.indexer.integration.webapp.SanityCheckIT.java
protected int getStatus(final HttpUriRequest method) throws IOException { logger.info("Executing: " + method.getMethod() + " to " + method.getURI()); return client.execute(method).getStatusLine().getStatusCode(); }
From source file:org.fcrepo.integration.syndication.AbstractResourceIT.java
protected int getStatus(HttpUriRequest method) throws ClientProtocolException, IOException { logger.debug("Executing: " + method.getMethod() + " to " + method.getURI()); return client.execute(method).getStatusLine().getStatusCode(); }
From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java
private void assertCommonParts(HttpUriRequest request) { assertEquals(SCHEME, request.getURI().getScheme()); assertEquals(HOST, request.getURI().getHost()); assertEquals(PORT, request.getURI().getPort()); }