Example usage for java.net URISyntaxException URISyntaxException

List of usage examples for java.net URISyntaxException URISyntaxException

Introduction

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

Prototype

public URISyntaxException(String input, String reason) 

Source Link

Document

Constructs an instance from the given input string and reason.

Usage

From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java

public static MMapURI editURI(final MindMapDocumentEditor editor, final String title, final MMapURI uri) {
    final UriEditPanel uriEditor = new UriEditPanel(uri == null ? null : uri.asString(false, false));

    uriEditor.doLayout();/*  w  w w. j  a  v a  2 s .com*/
    uriEditor.setPreferredSize(new Dimension(450, uriEditor.getPreferredSize().height));

    if (plainMessageOkCancel(editor.getProject(), title, uriEditor)) {
        final String text = uriEditor.getText();
        if (text.isEmpty()) {
            return EMPTY_URI;
        }
        try {
            if (!new URI(text).isAbsolute())
                throw new URISyntaxException(text, "URI is not absolute one");
            return new MMapURI(text.trim());
        } catch (URISyntaxException ex) {
            editor.getDialogProvider()
                    .msgError(String.format(BUNDLE.getString("NbUtils.errMsgIllegalURI"), text));
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.dataconservancy.packaging.tool.impl.generator.OrePackageModelBuilder.java

private URI getPropertyURI(String pkgDescriptionPropertyName) {

    if (!orePropertyMap.containsKey(pkgDescriptionPropertyName)) {
        try {//from  w  w  w. j  ava 2 s .  com
            URI uri = new URI(pkgDescriptionPropertyName);
            if (uri.getScheme() == null) {
                throw new URISyntaxException(pkgDescriptionPropertyName, "scheme");
            }
            return new URI(pkgDescriptionPropertyName);
        } catch (URISyntaxException e) {
            throw new RuntimeException(
                    pkgDescriptionPropertyName + " is neither a known property name, nor a URI");
        }
    }

    return orePropertyMap.get(pkgDescriptionPropertyName);
}

From source file:org.dataconservancy.packaging.tool.impl.generator.OrePackageModelBuilder.java

private URI getForwardRelationshipURI(String pkgDescriptionRelName) {

    if (!oreForwardRelationshipMap.containsKey(pkgDescriptionRelName)) {
        try {//from   ww w.  j a  v a2  s. c  om
            URI uri = new URI(pkgDescriptionRelName);
            if (uri.getScheme() == null) {
                throw new URISyntaxException(pkgDescriptionRelName, "scheme");
            }

            return uri;
        } catch (URISyntaxException e) {
            throw new RuntimeException(
                    pkgDescriptionRelName + " is neither a known relationship name, nor a URI");
        }
    }

    return oreForwardRelationshipMap.get(pkgDescriptionRelName);
}

From source file:eu.bittrade.libs.steemj.configuration.SteemJConfig.java

/**
 * Configure the connection to the Steem Node by providing the endpoint URI
 * and the SSL verification settings.//from  w  w  w .j a v  a  2 s.c  om
 * 
 * @param endpointURI
 *            The URI of the node you want to connect to.
 * @param sslVerificationDisabled
 *            Define if SteemJ should verify the SSL certificate of the
 *            endpoint. This option will be ignored if the given
 *            <code>endpointURI</code> is using a non SSL protocol.
 * @throws URISyntaxException
 *             If the <code>endpointURI</code> is null.
 */
public void addEndpointURI(URI endpointURI, boolean sslVerificationDisabled) throws URISyntaxException {
    if (endpointURI == null) {
        throw new URISyntaxException("endpointURI", "The endpointURI can't be null.");
    }

    this.endpointURIs.add(new ImmutablePair<URI, Boolean>(endpointURI, sslVerificationDisabled));
}

From source file:com.vmware.appfactory.recipe.controller.RecipeApiController.java

private void writeRecipeFileToZip(Recipe recipe, RecipeFile file, ZipOutputStream zos) throws IOException {
    _log.debug("Writing recipe payload file {}, URI = {}", file.getPath(), file.getURI().toString());

    URI uri = file.getURI();/*  w  w w.  j a va  2 s  .  c  o  m*/
    InputStream is = null;

    try {
        zos.putNextEntry(new ZipEntry(file.getPath()));

        if (uri.getScheme().equals(DsUtil.DATASTORE_URI_SCHEME)) {
            /*
             * Use datastore methods to copy the file from the datastore
             * into the ZIP file.
             */
            Long dsId = Long.valueOf(uri.getHost());
            DsDatastore ds = _dsClient.findDatastore(dsId, true);
            if (ds == null) {
                throw new URISyntaxException(uri.toString(), "Datastore URI has invalid ID " + uri.getHost());
            }

            is = ds.openStream(uri.getPath());
            IOUtils.copy(is, zos);
        } else {
            /*
             * Use regular HTTP methods to copy file from URL into the ZIP file.
             */
            URL url = uri.toURL();
            is = new BufferedInputStream(url.openStream());
            IOUtils.copy(is, zos);
        }
    } catch (URISyntaxException ex) {
        throwBadLocationException(recipe, uri.toString());
    } catch (DsException ex) {
        throwBadLocationException(recipe, uri.toString());
    } catch (MalformedURLException ex) {
        throwBadLocationException(recipe, uri.toString());
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.altiscale.TcpProxy.HostPort.java

private static ProxyConfiguration assembleConfigFromCommandLine(Options options, String[] args) {
    CommandLine commandLine = null;/* w w  w. ja va 2 s.  com*/
    try {
        commandLine = new GnuParser().parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        LOG.info("Parsing exception" + e.getMessage());
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("h")) {
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("version")) {
        LOG.info("Transfer Accelerator Version " + getProxyVersion());
        System.exit(1);
    }

    if (commandLine.hasOption("verbose")) {
        LogManager.getRootLogger().setLevel(Level.DEBUG);
    }

    ProxyConfiguration conf = new ProxyConfiguration();

    if (commandLine.hasOption("port")) {
        conf.listeningPort = Integer.parseInt(commandLine.getOptionValue("port"));
    }

    if (commandLine.hasOption("webstatus_port")) {
        conf.statusPort = Integer.parseInt(commandLine.getOptionValue("webstatus_port"));
    }

    // Maybe add jumphost.
    HostPort jumphostSshd = null;
    if (commandLine.hasOption("jumphost")) {
        String jumphostString = commandLine.getOptionValue("jumphost");
        try {
            jumphostSshd = conf.parseServerString(jumphostString);
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception for jumphost: " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Add jumphostServer if we have a jumphost.
    HostPort jumphostServer = null;
    if (commandLine.hasOption("jumphost_server")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_server.");
            printHelp(options);
            System.exit(1);
        }
        String jumphostServerString = commandLine.getOptionValue("jumphost_server");
        try {
            jumphostServer = conf.parseServerString(jumphostServerString);
            if (jumphostServer.port == -1) {
                throw new URISyntaxException(jumphostServerString, "Jumphost server parameter missing port.");
            }
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception for jumphost_server:" + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Maybe add jumphostUser if we have a jumphost.
    String jumphostUser = null;
    if (commandLine.hasOption("jumphost_user")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_user.");
            printHelp(options);
            System.exit(1);
        }
        jumphostUser = commandLine.getOptionValue("jumphost_user");
    }

    // Maybe add jumphostCredentials if we have a jumphost.
    String jumphostCredentials = null;
    if (commandLine.hasOption("jumphost_credentials")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_credentials.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCredentials = commandLine.getOptionValue("jumphost_credentials");
    }

    // Maybe set jumphostCompression if we have a jumphost.
    boolean jumphostCompression = false;
    if (commandLine.hasOption("jumphost_compression")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_compression.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCompression = true;
    }

    // Maybe add jumphostCiphers if we have a jumphost.
    String jumphostCiphers = null;
    if (commandLine.hasOption("jumphost_ciphers")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_ciphers.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCiphers = commandLine.getOptionValue("jumphost_ciphers");
    }

    // Maybe add sshBinary if we have a jumphost.
    String sshBinary = null;
    if (commandLine.hasOption("ssh_binary")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify ssh_binary.");
            printHelp(options);
            System.exit(1);
        }
        sshBinary = commandLine.getOptionValue("ssh_binary");
    }
    boolean openInterfaces = false;
    if (commandLine.hasOption("openInterfaces")) {
        openInterfaces = true;
    }

    // Add jumphost to the config.
    if (null != jumphostSshd && null != jumphostServer) {
        conf.jumphost = new JumpHost(jumphostSshd, jumphostServer, jumphostUser, jumphostCredentials,
                jumphostCompression, jumphostCiphers, sshBinary, openInterfaces);
    }

    if (!commandLine.hasOption("num_servers") && !commandLine.hasOption("servers")) {
        LOG.error("You need to specify one of the num_servers or servers flags.");
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("num_servers") && commandLine.hasOption("servers")) {
        LOG.error("You need to specify one of the num_servers or servers flags, not both.");
        printHelp(options);
        System.exit(1);
    }

    // Add servers.
    if (commandLine.hasOption("num_servers")) {
        try {
            int num_servers = Integer.parseInt(commandLine.getOptionValue("num_servers"));
            if (num_servers > TcpProxyServer.MAX_NUM_SERVERS) {
                throw new Exception("Please specify -servers.");
            }
            for (int i = 0; i < num_servers; i++) {
                conf.parseServerStringAndAdd("localhost:" + (TcpProxyServer.START_PORT_RANGE + i));
            }
        } catch (Exception e) {
            LOG.error("num_servers parsing exception " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("servers")) {
        String[] servers = commandLine.getOptionValues("servers");
        try {
            for (String server : servers) {
                conf.parseServerStringAndAdd(server);
            }
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Maybe set load balancer.
    if (commandLine.hasOption("load_balancer")) {
        HashSet<String> loadBalancers = new HashSet<String>(
                Arrays.asList("RoundRobin", "LeastUsed", "UniformRandom"));
        conf.loadBalancerString = commandLine.getOptionValue("load_balancer");
        if (!loadBalancers.contains(conf.loadBalancerString)) {
            LOG.error("Bad load_balancer value.");
            printHelp(options);
            System.exit(1);
        }
    }
    return conf;
}

From source file:org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.java

/**
 * Method to extract the account name from an Azure URI.
 * /*from   w ww  .  ja  v a 2 s  .c o m*/
 * @param uri
 *          -- WASB blob URI
 * @returns accountName -- the account name for the URI.
 * @throws URISyntaxException
 *           if the URI does not have an authority it is badly formed.
 */
private String getAccountFromAuthority(URI uri) throws URISyntaxException {

    // Check to make sure that the authority is valid for the URI.
    //
    String authority = uri.getRawAuthority();
    if (null == authority) {
        // Badly formed or illegal URI.
        //
        throw new URISyntaxException(uri.toString(), "Expected URI with a valid authority");
    }

    // Check if authority container the delimiter separating the account name from the
    // the container.
    //
    if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
        return authority;
    }

    // Split off the container name and the authority.
    //
    String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

    // Because the string contains an '@' delimiter, a container must be
    // specified.
    //
    if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
        // Badly formed WASB authority since there is no container.
        //
        final String errMsg = String.format("URI '%s' has a malformed WASB authority, expected container name. "
                + "Authority takes the form wasb://[<container name>@]<account name>", uri.toString());
        throw new IllegalArgumentException(errMsg);
    }

    // Return with the account name. It is possible that this name is NULL.
    //
    return authorityParts[1];
}

From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java

public static <T> PropertyStore<T> getStore(ZKConnection zkclient, String store,
        PropertySerializer<T> serializer) throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);

    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {

            ZooKeeperPermanentStore<T> zkStore = new ZooKeeperPermanentStore<T>(zkclient, serializer,
                    storeUri.getPath());
            startStore(zkStore);/*from   w  w w  .  j av a 2s .co  m*/
            return zkStore;
        } else {
            throw new URISyntaxException(store,
                    "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<T>(storeUri.getPath(), ".json", serializer);
    }

}

From source file:org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.java

/**
 * Method to extract the container name from an Azure URI.
 * //  w w w.j av a2s.c  o m
 * @param uri
 *          -- WASB blob URI
 * @returns containerName -- the container name for the URI. May be null.
 * @throws URISyntaxException
 *           if the uri does not have an authority it is badly formed.
 */
private String getContainerFromAuthority(URI uri) throws URISyntaxException {

    // Check to make sure that the authority is valid for the URI.
    //
    String authority = uri.getRawAuthority();
    if (null == authority) {
        // Badly formed or illegal URI.
        //
        throw new URISyntaxException(uri.toString(), "Expected URI with a valid authority");
    }

    // The URI has a valid authority. Extract the container name. It is the
    // second component of the WASB URI authority.
    if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
        // The authority does not have a container name. Use the default container by
        // setting the container name to the default Azure root container.
        //
        return AZURE_ROOT_CONTAINER;
    }

    // Split off the container name and the authority.
    String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

    // Because the string contains an '@' delimiter, a container must be
    // specified.
    if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
        // Badly formed WASB authority since there is no container.
        final String errMsg = String.format("URI '%s' has a malformed WASB authority, expected container name."
                + "Authority takes the form wasb://[<container name>@]<account name>", uri.toString());
        throw new IllegalArgumentException(errMsg);
    }

    // Set the container name from the first entry for the split parts of the
    // authority.
    return authorityParts[0];
}

From source file:eu.asterics.mw.services.ResourceRegistry.java

/**
 * Returns a File object representing the given URI if possible.
 * This only works if the given URI is a relative path or is a path with a file scheme (starting with: file)
 * @param uri//from ww w  .  j a  v a2s .  c  o m
 * @return
 * @throws URISyntaxException 
 */
public static File toFile(URI uri) throws URISyntaxException {
    String scheme = uri.getScheme();
    if (scheme != null && !scheme.startsWith("file")) {
        throw new URISyntaxException(uri.toString(), "The uri does not start with the scheme <file>");
    }
    File f = new File(uri.getPath());
    return f;
}