Example usage for java.net URISyntaxException getReason

List of usage examples for java.net URISyntaxException getReason

Introduction

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

Prototype

public String getReason() 

Source Link

Document

Returns a string explaining why the input string could not be parsed.

Usage

From source file:edu.harvard.hul.ois.drs.pdfaconvert.PdfaConvert.java

private static void loadApplicationPropertiesFile() {
    // Set the projects properties.
    // First look for a system property pointing to a project properties file.
    // This value can be either a file path, file protocol (e.g. - file:/path/to/file),
    // or a URL (http://some/server/file).
    // If this value either does not exist or is not valid, the default
    // file that comes with this application will be used for initialization.
    String environmentProjectPropsFile = System.getProperty(ApplicationConstants.ENV_PROJECT_PROPS);
    logger.info("Have {} from environment: {}", ApplicationConstants.PROJECT_PROPS,
            environmentProjectPropsFile);
    URI projectPropsUri = null;/*from w  ww  . ja  v a 2s.  c  o m*/
    if (environmentProjectPropsFile != null) {
        try {
            projectPropsUri = new URI(environmentProjectPropsFile);
            // properties file needs a scheme in the URI so convert to file if necessary.
            if (null == projectPropsUri.getScheme()) {
                File projectProperties = new File(environmentProjectPropsFile);
                if (projectProperties.exists() && projectProperties.isFile()) {
                    projectPropsUri = projectProperties.toURI();
                } else {
                    // No scheme and not a file - yikes!!! Let's bail and
                    // use fall-back file.
                    projectPropsUri = null;
                    throw new URISyntaxException(environmentProjectPropsFile, "Not a valid file");
                }
            }
        } catch (URISyntaxException e) {
            // fall back to default file
            logger.error("Unable to load properties file: {} -- reason: {}", environmentProjectPropsFile,
                    e.getReason());
            logger.error("Falling back to default {} file: {}", ApplicationConstants.PROJECT_PROPS,
                    ApplicationConstants.PROJECT_PROPS);
        }
    }

    applicationProps = new Properties();
    // load properties if environment value set
    if (projectPropsUri != null) {
        File envPropFile = new File(projectPropsUri);
        if (envPropFile.exists() && envPropFile.isFile() && envPropFile.canRead()) {
            Reader reader;
            try {
                reader = new FileReader(envPropFile);
                logger.info("About to load {} from environment: {}", ApplicationConstants.PROJECT_PROPS,
                        envPropFile.getAbsolutePath());
                applicationProps.load(reader);
                logger.info("Success -- loaded properties file.");
            } catch (IOException e) {
                logger.error("Could not load environment properties file: {}", projectPropsUri, e);
                // set URI back to null so default prop file loaded
                projectPropsUri = null;
            }
        }
    }

    if (projectPropsUri == null) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try {
            InputStream resourceStream = loader.getResourceAsStream(ApplicationConstants.PROJECT_PROPS);
            applicationProps.load(resourceStream);
            logger.info("loaded default applicationProps: ");
        } catch (IOException e) {
            logger.error("Could not load properties file: {}", ApplicationConstants.PROJECT_PROPS, e);
            // couldn't load default properties so bail...
            throw new RuntimeException("Couldn't load an applications properties file.", e);
        }
    }
}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testBuilderWithMalformedUriString() {
    try {/*from   ww  w  .  j a  va  2  s. c  o  m*/
        new UriBeacon.Builder().uriString(TestData.malformedUrlString).build();
        Assert.fail("Should fail");
    } catch (URISyntaxException e) {
        assertEquals("Not a valid URI", e.getReason());
    }
}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testBuilderWithLongInvalidUriString() {
    try {//from w w w.  j a  v a  2s .  c  o m
        new UriBeacon.Builder().uriString(TestData.longButInvalidUrlString).build();
        Assert.fail("Should fail");
    } catch (URISyntaxException e) {
        assertEquals("Uri size is larger than 18 bytes", e.getReason());
    }
}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testBuilderWithLongInvalidUriByteArray() {
    try {//ww  w.j  ava 2s  . co  m
        new UriBeacon.Builder().uriString(TestData.longButInvalidUrlByteArray).build();
        Assert.fail("Should fail");
    } catch (URISyntaxException e) {
        assertEquals("Uri size is larger than 18 bytes", e.getReason());
    }
}

