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.mcxiaoke.commons.http.util.URIBuilderEx.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), URIUtilsEx.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:com.jaeksoft.searchlib.crawler.database.DatabaseCrawlMongoDb.java

@Override
public String test() throws Exception {
    URI uri = new URI(getUrl());
    StringBuilder sb = new StringBuilder();
    if (!"mongodb".equals(uri.getScheme()))
        throw new SearchLibException(
                "Wrong scheme: " + uri.getScheme() + ". The URL should start with: mongodb://");
    MongoClient mongoClient = null;/*from w w w .j  a  v a 2 s  . c om*/
    try {
        mongoClient = getMongoClient();
        sb.append("Connection established.");
        sb.append(StringUtils.LF);
        if (!StringUtils.isEmpty(databaseName)) {
            MongoDatabase db = mongoClient.getDatabase(databaseName);
            if (db == null)
                throw new SearchLibException("Database not found: " + databaseName);
            MongoIterable<String> collections = db.listCollectionNames();
            if (collections == null)
                throw new SearchLibException("No collection found.");
            sb.append("Collections found:");
            sb.append(StringUtils.LF);
            for (String collection : collections) {
                sb.append(collection);
                sb.append(StringUtils.LF);
            }
            if (!StringUtils.isEmpty(collectionName)) {
                MongoCollection<?> dbCollection = db.getCollection(collectionName);
                if (dbCollection == null)
                    throw new SearchLibException("Collection " + collectionName + " not found.");
                sb.append(
                        "Collection " + collectionName + " contains " + dbCollection.count() + " document(s).");
                sb.append(StringUtils.LF);
                if (!StringUtils.isEmpty(criteria)) {
                    long count = dbCollection.count(getCriteriaObject());
                    sb.append("Query returns " + count + " document(s).");
                    sb.append(StringUtils.LF);
                }
            }
        }
    } finally {
        if (mongoClient != null)
            mongoClient.close();
    }
    return sb.toString();
}

From source file:cross.io.InputDataFactory.java

@Override
public TupleND<IFileFragment> prepareInputData(String[] input) {
    if (input == null || input.length == 0) {
        throw new ExitVmException("No input data given, aborting!");
    }/*from  ww  w  . j  a v a 2s  .c  o  m*/
    log.info("Preparing input data!");
    log.debug("Received paths: {}", Arrays.toString(input));
    this.initialFiles = new ArrayList<>();
    for (String s : input) {
        File inputFile = new File(s);
        URI uri = null;
        if (inputFile.isFile() && inputFile.exists()) {
            uri = inputFile.toURI();
        } else {
            uri = URI.create(FileTools.escapeUri(s));
        }
        if (uri.getScheme() != null) {
            this.initialFiles.add(new FileFragment(uri));
        } else {
            for (File f : getInputFiles(new String[] { s })) {
                log.info("Adding file {}", f.getAbsolutePath());
                initialFiles.add(new FileFragment(f.toURI()));
            }
        }
    }

    if (initialFiles.isEmpty()) {
        throw new ExitVmException("Could not create input data for files " + Arrays.toString(input));
    }
    return new TupleND<>(initialFiles);
}

From source file:com.spotify.scio.util.RemoteFileUtil.java

