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


Java URIUtils.resolve方法代码示例

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


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

示例1: resolveHttpRedirects

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/** Return final location from http redirects  */
public static String resolveHttpRedirects(String uri) 
        throws IOException, URISyntaxException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpClientContext context = HttpClientContext.create();
    HttpGet httpget = new HttpGet(uri);
    //httpget.addHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121202 Firefox/17.0 Iceweasel/17.0.1");        
    CloseableHttpResponse response = httpclient.execute(httpget, context);          
    try {
        HttpHost target = context.getTargetHost();
        List<URI> redirectLocations = context.getRedirectLocations();
        URI location = URIUtils.resolve(httpget.getURI(), target, redirectLocations);
        return location.toString();
    } finally {
        response.close();           
    }                
}
 
开发者ID:dkorenci,项目名称:feedsucker,代码行数:18,代码来源:HttpUtils.java

示例2: c

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static String c(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    URI i = i(str);
    if (i == null) {
        return str;
    }
    i = i.normalize();
    if (i.isOpaque()) {
        return str;
    }
    i = URIUtils.resolve(i, "./");
    if (i != null) {
        return i.toString();
    }
    return str;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:jr.java

示例3: getRequestURI

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
 * Creates absolute request URI with full path from passed in context.
 */
@Nonnull
private URI getRequestURI(final HttpContext context) {
  final HttpClientContext clientContext = HttpClientContext.adapt(context);
  final HttpRequest httpRequest = clientContext.getRequest();
  final HttpHost target = clientContext.getTargetHost();
  try {
    URI uri;
    if (httpRequest instanceof HttpUriRequest) {
      uri = ((HttpUriRequest) httpRequest).getURI();
    }
    else {
      uri = URI.create(httpRequest.getRequestLine().getUri());
    }
    return uri.isAbsolute() ? uri : URIUtils.resolve(URI.create(target.toURI()), uri);
  }
  catch (Exception e) {
    log.warn("Could not create absolute request URI", e);
    return URI.create(target.toURI());
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:24,代码来源:HttpClientManagerImpl.java

示例4: testUrlRedirect

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
private static void testUrlRedirect() throws IOException, URISyntaxException {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpClientContext context = HttpClientContext.create();        
        //String uri="http://feeds.nbcnews.com/c/35002/f/663303/s/410be3e0/sc/1/l/0L0Snbcnews0N0Cpolitics0Cfirst0Eread0Csimple0Ecommon0Esense0Ejeh0Ejohnson0Edefends0Eexecutive0Eaction0Eimmigration0En259736/story01.htm";
        //String uri="http://feeds.theguardian.com/c/34708/f/663879/s/410c0702/sc/8/l/0L0Stheguardian0N0Cworld0C20A140Cdec0C0A20Cnorth0Ekorea0Esony0Ecyber0Eattack/story01.htm";
        //String uri = "http://feeds.reuters.com/~r/Reuters/worldNews/~3/ySVJ_LFYBrs/story01.htm";
        String uri = "http://rss.nytimes.com/c/34625/f/642565/s/40f27c2a/sc/20/l/0L0Snytimes0N0C20A140C110C290Cworld0Cmiddleeast0Cpalestinian0Ehaven0Efor0E60Edecades0Enow0Eflooded0Efrom0Esyria0E0Bhtml0Dpartner0Frss0Gemc0Frss/story01.htm";
        HttpGet httpget = new HttpGet(uri);
        httpget.addHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121202 Firefox/17.0 Iceweasel/17.0.1");        
        CloseableHttpResponse response = httpclient.execute(httpget, context);          
        try {
            HttpHost target = context.getTargetHost();
            System.out.println("httpget URI: " + httpget.getURI());
            System.out.println("target host: " + target);
            System.out.println(response.getStatusLine().getStatusCode());            
            for (Header h : response.getAllHeaders()) {
                System.out.println(h.getName()+ " : " + h.getValue());                
            }
//            BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
//            String line = null;
//            while ((line = br.readLine()) != null) {
//                System.out.println(line);
//            }
            List<URI> redirectLocations = context.getRedirectLocations();
            if (redirectLocations != null)
            for (URI loc : redirectLocations) {
                System.out.println("redirect location: " + loc);
            }
            URI location = URIUtils.resolve(httpget.getURI(), target, redirectLocations);
            System.out.println("Final HTTP location: " + location.toASCIIString());
            // Expected to be an absolute URI
        } finally {
            response.close();
        }
    }
 
开发者ID:dkorenci,项目名称:feedsucker,代码行数:36,代码来源:BasicTests.java

示例5: 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

示例6: testAbsoluteRequestURIWithFragment

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

    final HttpHost target = start();

    final URI uri = new URIBuilder()
        .setHost(target.getHostName())
        .setPort(target.getPort())
        .setScheme(target.getSchemeName())
        .setPath("/stuff")
        .setFragment("blahblah")
        .build();

    final HttpGet httpget = new HttpGet(uri);
    final HttpClientContext context = HttpClientContext.create();

    final HttpResponse response = this.httpclient.execute(httpget, context);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());

    final HttpRequest request = context.getRequest();
    Assert.assertEquals("/stuff", request.getRequestLine().getUri());

    final List<URI> redirectLocations = context.getRedirectLocations();
    final URI location = URIUtils.resolve(uri, target, redirectLocations);
    Assert.assertEquals(uri, location);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:29,代码来源:TestClientRequestExecution.java

示例7: consume

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public void consume(Map<String, String> returnResult) {
    URI location;
    try {
        location = URIUtils.resolve(uri, targetHost, redirectLocations);
    } catch (URISyntaxException e) {
        //this is not a fatal error
        throw new IllegalArgumentException("could not determine '" + CSHttpClient.FINAL_LOCATION
                + "': " + e.getMessage(), e);
    }
    returnResult.put(CSHttpClient.FINAL_LOCATION, location.toASCIIString());
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:12,代码来源:FinalLocationConsumer.java

示例8: relativeToAbsolute

import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static String relativeToAbsolute(String baseUrl, String url)
{
  try
  {
    URI result = URIUtils.resolve(new URI(baseUrl), url);
    return result.toString();
  }
  catch (Exception e)
  {
    logger.warn("Cannot convert relative URL " + url + " to absolute, with base " + baseUrl, e);
  }
  return url;
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:14,代码来源:HttpClientUtils.java

示例9: 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.resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。