Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

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

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:com.app.server.XMLDeploymentScanner.java

public void deploy(URL url) {
    try {/*from   w ww  .j  a v a2s  .co m*/
        File file = new File(url.toURI());
        installDataSource(file);
        datasources.add(url.toURI().toString());
        log.info(url.toURI() + " deployed");
    } catch (Exception ex) {
        log.error("Error in deploying the datasource " + url, ex);
        //ex.printStackTrace();
    }

}

From source file:it.geosolutions.figis.ws.test.CheckChangeUserTest.java

/**
 * Create or modified test file/*from   w ww .  ja  v  a  2  s .  co  m*/
 *
 * @param useracProptestFile
 * @param userRoleAdminPwd
 * @throws IOException
 */
public void modifyUseracTestFile(String useracProptestFile, String userRoleAdminPwd) throws IOException {

    FileWriter fstream = null;
    BufferedWriter out = null;
    try {
        // Create file
        java.net.URL url = this.getClass().getClassLoader().getResource(useracProptestFile);
        fstream = new FileWriter(url.toURI().toURL().getPath());
        out = new BufferedWriter(fstream);
        out.write(TO_TEST_PROPERTIES_FILE + "\n");
        out.write(TO_TEST_PERIOD + "\n");
        out.write(userRoleAdminPwd + "\n");
        out.write(TO_TEST_USERS_ROLE_USER + "\n");
        out.flush();
    } catch (Exception e) // Catch exception if any
    {
        LOGGER.error(e.getLocalizedMessage(), e);
    } finally {
        // Close the output stream
        if (fstream != null) {
            IOUtils.closeQuietly(fstream);
        }
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    }
}

From source file:org.jboss.as.test.integration.web.tx.TxControlUnitTestCase.java

private void testURL(URL baseURL, boolean include, boolean commit) throws Exception {
    URL url = new URL(baseURL + TxControlServlet.URL_PATTERN + "?include=" + include + "&commit=" + commit);
    HttpGet httpget = new HttpGet(url.toURI());
    DefaultHttpClient httpclient = new DefaultHttpClient();

    log.info("executing request" + httpget.getRequestLine());
    HttpResponse response = httpclient.execute(httpget);

    int statusCode = response.getStatusLine().getStatusCode();
    assertEquals("Wrong response code: " + statusCode, HttpURLConnection.HTTP_OK, statusCode);

    if (include) {
        Header outerStatus = response.getFirstHeader(TxControlServlet.OUTER_STATUS_HEADER);
        Assert.assertNotNull(TxControlServlet.OUTER_STATUS_HEADER + " is null", outerStatus);
        Header innerStatus = response.getFirstHeader(TxControlServlet.INNER_STATUS_HEADER);
        Assert.assertNotNull(TxControlServlet.INNER_STATUS_HEADER + " is null", innerStatus);
        assertEquals("Wrong inner transaction status: " + innerStatus.getValue(), STATUS_ACTIVE,
                innerStatus.getValue());
        assertEquals("Wrong inner transaction status: " + outerStatus.getValue(), STATUS_ACTIVE,
                outerStatus.getValue());
    } // else TxControlServlet is using RequestDispatcher.forward and can't write to the response

    // Unfortunately, there's no simple mechanism to test that in the commit=false case the server cleaned up
    // the uncommitted tx. The cleanup (TransactionRollbackSetupAction) rolls back the tx and logs, but this
    // does not result in any behavior visible to the client.
}

From source file:com.adaptris.core.fs.FsHelperTest.java

@Test
public void testUnixStyleURI() throws Exception {
    URL url = FsHelper.createUrlFromString("/home/fred");
    assertEquals("fred", new File(url.toURI()).getName());
}

From source file:com.igormaznitsa.nbmindmap.nb.refactoring.elements.MoveFileActionPlugin.java