From source file:com.visionspace.jenkins.vstart.plugin.VSPluginPerformer.java

public boolean validateTestCase(Long id, AbstractBuild build, BuildListener listener) {
    try {/*from  ww w  .  jav  a 2 s .  c  om*/
        if (!vstObject.canRun(id)) {
            listener.getLogger().println("This job can't be run at the moment. [JOB: "
                    + build.getProject().getName() + " BUILD NO " + build.getNumber() + "]);");
            return false;
        } else {
            return true;
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the test case validation -> " + ex.getReason());
        return false;
    } catch (IOException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getLocalizedMessage());
        return false;
    }
}

From source file:com.visionspace.jenkins.vstart.plugin.VSPluginPerformer.java

public boolean logToWorkspace(Long reportId, AbstractBuild build, BuildListener listener) {
    try {/*from  w  w  w. j  a va  2 s .co m*/
        org.json.JSONObject report = vstObject.getReport(reportId);
        FilePath jPath = new FilePath(build.getWorkspace(), build.getWorkspace().toString() + "/VSTART_JSON");
        if (!jPath.exists()) {
            jPath.mkdirs();
        }

        String filePath = jPath + "/VSTART_JSON_" + build.getId() + ".json";

        JSONArray reports;
        try {
            String content = new String(Files.readAllBytes(Paths.get(filePath)));
            reports = new JSONArray(content);
        } catch (IOException e) {
            Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.WARNING, null, e);
            reports = new JSONArray();
        }

        reports.put(report);

        PrintWriter wj = new PrintWriter(filePath);
        wj.println(reports.toString());
        wj.close();

        //TODO: check test case result
        /*
        if (report.getString("status").equals("PASSED")) {          
        */
        return true;
        /* } */

    } catch (URISyntaxException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Error on performing the workspace logging -> " + ex.getReason());
    } catch (IOException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Error on performing the workspace logging -> " + ex.toString());
    } catch (InterruptedException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Error on performing the workspace logging -> " + ex.getMessage());
    }
    return false;

}

From source file:com.visionspace.jenkins.vstart.plugin.VSPluginPerformer.java

public Long runVstart(Long id, BuildListener listener, int timeInterval) {
    try {//from   w ww  .j av  a 2s  . c om
        //Run VSTART
        org.json.JSONObject runObject = vstObject.run(id);
        listener.getLogger().println("\nVSTART is now running!");
        Long reportId = runObject.getLong("reportId");

        //Inform which test case is running
        //listener.getLogger().println("The test case " + vstObject.getTestCase(testCaseId) + "has started.");

        //For concurrency issues
        Object obj = new Object();

        synchronized (obj) {
            long timeStamp = 0;
            org.json.JSONObject logger = null;

            do {
                logger = vstObject.getLog(reportId, timeStamp);
                JSONArray jArray = logger.getJSONArray("log");
                for (int i = 0; i < jArray.length(); i++) {
                    org.json.JSONObject json = jArray.getJSONObject(i);
                    Long eventTimeStamp = json.getLong("timestamp");
                    Date date = new Date(eventTimeStamp);
                    listener.getLogger().println(json.getString("level") + " " + /*eventTimeStamp*/date + " ["
                            + json.getString("resource") + "]" + " - " + json.getString("message") + "\n");

                    //Stores the latest timestamp
                    if (eventTimeStamp > timeStamp) {
                        timeStamp = eventTimeStamp;
                    }
                }
                if (!logger.getBoolean("finished")) {
                    obj.wait(timeInterval);
                }
            } while (!logger.getBoolean("finished"));
        }

        //inform the finishing of the test case execution
        //listener.getLogger().println("The test case " + vstObject.getTestCase(testCaseId) + "has finished its execution.");

        //Finished run
        listener.getLogger().println("VSTART run has now ended!");

        return reportId;
    } catch (URISyntaxException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getReason());
        return 0l;
    } catch (IOException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getMessage());
        return 0l;
    } catch (InterruptedException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getMessage());
        return 0l;
    }
}

