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:com.smartitengineering.util.rest.client.jersey.cache.CustomApacheHttpClientResponseResolver.java

/**
 * Determines the HttpClient's request method from the HTTPMethod enum.
 *
 * @param method     the HTTPCache enum that determines
 * @param requestURI the request URI.//from  w ww  . java2  s  .  com
 * @return a new HttpMethod subclass.
 */
protected HttpMethod getMethod(HTTPMethod method, URI requestURI) {
    if (CONNECT.equals(method)) {
        HostConfiguration config = new HostConfiguration();
        config.setHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
        return new ConnectMethod(config);
    } else if (DELETE.equals(method)) {
        return new CustomHttpMethod(HTTPMethod.DELETE.name(), requestURI.toString());
    } else if (GET.equals(method)) {
        return new GetMethod(requestURI.toString());
    } else if (HEAD.equals(method)) {
        return new HeadMethod(requestURI.toString());
    } else if (OPTIONS.equals(method)) {
        return new OptionsMethod(requestURI.toString());
    } else if (POST.equals(method)) {
        return new PostMethod(requestURI.toString());
    } else if (PUT.equals(method)) {
        return new PutMethod(requestURI.toString());
    } else if (TRACE.equals(method)) {
        return new TraceMethod(requestURI.toString());
    } else {
        return new CustomHttpMethod(method.name(), requestURI.toString());
    }
}

From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java

@Override
public String getDefaultUri() {
    final DestinationProvider destinationProvider = this.getDestinationProvider();
    if (destinationProvider != null) {
        final URI uri = destinationProvider.getDestination();
        if (uri == null) {
            return null;
        }/* w  w w . j a  v  a  2  s.  co m*/

        if (portOverride == null) {
            return uri.toString();
        }

        final URI overridenUri;
        try {
            overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride,
                    uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e);
            return uri.toString();
        }

        return overridenUri.toString();
    }

    return null;
}

From source file:org.epics.archiverappliance.retrieval.channelarchiver.ChannelArchiverReadOnlyPlugin.java

private List<Callable<EventStream>> getDataForPV(BasicContext context, String pvName, Timestamp startTime,
        Timestamp endTime, int archiveKey, PostProcessor postProcessor) throws IOException {
    try {// w  w  w.  java2  s  .co  m
        // TODO the only thing that seems to get similar charts in ArchiveViewer for production data is using plot-binning.
        // This is hardcoded somewhere in the Data server or the ArchiveViewer code....
        // Need to figure out where it and and how to address it.
        String howStr = "3";
        String pvNameForCall = pvName;
        if (context.getPvNameFromRequest() != null) {
            logger.info("Using pvName from request " + context.getPvNameFromRequest()
                    + " when making a call to the ChannelArchiver for pv " + pvName);
            pvNameForCall = context.getPvNameFromRequest();
        }

        String archiveValuesStr = new String("<?xml version=\"1.0\"?>\n" + "<methodCall>\n"
                + "<methodName>archiver.values</methodName>\n" + "<params>\n" + "<param><value><i4>"
                + archiveKey + "</i4></value></param>\n" + "<param><value><array><data><value><string>"
                + pvNameForCall + "</string></value></data></array></value></param>\n" + "<param><value><i4>"
                + TimeUtils.convertToEpochSeconds(startTime) + "</i4></value></param>\n" + "<param><value><i4>"
                + startTime.getNanos() + "</i4></value></param>\n" + "<param><value><i4>"
                + TimeUtils.convertToEpochSeconds(endTime) + "</i4></value></param>\n" + "<param><value><i4>"
                + endTime.getNanos() + "</i4></value></param>\n" + "<param><value><i4>" + valuesRequested
                + "</i4></value></param>\n" + "<param><value><i4>" + howStr + "</i4></value></param>\n"
                + "</params>\n" + "</methodCall>\n");
        URI serverURI = new URI(serverURL);
        if (serverURI.getScheme().equals("file")) {
            logger.info("Using a file provider for Channel Archiver data - this better be a unit test.");
            // We use the file scheme for unit testing... Yeah, the extensions are hardcoded...
            InputStream is = new BufferedInputStream(
                    new FileInputStream(new File(serverURI.getPath() + File.separator + pvName + ".xml")));
            // ArchiverValuesHandler takes over the burden of closing the input stream.
            ArchiverValuesHandler handler = new ArchiverValuesHandler(pvName, is,
                    serverURL.toString() + "\n" + archiveValuesStr, context.getRetrievalExpectedDBRType());
            if (postProcessor != null) {
                return CallableEventStream.makeOneStreamCallableList(handler, postProcessor, true);
            } else {
                return CallableEventStream.makeOneStreamCallableList(handler);
            }
        } else {
            StringEntity archiverValues = new StringEntity(archiveValuesStr, ContentType.APPLICATION_XML);
            if (logger.isDebugEnabled()) {
                logger.debug(getDescription() + " making call to channel archiver with " + archiveValuesStr);
            }

            CloseableHttpClient httpclient = HttpClients.createDefault();
            HttpPost postMethod = new HttpPost(serverURL);
            postMethod.addHeader("Content-Type", "text/xml");
            postMethod.setEntity(archiverValues);
            if (logger.isDebugEnabled()) {
                logger.debug("About to make a POST with " + archiveValuesStr);
            }
            HttpResponse response = httpclient.execute(postMethod);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode >= 200 && statusCode <= 206) {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    logger.debug("Obtained a HTTP entity of length " + entity.getContentLength());
                    // ArchiverValuesHandler takes over the burden of closing the input stream.
                    InputStream is = entity.getContent();
                    ArchiverValuesHandler handler = new ArchiverValuesHandler(pvName, is,
                            serverURL.toString() + "\n" + archiveValuesStr,
                            context.getRetrievalExpectedDBRType());
                    if (postProcessor != null) {
                        return CallableEventStream.makeOneStreamCallableList(handler, postProcessor, true);
                    } else {
                        return CallableEventStream.makeOneStreamCallableList(handler);
                    }
                } else {
                    throw new IOException("HTTP response did not have an entity associated with it");
                }
            } else {
                logger.error("Got an invalid status code " + statusCode + " from the server " + serverURL
                        + " for PV " + pvName + " so returning null");
                return null;
            }
        }
    } catch (UnsupportedEncodingException ex) {
        throw new IOException("Exception making call to Channel Archiver", ex);
    } catch (URISyntaxException e) {
        throw new IOException("Invalid URL " + serverURL, e);
    }
}

