List of usage examples for org.apache.http.client.utils URIUtils rewriteURI
public static URI rewriteURI(final URI uri, final HttpHost target) throws URISyntaxException
From source file:org.apache.sling.hapi.client.test.util.HttpServerRule.java
@Override protected void before() throws Throwable { final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(5000).build(); serverBootstrap = ServerBootstrap.bootstrap().setSocketConfig(socketConfig).setServerInfo(ORIGIN); if (ProtocolScheme.https.equals(protocolScheme)) { serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext()); }// www .j ava 2 s . co m registerHandlers(); server = serverBootstrap.create(); server.start(); host = new HttpHost("127.0.0.1", server.getLocalPort(), protocolScheme.name()); uri = URIUtils.rewriteURI(new URI("/"), host); }
From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java
protected void rewriteRequestURI(final RequestWrapper request, final HttpRoute route) throws ProtocolException { try {//from ww w . j av a 2 s . c o m URI uri = request.getURI(); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target); request.setURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null); request.setURI(uri); } } } catch (URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
From source file:com.googlecode.jdeltasync.DeltaSyncClient.java
private <T> T post(final IDeltaSyncSession session, String uri, final String userAgent, final String contentType, final byte[] data, final UriCapturingResponseHandler<T> handler) throws DeltaSyncException, IOException { final HttpPost post = createHttpPost(uri, userAgent, contentType, data); final HttpContext context = new BasicHttpContext(); context.setAttribute(HttpClientContext.COOKIE_STORE, session.getCookieStore()); try {//from ww w . ja va 2 s . co m return httpClient.execute(post, new ResponseHandler<T>() { public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException { try { if (isRedirect(response)) { URI redirectUri = getRedirectLocationURI(session, post, response, context); return post(session, redirectUri.toString(), userAgent, contentType, data, handler); } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST); HttpHost host = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); URI uri; try { if (request instanceof HttpUriRequest) { uri = ((HttpUriRequest) request).getURI(); } else { uri = new URI(request.getRequestLine().getUri()); } if (!uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, host); } } catch (URISyntaxException e) { throw new DeltaSyncException(e); } return handler.handle(uri, response); } catch (DeltaSyncException e) { throw new RuntimeException(e); } } }, context); } catch (RuntimeException e) { Throwable t = e.getCause(); while (t != null) { if (t instanceof DeltaSyncException) { throw (DeltaSyncException) t; } t = t.getCause(); } throw e; } }
From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java
protected void rewriteRequestURI(final RequestWrapper request, final HttpRoute route) throws ProtocolException { try {/*from w w w . j ava 2s. c om*/ URI uri = request.getURI(); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { final HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target); request.setURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null); request.setURI(uri); } } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }