Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

In this page you can find the example usage for java.net URI getScheme.

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:org.fishwife.jrugged.httpclient.PerHostServiceWrappedHttpClient.java

private HttpHost getCanonicalHost(HttpHost host) {
    URI uri;
    try {/*from w ww .  ja v  a 2s. com*/
        uri = new URI(host.toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    String hostname = uri.getHost();
    int port = uri.getPort();
    String scheme = uri.getScheme();
    boolean isHttps = "HTTPS".equalsIgnoreCase(scheme);
    String schemePart = isHttps ? (scheme + "://") : "";
    if (port == -1) {
        port = isHttps ? 443 : 80;
    }
    return new HttpHost(schemePart + hostname + ":" + port);
}

From source file:com.qualogy.qafe.bind.io.Reader.java

/**
 * @deprecated: This method is a nasty hack to get the root path to pass it
 *              to the unmarshallingcontext. The nastiest of all that this
 *              method is called with the first string path passed to the
 *              reader assuming this file is in the root.
 * @param string//from   w  w  w  .j a va 2  s .  c o  m
 * @return
 */
private String getApplicationRoot(URI fileName) {
    String path = null;
    if (fileName.getScheme().equals(FileLocation.SCHEME_FILE)) {
        File file = new File(fileName);

        if (file.exists()) {
            path = file.getAbsolutePath();
            String name = file.getName();
            path = path.substring(0, path.length() - name.length());
            path = path.replace('\\', File.separatorChar);
        }
    } else {
        path = fileName.toString();
    }
    return path;
}

From source file:mitm.common.security.crl.HTTPCRLDownloadHandler.java

@Override
public boolean canHandle(URI uri) {
    Check.notNull(uri, "uri");

    String scheme = uri.getScheme();

    return scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"));
}

From source file:org.wso2.carbon.http2.transport.util.Http2ConnectionFactory.java

/**
 * Generate hash-key for each clientHandler using uri
 *
 * @param uri/*w  w  w .j a  va  2s.  c  o m*/
 * @return
 */
private String generateKey(URI uri) {
    String host = uri.getHost();
    int port = uri.getPort();
    String ssl;
    if (uri.getScheme().equalsIgnoreCase(Http2Constants.HTTPS2) || uri.getScheme().equalsIgnoreCase("https")) {
        ssl = "https://";
    } else
        ssl = "http://";
    return ssl + host + ":" + port;
}

From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java

/**
 * Append the signedString to the uri.//w w  w. j  a va  2s  . co m
 * 
 * @param uri
 * @param signedString
 * @return The uri after be appended with signedString.
 */
private URI appendSignString(URI uri, String signedString) {
    try {
        return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(),
                HttpUtilities.getNormalizePath(uri),
                (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + "&" + signedString,
                uri.getFragment());
    } catch (URISyntaxException e) {
        Logger.error("", e);
    }
    return uri;
}

From source file:com.alibaba.dubbo.rpc.protocol.springmvc.support.ApacheHttpClient.java

HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
        throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
    RequestBuilder requestBuilder = RequestBuilder.create(request.method());

    //per request timeouts
    //    RequestConfig requestConfig = RequestConfig
    //            .custom()
    //            .setConnectTimeout(options.connectTimeoutMillis())
    //            .setSocketTimeout(options.readTimeoutMillis())
    //            .build();
    //requestBuilder.setConfig(requestConfig);

    URI uri = new URIBuilder(request.url()).build();

    requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath());

    //request query params
    List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name());
    for (NameValuePair queryParam : queryParams) {
        requestBuilder.addParameter(queryParam);
    }/*from  w  ww.java  2s.c o  m*/

    //request headers
    boolean hasAcceptHeader = false;
    for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) {
        String headerName = headerEntry.getKey();
        if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) {
            hasAcceptHeader = true;
        }

        if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) {
            // The 'Content-Length' header is always set by the Apache client and it
            // doesn't like us to set it as well.
            continue;
        }

        for (String headerValue : headerEntry.getValue()) {
            requestBuilder.addHeader(headerName, headerValue);
        }
    }
    //some servers choke on the default accept string, so we'll set it to anything
    if (!hasAcceptHeader) {
        requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*");
    }

    //request body
    if (request.body() != null) {
        HttpEntity entity = null;
        if (request.charset() != null) {
            ContentType contentType = getContentType(request);
            String content = new String(request.body(), request.charset());
            entity = new StringEntity(content, contentType);
        } else {
            entity = new ByteArrayEntity(request.body());
        }

        requestBuilder.setEntity(entity);
    }

    return requestBuilder.build();
}

From source file:com.buaa.cfs.utils.NetUtils.java

/**
 * Resolve the uri's hostname and add the default port if not in the uri
 *
 * @param uri         to resolve/*from ww w. j a  v  a2  s  . c  o m*/
 * @param defaultPort if none is given
 *
 * @return URI
 */
public static URI getCanonicalUri(URI uri, int defaultPort) {
    // skip if there is no authority, ie. "file" scheme or relative uri
    String host = uri.getHost();
    if (host == null) {
        return uri;
    }
    String fqHost = canonicalizeHost(host);
    int port = uri.getPort();
    // short out if already canonical with a port
    if (host.equals(fqHost) && port != -1) {
        return uri;
    }
    // reconstruct the uri with the canonical host and port
    try {
        uri = new URI(uri.getScheme(), uri.getUserInfo(), fqHost, (port == -1) ? defaultPort : port,
                uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return uri;
}

From source file:de.kp.ames.http.HttpClient.java

/**
 * @param url//from   w  w w  .  ja v  a2s  . c o  m
 * @return
 * @throws Exception
 */
private URI createUri(String url) throws Exception {

    URI uri = new URI(url);
    String protocol = uri.getScheme();

    if (protocol.equals(HTTPS_NAME) == false)
        throw new Exception("[HttpClient] This protocol is not supported.");

    return uri;

}

From source file:org.bndtools.rt.repository.server.RepositoryResourceComponent.java

@GET
@Path("index")
@Produces(MediaType.APPLICATION_XML)//from  www . ja  v  a2s  . c  om
public Response getIndex(@Context HttpHeaders headers) throws Exception {
    List<URI> locations = repo.getIndexLocations();
    if (locations.isEmpty())
        return Response.serverError().entity("No index available").build();

    Response response;
    URI location = locations.get(0);
    if ("file".equals(location.getScheme())) {
        File file = new File(location);

        @SuppressWarnings("resource")
        FileInputStream indexStream = new FileInputStream(file);
        InputStream bufferedStream = indexStream.markSupported() ? indexStream
                : new BufferedInputStream(indexStream);

        InputStream responseStream;
        if (isGZip(bufferedStream)) {
            responseStream = new GZIPInputStream(indexStream);
        } else {
            responseStream = bufferedStream;
        }
        response = Response.ok(responseStream, MediaType.APPLICATION_XML_TYPE).build();
    } else {
        response = Response.status(Status.SEE_OTHER).location(location).build();
    }
    return response;
}