當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。