From source file:com.github.joelittlejohn.embedmongo.StartMojo.java

public IProxyFactory getProxyFactory(Settings settings) {
    URI downloadUri = URI.create(downloadPath);
    final String downloadHost = downloadUri.getHost();
    final String downloadProto = downloadUri.getScheme();

    if (settings.getProxies() != null) {
        for (org.apache.maven.settings.Proxy proxy : (List<org.apache.maven.settings.Proxy>) settings
                .getProxies()) {/* www  .  j a v a  2s.com*/
            if (proxy.isActive() && equalsIgnoreCase(proxy.getProtocol(), downloadProto)
                    && !contains(proxy.getNonProxyHosts(), downloadHost)) {
                return new HttpProxyFactory(proxy.getHost(), proxy.getPort());
            }
        }
    }

    return new NoProxyFactory();
}

From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java

String getWebAppRootURI() {
    final URI currentUri = UI.getCurrent().getPage().getLocation();
    String instancePrefix = currentUri.getScheme() + "://" + currentUri.getHost();
    if (currentUri.getPort() > -1) {
        instancePrefix += ":" + currentUri.getPort();
    }// w w w.j  a va2  s .  c o m
    instancePrefix += currentUri.getPath(); // Path contains the ctx
    if (StringUtils.isNotBlank(currentUri.getQuery())) {
        instancePrefix += "?" + currentUri.getQuery();
    }
    return instancePrefix;
}

From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java

License:asdf

