当前位置: 首页>>代码示例>>Java>>正文


Java URIUtils.rewriteURI方法代码示例

本文整理汇总了Java中org.apache.http.client.utils.URIUtils.rewriteURI方法的典型用法代码示例。如果您正苦于以下问题:Java URIUtils.rewriteURI方法的具体用法?Java URIUtils.rewriteURI怎么用?Java URIUtils.rewriteURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.utils.URIUtils的用法示例。


在下文中一共展示了URIUtils.rewriteURI方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
static void rewriteRequestURI(
        final HttpRequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {
        URI uri = request.getURI();
        if (uri != null) {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
            request.setURI(uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:MinimalClientExec.java

示例2: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void rewriteRequestURI(
    final RequestWrapper request,
    final HttpRoute route) throws ProtocolException {
  try {

    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);
  }
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:27,代码来源:DefaultRequestDirector.java

示例3: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void rewriteRequestURI(
        final RequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {
        
        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);
    }
}
 
开发者ID:tdopires,项目名称:cJUnit-mc626,代码行数:27,代码来源:DefaultRequestDirector.java

示例4: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void rewriteRequestURI(
        final RequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {

        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);
    }
}
 
开发者ID:cattong,项目名称:YiBo,代码行数:27,代码来源:LibRequestDirector.java

示例5: before

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
@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());
    }
    registerHandlers();
    server = serverBootstrap.create();
    server.start();
    host = new HttpHost("127.0.0.1", server.getLocalPort(), protocolScheme.name());
    uri = URIUtils.rewriteURI(new URI("/"), host);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:14,代码来源:HttpServerRule.java

示例6: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void rewriteRequestURI(
        final RequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {

        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, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        } else {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        }
        request.setURI(uri);

    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " +
                request.getRequestLine().getUri(), ex);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:DefaultRequestDirector.java

示例7: rewriteRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void rewriteRequestURI(
        final RequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {

        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, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        } else {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        }
        request.setURI(uri);

    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " +
                request.getRequestLine().getUri(), ex);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:30,代码来源:DefaultRequestDirector.java

示例8: getLocationURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:61,代码来源:DefaultRedirectStrategy.java

示例9: testBasicRedirect301

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
@Test
public void testBasicRedirect301() throws Exception {
    this.serverBootstrap.registerHandler("*",
            new BasicRedirectService(HttpStatus.SC_MOVED_PERMANENTLY));

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpGet httpget = new HttpGet("/oldlocation/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(target, host);

    final List<URI> redirects = context.getRedirectLocations();
    Assert.assertNotNull(redirects);
    Assert.assertEquals(1, redirects.size());

    final URI redirect = URIUtils.rewriteURI(new URI("/newlocation/"), target);
    Assert.assertTrue(redirects.contains(redirect));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:29,代码来源:TestRedirects.java

示例10: getLocationURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    //get the location header to find out where to redirect to
    Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    URI uri = createLocationURI(location);

    HttpParams params = request.getParams();
    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        // Drop fragment
        uri = URIUtils.rewriteURI(uri);
        if (!uri.isAbsolute()) {
            if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (target == null) {
                throw new IllegalStateException("Target host not available " +
                        "in the HTTP context");
            }
            URI requestURI = new URI(request.getRequestLine().getUri());
            URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(
            REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
    }
    if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:68,代码来源:DefaultRedirectStrategy.java


注:本文中的org.apache.http.client.utils.URIUtils.rewriteURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。