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


Java URIUtils类代码示例

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


URIUtils类属于org.apache.http.client.utils包,在下文中一共展示了URIUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: OTSUri

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
public OTSUri(String endpoint, String action) {
    this.action = action;

    final String delimiter = "/";
    if (!endpoint.endsWith(delimiter)) {
        endpoint += delimiter;
    }

    // keep only one '/' in the end
    int index = endpoint.length() - 1;
    while (index > 0 && endpoint.charAt(index - 1) == '/') {
        index--;
    }

    endpoint = endpoint.substring(0, index + 1);

    try {
        this.uri = new URI(endpoint + action);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("The endpoint is invalid.", e);
    }

    this.host = URIUtils.extractHost(uri);
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-java-sdk,代码行数:25,代码来源:OTSUri.java

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

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

示例6: createURI

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
/**
 * @param query
 *            e.g. "/issues.xml"
 * @return URI with auth parameter "key" if not in "basic auth mode.
 */
private URI createURI(String query,
		Collection<? extends NameValuePair> origParams) {
	final List<NameValuePair> params = new ArrayList<NameValuePair>(
			origParams);
	if (apiAccessKey != null) {
		params.add(new BasicNameValuePair("key", apiAccessKey));
	}
	URI uri;
	try {
		URL url = baseURL;
		String path = url.getPath();
		if (!query.isEmpty()) {
			path += "/" + query;
		}
		uri = URIUtils.createURI(url.getProtocol(), url.getHost(),
				url.getPort(), path,
				URLEncodedUtils.format(params, "UTF-8"), null);
	} catch (URISyntaxException e) {
		throw new RedmineInternalError(e);
	}
	return uri;
}
 
开发者ID:andrea-rockt,项目名称:mylyn-redmine-connector,代码行数:28,代码来源:URIConfigurator.java

示例7: initTarget

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
protected void initTarget() throws ServletException {
    // TODO - should get the Kibana URI from Settings.java
//    targetUri = Settings.getKibanaUri();
    targetUri = settings.getYarnWebUIAddress();
    if (!targetUri.contains("http://")) {
      targetUri = "http://" + targetUri;
    }
    if (targetUri == null) {
      throw new ServletException(P_TARGET_URI + " is required.");
    }
    //test it's valid
    try {
      targetUriObj = new URI(targetUri);
    } catch (Exception e) {
      throw new ServletException("Trying to process targetUri init parameter: "
          + e, e);
    }
    targetHost = URIUtils.extractHost(targetUriObj);
  }
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:20,代码来源:YarnUIProxyServlet.java

示例8: initTarget

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
protected void initTarget() throws ServletException {
    // TODO - should get the Kibana URI from Settings.java
//    targetUri = Settings.getKibanaUri();
    targetUri = getConfigParam(P_TARGET_URI);
    if (targetUri == null) {
      throw new ServletException(P_TARGET_URI + " is required.");
    }
    //test it's valid
    try {
      targetUriObj = new URI(targetUri);
    } catch (Exception e) {
      throw new ServletException("Trying to process targetUri init parameter: "
          + e, e);
    }
    targetHost = URIUtils.extractHost(targetUriObj);
  }
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:17,代码来源:ProxyServlet.java

示例9: doGet

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
/**
 * Make a GET request and append the Map of parameters onto the query string.
 * @param address		the fully qualified URL to make the request to
 * @param parameters	the Map of parameters, ie key,value pairs
 * @return
 */
private String doGet(String address, Map<String, String> parameters){
	try {
		
		List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
		
		for (Map.Entry<String,String> entry : parameters.entrySet()) {
			queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		
		URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null);
		
		log.info(uri.toString());
		
		return doGet(uri.toString());
	
	} catch (URISyntaxException e) {
		log.error(e.getClass() + ":" + e.getMessage());
	}
	return null;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:27,代码来源:BitlyUrlService.java

示例10: createLocationURI

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
    try {
        URI uri;
        //NULogger.getLogger().log(Level.INFO, "location: {0}", location);
        
        //If it contains a special char we create our custom uri (it fails otherwise)
        if(location.contains("|")){
            uri = neembuu.uploader.utils.URIUtils.createURI(location);
        }
        else{
            uri = new URI(location);
        }
        return uri.normalize();
    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:21,代码来源:CustomRedirectStrategy.java

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

示例12: loadTopics

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
@Override
protected ArrayList<? extends IListItem> loadTopics(Client client, ListInfo listInfo) throws IOException, ParseException, URISyntaxException {
    SharedPreferences prefs = App.getInstance().getPreferences();
    if (mUrl == null) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("showforum", getForumId()));
        qparams.add(new BasicNameValuePair("sort_key", prefs.getString(getListName() + ".sort_key", "last_post")));
        qparams.add(new BasicNameValuePair("sort_by", prefs.getString(getListName() + ".sort_by", "Z-A")));
        qparams.add(new BasicNameValuePair("prune_day", prefs.getString(getListName() + ".prune_day", "100")));
        qparams.add(new BasicNameValuePair("topicfilter", prefs.getString(getListName() + ".topicfilter", "all")));
        qparams.add(new BasicNameValuePair("st", Integer.toString(listInfo.getFrom())));


        URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php",
                URLEncodedUtils.format(qparams, "UTF-8"), null);
        mUrl = uri.toString();
    } else {
        mUrl = mUrl.replaceAll("&st=\\d+", "").concat("&st=" + mListInfo.getFrom());
    }
    ArrayList<Topic> res = TopicsApi.getForumTopics(client, mUrl,getForumId(),
            prefs.getBoolean(getListName() + ".unread_in_top", false),
            mListInfo);
    mUrl = Client.getInstance().getRedirectUri() != null ? Client.getInstance().getRedirectUri().toString() : mUrl;
    return res;
}
 
开发者ID:slartus,项目名称:4pdaClient-plus,代码行数:26,代码来源:ForumTopicsListFragment.java

示例13: pinFavorite

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
public static String pinFavorite(IHttpClient httpClient, String topicId, String trackType) throws ParseException, IOException, URISyntaxException {
    FavTopic favTopic = findTopicInFav(httpClient, topicId);

    if (favTopic == null) {
        return "Тема не найдена в избранном";
    }

    List<NameValuePair> qparams = new ArrayList<>();
    qparams.add(new BasicNameValuePair("act", "fav"));
    qparams.add(new BasicNameValuePair("selectedtids", favTopic.getTid()));
    qparams.add(new BasicNameValuePair("tact", trackType));
    URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php",
            URLEncodedUtils.format(qparams, "UTF-8"), null);
    httpClient.performGet(uri.toString());
    return TRACK_TYPE_PIN.equals(trackType) ? "Тема закреплена" : "Тема откреплена";
}
 
开发者ID:slartus,项目名称:4pdaClient-plus,代码行数:17,代码来源:TopicApi.java

示例14: getAllScoresFromServer

import org.apache.http.client.utils.URIUtils; //导入依赖的package包/类
public static String getAllScoresFromServer(String serverIP, int serverPort) throws URISyntaxException, IOException {

        URI uri = URIUtils.createURI("http", serverIP, serverPort, "/getScores", null, null);

        URL url = uri.toURL();
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();

        StringWriter writer = new StringWriter();
        IOUtils.copy(is, writer);
        String response = writer.toString();

        JSONObject jsonObject = new JSONObject(response);
        System.out.println(response);

        return jsonObject.toString();
    }
 
开发者ID:kaloni,项目名称:TheJavaProject,代码行数:18,代码来源:Network.java

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


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