@Test
public void testURI() {
    try {// w  ww.j  a va  2s . c  o m
        URI uri = new URI(
                "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef");
        System.out.println(uri.getScheme());
        System.out.println(uri.getHost());
        System.out.println(uri.getPort());
        System.out.println(uri.getQuery());
        System.out.println(uri.getPath());
    } catch (URISyntaxException ex) {
        Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111";
    URI uri;
    while (true) {
        try {
            uri = new URI(illegalQuery);
        } catch (URISyntaxException ex) {
            System.out.println(illegalQuery);
            System.out.println(illegalQuery.charAt(ex.getIndex()));
            System.out.println(illegalQuery.substring(0, ex.getIndex()));
            System.out.println(illegalQuery.substring(ex.getIndex() + 1));
            try {
                illegalQuery = illegalQuery.substring(0, ex.getIndex())
                        + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8")
                        + illegalQuery.substring(ex.getIndex() + 1);
            } catch (UnsupportedEncodingException ex1) {
            }
            System.out.println(illegalQuery);
            continue;
        }
        break;
    }
    System.out.println("SCHEME: " + uri.getScheme());
    System.out.println("HOST: " + uri.getHost());
    System.out.println("path: " + uri.getRawPath());
    System.out.println("query: " + uri.getRawQuery());
    System.out.println("PORT: " + uri.getPort());
}

From source file:com.qwazr.utils.json.client.JsonClientAbstract.java

protected JsonClientAbstract(String url, Integer msTimeOut, Credentials credentials) throws URISyntaxException {
    this.url = url;
    URI u = new URI(url);
    String path = u.getPath();//ww w  . j a  v a 2  s .co m
    if (path != null && path.endsWith("/"))
        u = new URI(u.getScheme(), null, u.getHost(), u.getPort(), path.substring(0, path.length() - 1),
                u.getQuery(), u.getFragment());
    this.scheme = u.getScheme() == null ? "http" : u.getScheme();
    this.host = u.getHost();
    this.fragment = u.getFragment();
    this.path = u.getPath();
    this.port = u.getPort() == -1 ? 80 : u.getPort();
    this.timeout = msTimeOut == null ? DEFAULT_TIMEOUT : msTimeOut;
    this.executor = credentials == null ? Executor.newInstance() : Executor.newInstance().auth(credentials);

}

From source file:com.subgraph.vega.internal.http.proxy.VegaHttpRequestParser.java

@Override
public HttpMessage parse() throws IOException, HttpException {
    RequestLine requestLine;// w w  w. j  a  v a2 s. co  m
    try {
        requestLine = parseRequestLine(sessionBuffer);
    } catch (ParseException px) {
        throw new ProtocolException(px.getMessage(), px);
    }

    List<CharArrayBuffer> headerLines = new ArrayList<CharArrayBuffer>();
    Header[] headers = AbstractMessageParser.parseHeaders(sessionBuffer, maxHeaderCount, maxLineLen, lineParser,
            headerLines);

    if (conn.isSslConnection()) {
        URI uri;
        try {
            uri = new URI(requestLine.getUri());
        } catch (URISyntaxException e) {
            throw new ProtocolException("Invalid URI: " + requestLine.getUri(), e);
        }
        if (uri.getScheme() == null) {
            final Header hostHeader = getFirstHeader(headers, HTTP.TARGET_HOST);
            final StringBuilder buf = new StringBuilder();
            if (hostHeader != null) {
                // REVISIT: does using the Host header value instead of the SSL host risk opening another connection?
                buf.append("https://");
                buf.append(hostHeader.getValue());
            } else {
                buf.append(conn.getSslHost().toURI());
            }
            buf.append(uri.getRawPath());
            if (uri.getRawQuery() != null) {
                buf.append("?");
                buf.append(uri.getRawQuery());
            }

            requestLine = new BasicRequestLine(requestLine.getMethod(), buf.toString(),
                    requestLine.getProtocolVersion());
        }
    }

    HttpMessage message = requestFactory.newHttpRequest(requestLine);
    message.setHeaders(headers);
    return message;
}

From source file:org.taverna.server.master.interaction.InteractionFeedSupport.java

@Nullable
public URL getLocalFeedBase(URI feedURI) {
    if (feedURI == null)
        return null;
    return endPoints.get(feedURI.getScheme());
}

From source file:com.mesosphere.dcos.cassandra.executor.backup.S3StorageDriver.java

String getEndpoint(BackupRestoreContext ctx) throws URISyntaxException {
    URI uri = new URI(ctx.getExternalLocation());
    String scheme = uri.getScheme();
    if (scheme.equals(AmazonS3Client.S3_SERVICE_NAME)) {
        return Constants.S3_HOSTNAME;
    } else {//  www.  ja va  2s. com
        String endpoint = scheme + "://" + uri.getHost();

        int port = uri.getPort();
        if (port != -1) {
            endpoint += ":" + Integer.toString(port);
        }

        return endpoint;
    }
}