@Override
protected Problem processFile(final Project project, final int level, final File projectFolder,
        final FileObject fileObject) {
    final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);

    final Lookup targetLookup = this.refactoring.getTarget();
    if (targetLookup == null) {
        return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindLookup"));
    }/*from  www  . j  a va2s  . c o  m*/

    final URL targetURL = targetLookup.lookup(URL.class);

    if (targetURL != null) {
        try {
            URI baseURI = targetURL.toURI();
            if (baseURI.isAbsolute()) {
                final URI projectURI = Utilities.toURI(projectFolder);
                baseURI = projectURI.relativize(baseURI);
            }

            final MMapURI newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null)
                    .replaceBaseInPath(true, baseURI, level);

            for (final FileObject mmap : allMapsInProject(project)) {
                try {
                    if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
                        final MoveElement element = new MoveElement(new MindMapLink(mmap), projectFolder,
                                MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
                        element.setTarget(newFileAsURI);
                        addElement(element);
                    }
                } catch (Exception ex) {
                    ErrorManager.getDefault().notify(ex);
                    return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
                }
            }
        } catch (URISyntaxException ex) {
            LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex); //NOI18N
            return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantMakeURIForFile")); //NOI18N
        }
        return null;
    } else {
        return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindURL"));
    }
}

From source file:com.threewks.thundr.http.service.gae.HttpResponseImpl.java

@Override
public URI getUri() {
    try {/*from w w  w. j a  v  a 2s  .co m*/
        // final url is only non-null when we follow redirects
        URL finalUrl = response().getFinalUrl();
        return finalUrl == null ? url.toURI() : finalUrl.toURI();
    } catch (URISyntaxException e) {
        throw new HttpResponseException(e, "Uri cannot be parsed: %s", e.getMessage());
    }
}

From source file:de.tsystems.mms.apm.performancesignature.viewer.rest.JenkinsServerConnection.java

private boolean downloadArtifact(final FilePath file, final URL url, final PrintStream logger) {
    try {//  w w w .  ja va 2s. com
        InputStream inputStream = getJenkinsJob().getClient().getFile(url.toURI());
        file.copyFrom(inputStream);
        return true;
    } catch (IOException | InterruptedException | URISyntaxException e) {
        logger.println("Could not download artifact: " + FilenameUtils.getBaseName(url.toString()));
        return false;
    }
}

From source file:com.dhenton9000.filedownloader.FileDownloader.java

/**
 * Specify a URL that you want to perform an HTTP Status Check upon/Download a file from
 *
 * @param linkToFile URL/*from w  w w .  j  av  a  2 s  . c  o m*/
 */
public void setURI(URL linkToFile) throws URISyntaxException {
    fileURI = linkToFile.toURI();
}

From source file:com.app.server.XMLDeploymentScanner.java

public void undeploy(URL url) {
    try {/*from   ww  w.j a v  a 2  s . co m*/
        File file = new File(url.toURI());
        XMLDataSources xmlDataSources = xmlmap.get(file.getAbsolutePath());
        for (XMLDataSource xmlDataSource : xmlDataSources.xmlDataSources) {
            if (xmlDataSource != null)
                ic.unbind("java:/" + xmlDataSource.getJndi());
        }
        datasources.remove(url.toURI().toString());
        log.info(url.toURI() + " undeployed");
    } catch (Exception e) {
        log.error("Could not undeploy the datasource " + url, e);
        //e.printStackTrace();
    }
}

From source file:com.omertron.slackbot.utils.HttpTools.java

/**
 * GET data from the URL// w ww .j  a v  a 2  s  .  co m
 *
 * @param url URL to use in the request
 * @return String content
 * @throws ApiException
 */
public String getRequest(final URL url) throws ApiException {
    try {
        HttpGet httpGet = new HttpGet(url.toURI());
        httpGet.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON);
        DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET);
        long retryCount = 0L;

        // If we have a 429 response, wait and try again
        while (response.getStatusCode() == STATUS_TOO_MANY_REQUESTS && retryCount++ <= RETRY_MAX) {
            delay(retryCount);

            // Retry the request
            response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET);
        }

        return validateResponse(response, url);
    } catch (URISyntaxException | IOException ex) {
        throw new ApiException(ApiExceptionType.CONNECTION_ERROR, null, url, ex);
    } catch (RuntimeException ex) {
        throw new ApiException(ApiExceptionType.HTTP_503_ERROR, "Service Unavailable", url, ex);
    }
}