private Path downloadImpl(URI src) {
    try {/* w w  w  .j  a v  a 2  s.  c  om*/
        Path dst = getDestination(src);

        if (src.getScheme() == null || src.getScheme().equals("file")) {
            // Local URI
            Path srcPath = src.getScheme() == null ? Paths.get(src.toString()) : Paths.get(src);
            if (Files.isSymbolicLink(dst) && Files.readSymbolicLink(dst).equals(srcPath)) {
                LOG.info("URI {} already symlink-ed", src);
            } else {
                Files.createSymbolicLink(dst, srcPath);
                LOG.info("Symlink-ed {} to {}", src, dst);
            }
        } else {
            // Remote URI
            long srcSize = getRemoteSize(src);
            boolean shouldDownload = true;
            if (Files.exists(dst)) {
                long dstSize = Files.size(dst);
                if (srcSize == dstSize) {
                    LOG.info("URI {} already downloaded", src);
                    shouldDownload = false;
                } else {
                    LOG.warn("Destination exists with wrong size. {} [{}B] -> {} [{}B]", src, srcSize, dst,
                            dstSize);
                    Files.delete(dst);
                }
            }
            if (shouldDownload) {
                copyToLocal(src, dst);
                LOG.info("Downloaded {} -> {} [{}B]", src, dst, srcSize);
            }
        }

        return dst;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

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

String getBucketName(BackupRestoreContext ctx) throws URISyntaxException {
    URI uri = new URI(ctx.getExternalLocation());
    LOGGER.info("URI: " + uri);
    if (uri.getScheme().equals(AmazonS3Client.S3_SERVICE_NAME)) {
        return uri.getHost();
    } else {/*from   w ww.j  av a2  s.c  om*/
        return uri.getPath().split("/")[1];
    }
}

From source file:fr.wseduc.webutils.email.SendInBlueSender.java

public SendInBlueSender(Vertx vertx, Container container, JsonObject config)
        throws InvalidConfigurationException, URISyntaxException {
    super(vertx, container);
    if (config != null && isNotEmpty(config.getString("uri")) && isNotEmpty(config.getString("api-key"))) {
        URI uri = new URI(config.getString("uri"));
        httpClient = vertx.createHttpClient().setHost(uri.getHost()).setPort(uri.getPort()).setMaxPoolSize(16)
                .setSSL("https".equals(uri.getScheme())).setKeepAlive(false);
        apiKey = config.getString("api-key");
        dedicatedIp = config.getString("ip");
        splitRecipients = config.getBoolean("split-recipients", false);
        mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    } else {//w  w w  .  jav a2  s  .  co  m
        throw new InvalidConfigurationException("missing.parameters");
    }
}

From source file:eu.openanalytics.rsb.component.EmailDepositHandler.java

@PostConstruct
public void setupChannelAdapters() throws URISyntaxException {
    final List<DepositEmailConfiguration> depositEmailConfigurations = getConfiguration()
            .getDepositEmailAccounts();/*from  www  .  j  a  va 2 s  .c o  m*/

    if ((depositEmailConfigurations == null) || (depositEmailConfigurations.isEmpty())) {
        return;
    }

    for (final DepositEmailConfiguration depositEmailConfiguration : depositEmailConfigurations) {
        final PeriodicTrigger trigger = new PeriodicTrigger(depositEmailConfiguration.getPollingPeriod(),
                TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(5000L);

        AbstractMailReceiver mailReceiver = null;

        final URI emailAccountURI = depositEmailConfiguration.getAccountURI();
        if (StringUtils.equals(emailAccountURI.getScheme(), "pop3")) {
            mailReceiver = new Pop3MailReceiver(emailAccountURI.toString());
        } else if (StringUtils.equals(emailAccountURI.getScheme(), "imap")) {
            mailReceiver = new ImapMailReceiver(emailAccountURI.toString());
            ((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(true);
        } else {
            throw new IllegalArgumentException("Invalid email account URI: " + emailAccountURI);
        }

        mailReceiver.setBeanFactory(beanFactory);
        mailReceiver.setBeanName("rsb-email-ms-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        mailReceiver.setShouldDeleteMessages(true);
        mailReceiver.setMaxFetchSize(1);
        mailReceiver.afterPropertiesSet();
        final MailReceivingMessageSource fileMessageSource = new MailReceivingMessageSource(mailReceiver);
        final HeaderSettingMessageSourceWrapper<javax.mail.Message> messageSource = new HeaderSettingMessageSourceWrapper<javax.mail.Message>(
                fileMessageSource, EMAIL_CONFIG_HEADER_NAME, depositEmailConfiguration);

        final SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter();
        channelAdapter.setBeanFactory(beanFactory);
        channelAdapter.setBeanName("rsb-email-ca-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        channelAdapter.setOutputChannel(emailDepositChannel);
        channelAdapter.setSource(messageSource);
        channelAdapter.setTrigger(trigger);
        channelAdapter.afterPropertiesSet();
        channelAdapter.start();

        getLogger().info("Started channel adapter: " + channelAdapter);

        channelAdapters.add(channelAdapter);
    }
}

From source file:org.droidparts.http.CookieJar.java

private List<Cookie> parseCookies(URI uri, List<String> cookieHeaders) {
    ArrayList<Cookie> cookies = new ArrayList<Cookie>();
    int port = (uri.getPort() < 0) ? 80 : uri.getPort();
    boolean secure = "https".equals(uri.getScheme());
    CookieOrigin origin = new CookieOrigin(uri.getHost(), port, uri.getPath(), secure);
    for (String cookieHeader : cookieHeaders) {
        BasicHeader header = new BasicHeader(SM.SET_COOKIE, cookieHeader);
        try {//from  ww  w. j  a  va  2  s  . co m
            cookies.addAll(cookieSpec.parse(header, origin));
        } catch (MalformedCookieException e) {
            L.d(e);
        }
    }
    return cookies;
}

From source file:com.mirth.connect.connectors.ws.WebServiceMessageDispatcher.java

/**
 * Returns the URL for the passed in String. If the URL requires
 * authentication, then the WSDL is saved as a temp file and the URL for
 * that file is returned.//www  . ja  va2  s.c o  m
 * 
 * @param wsdlUrl
 * @param username
 * @param password
 * @return
 * @throws Exception
 */
private URL getWsdlUrl(String wsdlUrl, String username, String password) throws Exception {
    URI uri = new URI(wsdlUrl);

    // If the URL points to file, just return it
    if (!uri.getScheme().equalsIgnoreCase("file")) {
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(wsdlUrl);

        int status = client.executeMethod(method);
        if ((status == HttpStatus.SC_UNAUTHORIZED) && (username != null) && (password != null)) {
            client.getState().setCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(username, password));
            status = client.executeMethod(method);

            if (status == HttpStatus.SC_OK) {
                String wsdl = method.getResponseBodyAsString();
                File tempFile = File.createTempFile("WebServiceSender", ".wsdl");
                tempFile.deleteOnExit();

                FileUtils.writeStringToFile(tempFile, wsdl);

                return tempFile.toURI().toURL();
            }
        }
    }

    return uri.toURL();
}