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:gov.nih.nci.caarray.application.fileaccess.FileAccessServiceStub.java

private void checkScheme(URI handle) {
    if (!SCHEME.equals(handle.getScheme())) {
        throw new UnsupportedSchemeException("Unsupported scheme: " + handle.getScheme());
    }/*from  w ww  .ja v a2  s. com*/
}

From source file:net.gplatform.sudoor.server.cors.CorsFilter.java

/**
 * Checks if a given origin is valid or not. Criteria:
 * <ul>// w  w w .j a  v a 2 s.c o m
 * <li>If an encoded character is present in origin, it's not valid.</li>
 * <li>Origin should be a valid {@link URI}</li>
 * </ul>
 * 
 * @param origin
 * @see <a href="http://tools.ietf.org/html/rfc952">RFC952</a>
 */
protected static boolean isValidOrigin(String origin) {
    //Changed by Shark to support origin file:// & null
    if ("file://".equals(origin) || "null".equals(origin)) {
        return true;
    }

    // Checks for encoded characters. Helps prevent CRLF injection.
    if (origin.contains("%")) {
        return false;
    }

    URI originURI;

    try {
        originURI = new URI(origin);
    } catch (URISyntaxException e) {
        return false;
    }
    // If scheme for URI is null, return false. Return true otherwise.
    return originURI.getScheme() != null;

}

From source file:com.jaeksoft.searchlib.scheduler.task.TaskFileCrawlerEvent.java

@Override
public void execute(Client client, TaskProperties properties, Variables variables, TaskLog taskLog)
        throws SearchLibException, IOException, InterruptedException {
    taskLog.setInfo("File crawler event started");

    String filePath = properties.getValue(propFilePathItem);
    String directoryURL = properties.getValue(propDirectoryURL);
    String logFilePattern = properties.getValue(propLogFilePattern);
    String domain = properties.getValue(propDomain);
    String login = properties.getValue(propLogin);
    String password = properties.getValue(propPassword);

    FilePathItem filePathItem = client.getFilePathManager().find(filePath);
    if (filePathItem == null)
        throw new SearchLibException("File path item not found: " + filePath);

    final FilePathItem fpi;
    URI srcURI;
    try {//from   www . j  av a2 s.  c  om
        srcURI = new URI(directoryURL);

        String scheme = srcURI.getScheme();
        if (scheme.equals("smb")) {
            fpi = new FilePathItem(client);
            fpi.setType(FileInstanceType.Smb);
            fpi.setHost(srcURI.getHost());
            if (domain != null)
                fpi.setDomain(domain);
            if (login != null)
                fpi.setUsername(login);
            if (password != null)
                fpi.setPassword(password);
        } else if (scheme.equals("file")) {
            fpi = new FilePathItem(client);
            fpi.setType(FileInstanceType.Local);
        } else
            throw new SearchLibException("Unsupported scheme: " + scheme);
        int count = 0;
        FileInstanceAbstract fileInstanceSource = FileInstanceAbstract.create(fpi, null, srcURI.getPath());
        FileInstanceAbstract[] fileInstances = fileInstanceSource.listFilesOnly();
        if (fileInstances == null)
            return;
        for (FileInstanceAbstract fileInstance : fileInstances) {
            if (!StringUtils.isEmpty(logFilePattern))
                if (!FilenameUtils.wildcardMatch(fileInstance.getFileName(), logFilePattern))
                    continue;
            count++;
            taskLog.setInfo("Extract #" + count + ": " + fileInstance.getURL());
            InputStream is = fileInstance.getInputStream();
            try {
                List<String> lines = IOUtils.readLines(is);
                if (lines == null)
                    continue;
                for (String line : lines) {
                    taskLog.setInfo("Crawl " + fileInstance.getURL());
                    client.getFileCrawlMaster().crawlDirectory(filePathItem, line);
                }
            } catch (NoSuchAlgorithmException e) {
                throw new SearchLibException(e);
            } catch (InstantiationException e) {
                throw new SearchLibException(e);
            } catch (IllegalAccessException e) {
                throw new SearchLibException(e);
            } catch (ClassNotFoundException e) {
                throw new SearchLibException(e);
            } catch (SmbException e) {
                throw new SearchLibException(e);
            } catch (HttpException e) {
                throw new SearchLibException(e);
            } finally {
                IOUtils.closeQuietly(is);
            }
            fileInstance.delete();
        }
        taskLog.setInfo(count + " file(s)");
    } catch (URISyntaxException e) {
        throw new SearchLibException(e);
    }
}

From source file:jp.primecloud.auto.api.ApiFilter.java

/**
 *
 * URI(Signature????)?/*from  w ww  .  java 2  s .  c  o  m*/
 *
 * @param decodeParamMap base64??
 * @param uri URI()
 * @return ???URL(Signature????)
 */
