Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:com.googlecode.psiprobe.Tomcat70ContainerAdaptor.java

@Override
public File getConfigFile(Context ctx) {
    URL configUrl = ctx.getConfigFile();
    if (configUrl != null) {
        try {//from   w  w  w  .  ja v  a2 s.c  om
            URI configUri = configUrl.toURI();
            if ("file".equals(configUri.getScheme())) {
                return new File(configUri.getPath());
            }
        } catch (Exception ex) {
            logger.error("Could not convert URL to URI: " + configUrl, ex);
        }
    }
    return null;
}

From source file:hadoopInstaller.installation.UploadConfiguration.java

private void modifyEnvShFile(Host host, FileObject configurationDirectory, String fileName)
        throws InstallationError {
    log.debug("HostInstallation.Upload.File.Start", //$NON-NLS-1$
            fileName, host.getHostname());
    FileObject configurationFile;
    try {// w  w w .ja v a 2s . c om
        configurationFile = configurationDirectory.resolveFile(fileName);
    } catch (FileSystemException e) {
        throw new InstallationError(e, "HostInstallation.CouldNotOpen", //$NON-NLS-1$
                fileName);
    }
    EnvShBuilder builder = new EnvShBuilder(configurationFile);
    String path = host.getInstallationDirectory();
    URI hadoop = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$
            path, InstallerConstants.HADOOP_DIRECTORY));
    URI java = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$
            path, InstallerConstants.JAVA_DIRECTORY));
    builder.setCustomConfig(getLocalFileContents(fileName));
    builder.setHadoopPrefix(hadoop.getPath());
    builder.setJavaHome(java.getPath());
    try {
        builder.build();
    } catch (IOException e) {
        throw new InstallationError(e, "HostInstallation.CouldNotWrite", //$NON-NLS-1$
                configurationFile.getName().getURI());
    }
    try {
        configurationFile.close();
    } catch (FileSystemException e) {
        log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$
                configurationFile.getName().getURI());
    }
    log.debug("HostInstallation.Upload.File.Success", //$NON-NLS-1$
            fileName, host.getHostname());
}

From source file:it.geosolutions.geostore.services.rest.security.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    URI url = null;
    try {//  w w  w  .j av a2  s  .  c  om
        url = new URI(request.getRequestURI());
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        LOGGER.error("Invalid URI:" + request.getRequestURI());
        super.commence(request, response, authException);
        return;
    }
    if (url == null) {
        super.commence(request, response, authException);
        return;
    }
    if (url.getPath().contains(LOGIN_PATH)) {
        response.setHeader("WWW-Authenticate", "FormBased");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    } else {
        super.commence(request, response, authException);

    }

}

From source file:org.attribyte.api.pubsub.impl.server.NotificationMetricsServlet.java

/**
 * Gets a metrics prefix for a topic./*from  www.  j a  v  a  2 s  .c om*/
 * @param topicId The topic id.
 * @param joinString The string used to join parts of the topic URI.
 * @param allowSlash Is '/' allowed in the prefix?
 * @return The prefix.
 */
private String getTopicPrefix(final long topicId, final String joinString, final boolean allowSlash) {
    try {
        Topic topic = endpoint.getDatastore().getTopic(topicId);
        if (topic != null) {
            URI uri = new URI(topic.getURL());
            List<String> components = Lists.newArrayListWithCapacity(4);
            if (uri.getHost() != null)
                components.add(uri.getHost());
            if (uri.getPort() > 0)
                components.add(Integer.toString(uri.getPort()));
            String path = uri.getPath();
            if (path != null) {
                if (path.startsWith("/"))
                    path = path.substring(1);
                if (path.endsWith("/"))
                    path = path.substring(0, path.length() - 1);
                components.add(path);
            }
            String prefix = Joiner.on(joinString).skipNulls().join(components);
            if (!allowSlash)
                prefix = prefix.replace('/', '_');
            return prefix;
        } else {
            return null;
        }
    } catch (DatastoreException de) {
        log("Unable to resolve topic", de);
        return null;
    } catch (URISyntaxException use) {
        return null;
    }
}