From source file:org.jolokia.client.J4pClient.java

private J4pException mapException(Exception pException) throws J4pException {
    if (pException instanceof ConnectException) {
        return new J4pConnectException(
                "Cannot connect to " + requestHandler.getJ4pServerUrl() + ": " + pException.getMessage(),
                (ConnectException) pException);
    } else if (pException instanceof ConnectTimeoutException) {
        return new J4pTimeoutException("Read timeout while request " + requestHandler.getJ4pServerUrl() + ": "
                + pException.getMessage(), (ConnectTimeoutException) pException);
    } else if (pException instanceof IOException) {
        return new J4pException("IO-Error while contacting the server: " + pException, pException);
    } else if (pException instanceof URISyntaxException) {
        URISyntaxException sExp = (URISyntaxException) pException;
        return new J4pException("Invalid URI " + sExp.getInput() + ": " + sExp.getReason(), pException);
    } else {/*from w ww .  j  a  v  a2 s .  c  o  m*/
        return new J4pException("Exception " + pException, pException);
    }
}

From source file:com.naryx.tagfusion.cfm.http.cfHttpConnection.java

@Override
public void setURL(String _url, int _port) throws cfmRunTimeException {
    port = _port;//from   w  w  w  .  j  a  v a  2s. c  o  m
    url = _url;

    if (_url.startsWith("/")) {
        url = "http://" + session.REQ.getServerName() + ":" + session.REQ.getServerPort()
                + session.REQ.getContextPath() + url;
    }

    try {
        ((HttpRequestBase) message).setURI(new URI(url));
    } catch (URISyntaxException ue) {
        throw newRunTimeException("Failed to set URL:" + ue.getReason());
    }

    int uriPort = message.getURI().getPort();
    if (port == -1 && uriPort == -1) {
        // use default port for http/https
    } else if (uriPort != -1) {
        // use specified port
        port = uriPort;
    }
}

From source file:com.google.caja.plugin.Config.java