private String createUriQueryParams(LinkedHashMap<String, String> decodeParamMap, URI uri) {
    String baseUriText = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath() + "?";
    StringBuffer uriText = new StringBuffer(baseUriText);
    String splitChar = "";
    for (String key : decodeParamMap.keySet()) {
        if (PARAM_NAME_SIGNATURE.equals(key) == false) {
            uriText.append(splitChar + key + "=" + decodeParamMap.get(key));
            splitChar = "&";
        }
    }
    return uriText.toString();
}

From source file:com.abiquo.abiserver.pojo.service.RemoteService.java

private boolean modifiedUri() {
    try {/*  w w w .j  a  va2s  .  c  om*/
        URI u = new URI(uri);

        return !fixProtocol(u.getScheme()).equals(fixProtocol(protocol)) || !u.getHost().equals(domainName)
                || u.getPort() != port || !StringUtils.isEmpty(u.getPath())
                        && !u.getPath().replaceFirst("/", "").equals(serviceMapping);
    } catch (URISyntaxException e) {
        return true;
    } catch (NullPointerException e) {
        return true;
    }
}

From source file:com.esri.geoportal.commons.http.BotsHttpClient.java

private URI updateURI(URI uri, PHP php) throws URISyntaxException {
    return new URI(php.protocol != null ? php.protocol : uri.getScheme(), uri.getUserInfo(),
            php.host != null ? php.host : uri.getHost(),
            php.host != null ? php.port != null ? php.port : -1 : uri.getPort(), uri.getPath(), uri.getQuery(),
            uri.getFragment());//from   w ww .  j  av  a 2s  . c  o  m
}

From source file:com.groupon.mesos.zookeeper.ZookeeperMasterDetector.java

public ZookeeperMasterDetector(final String master, final ManagedEventBus eventBus) throws IOException {
    checkNotNull(master, "master is null");
    this.eventBus = checkNotNull(eventBus, "eventBus is null");

    final URI zookeeperUri = URI.create(master);
    checkState(zookeeperUri.getScheme().equals("zk"), "Only zk:// URIs are supported (%s)", master);

    String authority = zookeeperUri.getAuthority();
    final int atIndex = authority.indexOf('@');
    if (atIndex != -1) {
        final List<String> userPass = ImmutableList
                .copyOf(Splitter.on(':').trimResults().split(authority.substring(0, atIndex)));
        checkState(userPass.size() == 2, "found %s for user name and password", userPass);
        user = userPass.get(0);/*from w w w  .  j  av  a2 s. c o m*/
        password = userPass.get(1);
        authority = authority.substring(atIndex + 1);
    } else {
        user = null;
        password = null;
    }

    String zookeeperPath = zookeeperUri.getPath();
    while (zookeeperPath.endsWith("/")) {
        zookeeperPath = zookeeperPath.substring(0, zookeeperPath.length() - 1);
    }
    this.zookeeperPath = zookeeperPath;

    checkState(!zookeeperPath.equals(""), "A zookeeper path must be given! (%s)", zookeeperPath);

    checkState(user == null && password == null,
            "Current version of Zkclient does not support authentication!");

    this.client = new ZkClient(authority);
    this.client.setZkSerializer(new MasterInfoZkSerializer());
}

From source file:io.selendroid.server.model.SelendroidNativeDriver.java

public void get(String url) {
    URI dest;
    try {//from  w  w  w . j a  v  a2  s.  co  m
        dest = new URI(url);
    } catch (URISyntaxException exception) {
        throw new IllegalArgumentException(exception);
    }

    if (!"and-activity".equals(dest.getScheme())) {
        throw new SelendroidException("Unrecognized scheme in URI: " + dest.toString());
    } else if (dest.getPath() != null && !dest.getPath().equals("")) {
        throw new SelendroidException("Unrecognized path in URI: " + dest.toString());
    }

    URI currentUri = getCurrentURI();

    if (currentUri != null && dest.getAuthority().endsWith(currentUri.getAuthority())) {
        // ignore request, activity is already open
        return;
    }

    serverInstrumentation.startActivity(dest.getAuthority());
    DefaultSelendroidDriver.sleepQuietly(500);
}

From source file:org.coffeebreaks.validators.nu.NuValidator.java

ValidationResult validateUri(URL url, ValidationRequest request) throws IOException {
    String parser = request.getValue("parser", null);
    HttpRequestBase method;//www .  j  a v a2  s  .  c  o m
    List<NameValuePair> qParams = new ArrayList<NameValuePair>();
    qParams.add(new BasicNameValuePair("out", "json"));
    if (parser != null) {
        qParams.add(new BasicNameValuePair("parser", parser));
    }
    qParams.add(new BasicNameValuePair("doc", url.toString()));

    try {
        URI uri = new URI(baseUrl);
        URI uri2 = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(),
                URLEncodedUtils.format(qParams, "UTF-8"), null);
        method = new HttpGet(uri2);
        return validate(method);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("invalid uri. Check your baseUrl " + baseUrl, e);
    }
}