From source file:org.openscore.lang.cli.utils.CompilerHelperTest.java

@Test
public void testFilePathValid() throws Exception {
    URI flowFilePath = getClass().getResource("/flow.sl").toURI();
    URI opFilePath = getClass().getResource("/test_op.sl").toURI();
    URI flow2FilePath = getClass().getResource("/flowsdir/flow2.sl").toURI();
    URI spFlow = getClass().getResource("/sp/flow.sl").toURI();
    URI spOp = getClass().getResource("/sp/operation.sl").toURI();
    compilerHelper.compile(flowFilePath.getPath(), null);
    Mockito.verify(slang).compile(SlangSource.fromFile(flowFilePath),
            Sets.newHashSet(SlangSource.fromFile(flowFilePath), SlangSource.fromFile(flow2FilePath),
                    SlangSource.fromFile(opFilePath), SlangSource.fromFile(spFlow),
                    SlangSource.fromFile(spOp)));
}

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 {//w  ww.j  a va 2  s  . c  o  m
        return uri.getPath().split("/")[1];
    }
}

From source file:org.openscore.lang.tools.verifier.SlangContentVerifierTest.java

@Test
public void testPreCompileIllegalSlangFile() throws Exception {
    URI resource = getClass().getResource("/no_dependencies").toURI();
    Mockito.when(slangCompiler.preCompile(any(SlangSource.class))).thenThrow(new RuntimeException());
    exception.expect(RuntimeException.class);
    slangContentVerifier.verifyAllSlangFilesInDirAreValid(resource.getPath());
}

From source file:eionet.gdem.utils.Utils.java

/**
 * Utility method for checking whether the resource exists. The resource can be web or file system resource that matches the URI
 * with "http", "https" or "file" schemes Returns false, if the resource does not exist
 *
 * @param strUri/*from w  ww.  j a  va2s.c  o  m*/
 * @return
 */
public static boolean resourceExists(String strUri) {
    strUri = StringUtils.replace(strUri, "\\", "/");
    try {
        URI uri = new URI(strUri);
        String scheme = uri.getScheme();
        if (scheme.startsWith("http")) {
            return HttpUtils.urlExists(strUri);
        } else if (scheme.equals("file")) {
            File f = new File(uri.getPath());
            return f.exists();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }
    return false;
}

From source file:com.b2international.snowowl.snomed.importer.rf2.util.SnomedRefSetNameCollector.java

private Optional<String> getFileName(final URL fileUrl) {

    String fileName = null;//from ww w . j ava  2s.  c  o  m

    try {

        fileName = new File(fileUrl.toURI()).getName();

    } catch (final Throwable t) {

        try {

            // assuming zip URL
            if (fileUrl.toString().startsWith("zip")) {
                final URI uri = URI.create(fileUrl.toString().substring(fileUrl.toString().indexOf('!') + 1));
                fileName = org.eclipse.emf.common.util.URI.createFileURI(uri.getPath()).lastSegment();
            }

        } catch (final Throwable t2) {
            // ignore it, file name is optional
        }

    }

    return Optional.<String>fromNullable(fileName);

}

From source file:com.mellanox.jxio.ServerPortal.java

private URI replacePortInURI(URI uri, int newPort) {
    URI newUri = null;/*from   ww w .j ava2 s  .  c  o m*/
    try {
        newUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), newPort, uri.getPath(),
                uri.getQuery(), uri.getFragment());
        if (LOG.isDebugEnabled()) {
            LOG.debug(this.toLogString() + "uri with port " + newPort + " is " + newUri.toString());
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
        LOG.error(this.toLogString() + "URISyntaxException occured while trying to create a new URI");
    }

    return newUri;
}