public boolean processArguments(String[] argv) {
    try {//from   www.j a v  a  2 s  .  co  m
        CommandLine cl;
        try {
            cl = new BasicParser().parse(options, argv, false);
        } catch (org.apache.commons.cli.ParseException e) {
            usage(e.getMessage(), stderr);
            return false;
        }

        inputUris = Lists.newArrayList();
        for (String input : getOptionValues(cl, INPUT)) {
            URI inputUri;
            try {
                if (input.indexOf(':') >= 0) {
                    inputUri = new URI(input);
                } else {
                    File inputFile = new File(input);

                    if (!inputFile.exists()) {
                        usage("File \"" + input + "\" does not exist", stderr);
                        return false;
                    }
                    if (!inputFile.canRead() || inputFile.isDirectory()) {
                        usage("File \"" + input + "\" is not a regular file", stderr);
                        return false;
                    }

                    inputUri = inputFile.getAbsoluteFile().toURI();
                }
            } catch (URISyntaxException ex) {
                usage("Input \"" + input + "\" is not a valid URI", stderr);
                return false;
            }

            inputUris.add(inputUri);
        }
        if (inputUris.isEmpty()) {
            usage("Option \"--" + INPUT.getLongOpt() + "\" missing", stderr);
            return false;
        }

        if (cl.getOptionValue(OUTPUT_BASE.getOpt()) != null) {
            outputBase = new File(cl.getOptionValue(OUTPUT_BASE.getOpt()));

            outputJsFile = substituteExtension(outputBase, ".out.js");
            outputHtmlFile = substituteExtension(outputBase, ".out.html");

            if (cl.getOptionValue(OUTPUT_JS.getOpt()) != null) {
                usage("Can't specify both --out and --output_js", stderr);
                return false;
            }
            if (cl.getOptionValue(OUTPUT_HTML.getOpt()) != null) {
                usage("Can't specify both --out and --output_html", stderr);
                return false;
            }
        } else {
            outputJsFile = cl.getOptionValue(OUTPUT_JS.getOpt()) == null ? null
                    : new File(cl.getOptionValue(OUTPUT_JS.getOpt()));

            outputHtmlFile = cl.getOptionValue(OUTPUT_HTML.getOpt()) == null ? null
                    : new File(cl.getOptionValue(OUTPUT_HTML.getOpt()));

            if (outputJsFile == null && outputHtmlFile == null) {
                usage("Please specify js output via " + OUTPUT_JS.getLongOpt() + " &| html output via "
                        + OUTPUT_HTML.getLongOpt(), stderr);
                return false;
            }
        }

        try {
            cssPropertyWhitelistUri = new URI(cl.getOptionValue(CSS_PROPERTY_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/css/css-extensions.json"));
            htmlAttributeWhitelistUri = new URI(cl.getOptionValue(HTML_ATTRIBUTE_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/html" + "/html4-attributes-extensions.json"));
            htmlElementWhitelistUri = new URI(cl.getOptionValue(HTML_ELEMENT_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/html" + "/html4-elements-extensions.json"));

            if (cl.getOptionValue(BASE_URI.getOpt()) != null) {
                baseUri = new URI(cl.getOptionValue(BASE_URI.getOpt()));
            } else {
                baseUri = inputUris.get(0);
            }
        } catch (URISyntaxException ex) {
            stderr.println("Invalid whitelist URI: " + ex.getInput() + "\n    " + ex.getReason());
            return false;
        }

        if (cl.getOptionValue(FETCHER_BASE.getOpt()) != null) {
            fetcherBase = new File(cl.getOptionValue(FETCHER_BASE.getOpt()));
        } else if (Strings.equalsIgnoreCase(baseUri.getScheme(), "file")) {
            fetcherBase = new File(baseUri).getParentFile();
        }

        idClass = cl.getOptionValue(ID_CLASS.getOpt(), null);

        String servicePortString;
        try {
            servicePortString = cl.getOptionValue(SERVICE_PORT.getOpt(), "8887");
            servicePort = Integer.parseInt(servicePortString);
        } catch (NumberFormatException e) {
            stderr.println("Invalid service port: " + SERVICE_PORT.getOpt() + "\n    " + e.getMessage());
            return false;
        }

        fUris = Sets.immutableSet(getOptionValues(cl, F_URI));
        lUris = Sets.immutableSet(getOptionValues(cl, L_URI));

        String renderString = cl.getOptionValue(RENDERER.getOpt());
        if (renderString != null) {
            renderer = SourceRenderMode.valueOf(renderString.toUpperCase());
            if (renderer == null) {
                stderr.println("Invalid renderer: " + renderString);
                return false;
            }
        } else {
            renderer = SourceRenderMode.PRETTY;
        }

        boolean debugMode = cl.hasOption(DEBUG_MODE.getOpt());
        boolean onlyJsEmitted = cl.hasOption(OUTPUT_JS.getOpt()) && !cl.hasOption(OUTPUT_HTML.getOpt());
        if (debugMode) {
            negGoals = negGoals.with(PipelineMaker.ONE_CAJOLED_MODULE);
            posGoals = posGoals.with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG);
        }
        if (onlyJsEmitted) {
            negGoals = negGoals.with(PipelineMaker.HTML_SAFE_STATIC);
        }

        String preconds = cl.getOptionValue(PIPELINE_PRECONDITIONS.getOpt());
        if (preconds != null) {
            Pair<Planner.PlanState, Planner.PlanState> deltas = planDeltas(preconds);
            negPreconds = negPreconds.with(deltas.a);
            posPreconds = posPreconds.with(deltas.b);
        }

        String goals = cl.getOptionValue(PIPELINE_GOALS.getOpt());
        if (goals != null) {
            Pair<Planner.PlanState, Planner.PlanState> deltas = planDeltas(goals);
            negGoals = negGoals.with(deltas.a);
            posGoals = posGoals.with(deltas.b);
        }

        return true;
    } finally {
        stderr.flush();
    }
}