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


Java URI类代码示例

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


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

示例1: executeURI

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Execute a transaction method given a complete URI.
 * @param method the transaction method
 * @param headers HTTP header values to send
 * @param uri a properly urlencoded URI
 * @return the HTTP response code
 * @throws IOException
 */
public int executeURI(HttpMethod method, Header[] headers, String uri)
    throws IOException {
  method.setURI(new URI(uri, true));
  for (Map.Entry<String, String> e: extraHeaders.entrySet()) {
    method.addRequestHeader(e.getKey(), e.getValue());
  }
  if (headers != null) {
    for (Header header: headers) {
      method.addRequestHeader(header);
    }
  }
  long startTime = System.currentTimeMillis();
  int code = httpClient.executeMethod(method);
  long endTime = System.currentTimeMillis();
  if (LOG.isDebugEnabled()) {
    LOG.debug(method.getName() + " " + uri + " " + code + " " +
      method.getStatusText() + " in " + (endTime - startTime) + " ms");
  }
  return code;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:29,代码来源:Client.java

示例2: executePathOnly

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Execute a transaction method given only the path. Will select at random
 * one of the members of the supplied cluster definition and iterate through
 * the list until a transaction can be successfully completed. The
 * definition of success here is a complete HTTP transaction, irrespective
 * of result code.  
 * @param cluster the cluster definition
 * @param method the transaction method
 * @param headers HTTP header values to send
 * @param path the properly urlencoded path
 * @return the HTTP response code
 * @throws IOException
 */
public int executePathOnly(Cluster cluster, HttpMethod method,
    Header[] headers, String path) throws IOException {
  IOException lastException;
  if (cluster.nodes.size() < 1) {
    throw new IOException("Cluster is empty");
  }
  int start = (int)Math.round((cluster.nodes.size() - 1) * Math.random());
  int i = start;
  do {
    cluster.lastHost = cluster.nodes.get(i);
    try {
      StringBuilder sb = new StringBuilder();
      sb.append("http://");
      sb.append(cluster.lastHost);
      sb.append(path);
      URI uri = new URI(sb.toString(), true);
      return executeURI(method, headers, uri.toString());
    } catch (IOException e) {
      lastException = e;
    }
  } while (++i != start && i < cluster.nodes.size());
  throw lastException;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:37,代码来源:Client.java

示例3: checkHttpSchemeSpecificPartSlashPrefix

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * If http(s) scheme, check scheme specific part begins '//'.
 * @throws URIException
 * @see <A href="http://www.faqs.org/rfcs/rfc1738.html">Section 3.1. 
 * Common Internet Scheme Syntax</A>
 */
protected void checkHttpSchemeSpecificPartSlashPrefix(final URI base,
        final String scheme, final String schemeSpecificPart)
        throws URIException {
    if (scheme == null || scheme.length() <= 0) {
        return;
    }
    if (!scheme.equals("http") && !scheme.equals("https")) {
        return;
    }
    if (schemeSpecificPart == null 
            || !schemeSpecificPart.startsWith("//")) {
        // only acceptable if schemes match
        if (base == null || !scheme.equals(base.getScheme())) {
            throw new URIException(
                    "relative URI with scheme only allowed for "
                            + "scheme matching base");
        }
        return;
    }
    if (schemeSpecificPart.length() <= 2) {
        throw new URIException("http scheme specific part is "
                + "too short: " + schemeSpecificPart);
    }
}
 
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:31,代码来源:NetarchiveSuiteUURIFactory.java

示例4: executeURI

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Execute a transaction method given a complete URI.
 * @param method the transaction method
 * @param headers HTTP header values to send
 * @param uri a properly urlencoded URI
 * @return the HTTP response code
 * @throws IOException
 */
public int executeURI(HttpMethod method, Header[] headers, String uri)
    throws IOException {
  method.setURI(new URI(uri, true));
  if (headers != null) {
    for (Header header: headers) {
      method.addRequestHeader(header);
    }
  }
  long startTime = System.currentTimeMillis();
  int code = httpClient.executeMethod(method);
  long endTime = System.currentTimeMillis();
  if (LOG.isDebugEnabled()) {
    LOG.debug(method.getName() + " " + uri + " " + code + " " +
      method.getStatusText() + " in " + (endTime - startTime) + " ms");
  }
  return code;
}
 
开发者ID:lifeng5042,项目名称:RStore,代码行数:26,代码来源:Client.java

示例5: getForObject

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Typical web service client class to get a string representation of the
 * response.
 * 
 * @param requestUrl
 *            Relative request URL
 * @param mapperClass
 *            Class to which the response should cast to.
 * @return JAXB deserialized response
 */
protected Object getForObject( final String requestUrl, Class< ? > mapperClass, String parameters )
{
    Object domainObject = null;
    HttpClient client = new HttpClient();

    try
    {
        PostMethod request = new PostMethod();
        request.setURI( new URI( getAbsoluteUrl( requestUrl + REQUEST_URL_SUFFIX + parameters ), false ) );
        request.addRequestHeader( CONTENT_TYPE, APPLICATION_XML );
        String apiToken = jenkinsClientProperties.getJenkinsApiToken();
        if ( !apiToken.isEmpty() )
        {
            request.setDoAuthentication( true );
        }
        domainObject = sendRequestToJenkins( mapperClass, domainObject, client, request, apiToken );

    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return domainObject;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:36,代码来源:AbstractService.java

示例6: performBuildOperationsViaGet

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Perform build Operations Via GET
 * 
 * @param requestUrl
 *            Relative request URL
 * @param mapperClass
 *            Class to which the response should cast to.
 * @return JAXB deserialized response
 */
protected Object performBuildOperationsViaGet( final String requestUrl, Class< ? > mapperClass )
{
    Object domainObject = null;
    HttpClient client = new HttpClient();
    try
    {
        GetMethod request = new GetMethod();
        request.setURI( new URI( getAbsoluteUrl( requestUrl ), false ) );
        request.addRequestHeader( CONTENT_TYPE, APPLICATION_XML );
        String apiToken = jenkinsClientProperties.getJenkinsApiToken();
        if ( !apiToken.isEmpty() )
        {
            request.setDoAuthentication( true );
        }

        domainObject = sendRequestToJenkins( mapperClass, domainObject, client, request, apiToken );
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return domainObject;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:34,代码来源:AbstractService.java

示例7: getHost

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
private String getHost(HttpMethod httpMethod, Object[] args) {
    try {
        final URI url = httpMethod.getURI();
        if (url.isAbsoluteURI()) {
            return getEndpoint(url.getHost(), url.getPort());
        }

        if (isDebug) {
            logger.debug("URI is not absolute. {}", url.getURI());
        }

        // if not found schema, use httpConnection.
        final HttpConnection httpConnection = getHttpConnection(args);
        if (httpConnection != null) {
            final String host = httpConnection.getHost();
            final int port = getPort(httpConnection);
            return getEndpoint(host, port);
        }
    } catch (URIException e) {
        // unexpected error, perhaps of user fault.
        logger.error("[HttpClient3] Fail get URI", e);
    }

    return null;
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:26,代码来源:HttpMethodBaseExecuteMethodInterceptor.java

示例8: getHttpUrl

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
private String getHttpUrl(String host, int port, URI uri, HttpConnection httpConnection) throws URIException {
    final Protocol protocol = httpConnection.getProtocol();
    if (protocol == null) {
        return uri.getURI();
    }
    final StringBuilder sb = new StringBuilder();
    final String scheme = protocol.getScheme();
    sb.append(scheme).append("://");
    sb.append(host);
    // if port is default port number.
    if (port != SKIP_DEFAULT_PORT) {
        sb.append(':').append(port);
    }
    sb.append(uri.getURI());
    return sb.toString();
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:17,代码来源:HttpMethodBaseExecuteMethodInterceptor.java

示例9: handleCertificateExceptionAndRetry

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
                                                             @NotNull HttpClient client, @NotNull URI uri,
                                                             @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
                                                             throws IOException {
  if (!isCertificateException(e)) {
    throw e;
  }

  if (isTrusted(host)) {
    // creating a special configuration that allows connections to non-trusted HTTPS hosts
    // see the javadoc to EasySSLProtocolSocketFactory for details
    Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, 443, easyHttps);
    String relativeUri = new URI(uri.getPathQuery(), false).getURI();
    // it is important to use relative URI here, otherwise our custom protocol won't work.
    // we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
    // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
    HttpMethod method = methodCreator.convert(relativeUri);
    client.executeMethod(hc, method);
    return method;
  }
  throw e;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:GithubSslSupport.java

示例10: encodeAuthority

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
public static String encodeAuthority(String uri) throws URIException
{
	int start = uri.indexOf("//");
	if(start == -1) return uri;
	start++;
	int end = uri.indexOf("/",start+1);
	if(end == -1) end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String authority= uri.substring(start+1,end);
	String after = uri.substring(end);
	authority = URIUtil.encode(authority, URI.allowed_authority);

	return before+authority+after;
}
 
开发者ID:apache,项目名称:airavata,代码行数:17,代码来源:URIUtils.java

示例11: encodePath

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
public static String encodePath(String uri) throws URIException
{
	int doubleSlashIndex = uri.indexOf("//");
	boolean hasAuthority =  doubleSlashIndex >= 0;
	int start = -1;
	if(hasAuthority)
	{
		start = uri.indexOf("/",doubleSlashIndex+2);
	}
	else
	{
		start = uri.indexOf(":");
	}
	if(start == -1) return uri;
	
	int end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String path= uri.substring(start+1,end);
	String after = uri.substring(end);
	path = URIUtil.encode(path, URI.allowed_abs_path);
	return before+path+after;
}
 
开发者ID:apache,项目名称:airavata,代码行数:25,代码来源:URIUtils.java

示例12: testParamValidity_GetLogCollection

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
@Test
public void testParamValidity_GetLogCollection() throws Exception {
    //Mandatory only
    URI uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, null).getURI();
    assertContainsURLParam(uri, "datasetid", datasetId);
    assertDoesntContainURLParam(uri, "mosaicsvc");

    //Optional Params
    uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, true).getURI();
    assertContainsURLParam(uri, "datasetid", datasetId);
    assertContainsURLParam(uri, "mosaicsvc", "yes");

    uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, false).getURI();
    assertContainsURLParam(uri, "datasetid", datasetId);
    assertContainsURLParam(uri, "mosaicsvc", "no");
}
 
开发者ID:AuScope,项目名称:detcrc-portal,代码行数:17,代码来源:TestNVCLDataServiceMethodMaker.java

示例13: testYilgarnGeochemistryFilter

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Test doing geochemistry filter and getting all values
 */
@Test
public void testYilgarnGeochemistryFilter() throws Exception{
    final String kmlBlob = "kmlBlob";
    final String serviceUrl = "http://service/wfs";
    final String geologicName = "filter info";
    final int maxFeatures = 0;
    final String bbox = null;
    final String expectedGML = "<gml/>";

    context.checking(new Expectations() {{
        oneOf(mockWfsService).getWfsResponseAsKml(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with(equal((String)null)));will(returnValue(new WFSTransformedResponse(expectedGML, kmlBlob, mockMethod)));

        allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
    }});
    ModelAndView modelAndView = controller.doYilgarnGeochemistryFilter(serviceUrl, geologicName, bbox, maxFeatures);
    Assert.assertNotNull(modelAndView);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertEquals(true, model.get("success"));
    Assert.assertNotNull(model.get("data"));
}
 
开发者ID:AuScope,项目名称:detcrc-portal,代码行数:24,代码来源:TestYilgarnGeochemistryController.java

示例14: testYilgarnGeochemistryFilterCount

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Test doing geochemistry filter and getting the count of all values
 */
@Test
public void testYilgarnGeochemistryFilterCount() throws Exception{
    final String serviceUrl = "http://service/wfs";
    final String geologicName = "filter info";
    final int maxFeatures = 134;
    final String bbox = null;
    final int numberOfFeatures = 123;

    context.checking(new Expectations() {{
        oneOf(mockWfsService).getWfsFeatureCount(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with((String) null));will(returnValue(new WFSCountResponse(numberOfFeatures)));

        allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
    }});
    ModelAndView modelAndView = controller.doYilgarnGeochemistryCount(serviceUrl, geologicName, bbox, maxFeatures);
    Assert.assertNotNull(modelAndView);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertEquals(true, model.get("success"));
    Assert.assertNotNull(model.get("data"));
    Assert.assertEquals(new Integer(numberOfFeatures), model.get("data"));
}
 
开发者ID:AuScope,项目名称:detcrc-portal,代码行数:24,代码来源:TestYilgarnGeochemistryController.java

示例15: testYilgarnGeochemistryFilterCountError

import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
 * Test doing geochemistry filter and getting the count of all values fails gracefully
 */
@Test
public void testYilgarnGeochemistryFilterCountError() throws Exception{
    final String serviceUrl = "http://service/wfs";
    final String geologicName = "filter info";
    final int maxFeatures = 134;
    final String bbox = null;

    context.checking(new Expectations() {{
        oneOf(mockWfsService).getWfsFeatureCount(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with((String) null));will(throwException(new PortalServiceException(mockMethod, new ConnectException())));

        allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
    }});
    ModelAndView modelAndView = controller.doYilgarnGeochemistryCount(serviceUrl, geologicName, bbox, maxFeatures);
    Assert.assertNotNull(modelAndView);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertEquals(false, model.get("success"));
}
 
开发者ID:AuScope,项目名称:detcrc-portal,代码行数:21,代码来源:TestYilgarnGeochemistryController.java


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