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.alehuo.wepas2016projekti.configuration.ProductionConfiguration.java

/**
 * Heroku -palvelussa kytetn PostgreSQL -tietokantaa tiedon
 * tallentamiseen. Tm metodi hakee herokusta tietokantayhteyden
 * mahdollistavat ympristmuuttujat./*ww  w.  j  a  v  a2s  . c om*/
 *
 * @return @throws URISyntaxException
 */
@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));

    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    //Autocommit pois plt
    basicDataSource.setDefaultAutoCommit(false);

    return basicDataSource;
}

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

@Test
public void testFilePathValidWithOtherPathForDependencies() throws Exception {
    URI flowFilePath = getClass().getResource("/flow.sl").toURI();
    URI folderPath = getClass().getResource("/flowsdir/").toURI();
    URI flow2FilePath = getClass().getResource("/flowsdir/flow2.sl").toURI();
    compilerHelper.compile(flowFilePath.getPath(), Lists.newArrayList(folderPath.getPath()));
    Mockito.verify(slang).compile(SlangSource.fromFile(flowFilePath),
            Sets.newHashSet(SlangSource.fromFile(flow2FilePath)));
}

From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java

private URI stripQuery(URI uri) {
    try {// w  ww .  j av  a 2  s.  c  o m
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null,
                null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.github.dozermapper.core.builder.xml.SchemaLSResourceResolver.java

/**
 * Attempt to resolve systemId resource from classpath by checking:
 *
 * 1. Try {@link SchemaLSResourceResolver#getClass()#getClassLoader()}
 * 2. Try {@link BeanContainer#getClassLoader()}
 * 3. Try {@link Activator#getBundle()}/*from   w w  w .  j a va  2 s .  co  m*/
 *
 * @param systemId systemId used by XSD
 * @return stream to XSD
 * @throws IOException if fails to find XSD
 */
private InputStream resolveFromClassPath(String systemId) throws IOException, URISyntaxException {
    InputStream source;

    String xsdPath;
    URI uri = new URI(systemId);
    if (uri.getScheme().equalsIgnoreCase("file")) {
        xsdPath = uri.toString();
    } else {
        xsdPath = uri.getPath();
        if (xsdPath.charAt(0) == '/') {
            xsdPath = xsdPath.substring(1);
        }
    }

    ClassLoader localClassLoader = getClass().getClassLoader();

    LOG.debug("Trying to locate [{}] via ClassLoader [{}]", xsdPath,
            localClassLoader.getClass().getSimpleName());

    //Attempt to find within this JAR
    URL url = localClassLoader.getResource(xsdPath);
    if (url == null) {
        //Attempt to find via user defined class loader
        DozerClassLoader dozerClassLoader = beanContainer.getClassLoader();

        LOG.debug("Trying to locate [{}] via DozerClassLoader [{}]", xsdPath,
                dozerClassLoader.getClass().getSimpleName());

        url = dozerClassLoader.loadResource(xsdPath);
    }

    if (url == null) {
        //Attempt to find via OSGi
        Bundle bundle = Activator.getBundle();
        if (bundle != null) {
            LOG.debug("Trying to locate [{}] via Bundle [{}]", xsdPath, bundle.getClass().getSimpleName());

            url = bundle.getResource(xsdPath);
        }
    }

    if (url == null) {
        throw new IOException("Could not resolve bean-mapping XML Schema [" + systemId
                + "]: not found in classpath; " + xsdPath);
    }

    try {
        source = url.openStream();
    } catch (IOException ex) {
        throw new IOException("Could not resolve bean-mapping XML Schema [" + systemId
                + "]: not found in classpath; " + xsdPath, ex);
    }

    LOG.debug("Found bean-mapping XML Schema [{}] in classpath @ [{}]", systemId, url.toString());

    return source;
}

From source file:com.alexshabanov.springrestapi.restapitest.RestOperationsTestClient.java

private MockHttpServletRequest toMockHttpServletRequest(URI url, HttpMethod method,
        ClientHttpRequest clientHttpRequest) throws IOException {
    final MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(method.name(),
            url.getPath());

    // copy headers
    final HttpHeaders headers = clientHttpRequest.getHeaders();
    for (final String headerKey : headers.toSingleValueMap().keySet()) {
        final List<String> headerValues = headers.get(headerKey);
        for (final String headerValue : headerValues) {
            mockHttpServletRequest.addHeader(headerKey, headerValue);
        }/*from w w w .  j ava 2  s  . c om*/
    }

    // copy query parameters
    final String query = clientHttpRequest.getURI().getQuery();
    if (query != null) {
        mockHttpServletRequest.setQueryString(query);
        final String[] queryParameters = query.split("&");
        for (String keyValueParam : queryParameters) {
            final String[] components = keyValueParam.split("=");
            if (components.length == 1) {
                continue; // optional parameter
            }

            Assert.isTrue(components.length == 2,
                    "Can't split query parameters " + keyValueParam + " by key-value pair");
            mockHttpServletRequest.setParameter(components[0], components[1]);
        }
    }

    // copy request body
    // TODO: another byte copying approach here
    // TODO: for now we rely to the fact that request body is always presented as byte array output stream
    final OutputStream requestBodyStream = clientHttpRequest.getBody();
    if (requestBodyStream instanceof ByteArrayOutputStream) {
        mockHttpServletRequest.setContent(((ByteArrayOutputStream) requestBodyStream).toByteArray());
    } else {
        throw new AssertionError("Ooops, client http request has non-ByteArrayOutputStream body");
    }

    return mockHttpServletRequest;
}

From source file:com.eucalyptus.http.MappingHttpRequest.java

/**
 * Constructor for outbound requests. /* w  w  w . ja  v a  2 s .c  om*/
 */
public MappingHttpRequest(final HttpVersion httpVersion, final HttpMethod method,
        final ServiceConfiguration serviceConfiguration, final Object source) {
    super(httpVersion);
    this.method = method;
    URI fullUri = ServiceUris.internal(serviceConfiguration);
    this.uri = fullUri.toString();
    this.servicePath = fullUri.getPath();
    this.query = null;
    this.parameters = null;
    this.rawParameters = null;
    this.nonQueryParameterKeys = null;
    this.formFields = null;
    this.message = source;
    if (source instanceof BaseMessage)
        this.setCorrelationId(((BaseMessage) source).getCorrelationId());
    this.addHeader(HttpHeaders.Names.HOST, fullUri.getHost() + ":" + fullUri.getPort());
}

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

String getPrefixKey(BackupRestoreContext ctx) throws URISyntaxException {
    URI uri = new URI(ctx.getExternalLocation());
    String[] segments = uri.getPath().split("/");

    int startIndex = uri.getScheme().equals(AmazonS3Client.S3_SERVICE_NAME) ? 1 : 2;
    String prefixKey = "";
    for (int i = startIndex; i < segments.length; i++) {
        prefixKey += segments[i];/*from w  w  w .j a  va 2 s  .  c o m*/
        if (i < segments.length - 1) {
            prefixKey += "/";
        }
    }

    prefixKey = (prefixKey.length() > 0 && !prefixKey.endsWith("/")) ? prefixKey + "/" : prefixKey;
    prefixKey += ctx.getName(); // append backup name

    return prefixKey;
}

From source file:com.almende.eve.goldemo.Cell.java

private String getNeighborId(final String neighbor, final boolean NEW) {
    String neighborId = null;//from   w  w w .ja  v a 2 s  .c  o  m
    if (neighbor.startsWith("local:")) {
        neighborId = neighbor.replace("local:", "");
    } else {
        URI neighborUrl = URI.create(neighbor);
        neighborId = neighborUrl.getPath().replaceFirst("agents/", "");
    }
    if (NEW) {
        neighborId = neighborId.replaceFirst(".*_", "");
    }
    return neighborId;
}

From source file:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testGetUrl() throws Exception {
    subject.get(URL, mapper);/*from  w w w.ja  v a2s  .  com*/
    ArgumentCaptor<HttpGet> argument = ArgumentCaptor.forClass(HttpGet.class);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}

From source file:org.robertburrelldonkin.template4couchdb.rest.HttpClientRestClientTest.java

@Test
public void testPostUrl() throws Exception {
    ArgumentCaptor<HttpPost> argument = ArgumentCaptor.forClass(HttpPost.class);
    this.subject.post(URL, documentMarshaller, document, responseUnmarshaller);
    verify(client).execute(argument.capture(), eq(handler));
    URI uri = argument.getValue().getURI();
    assertThat(PORT, is(uri.getPort()));
    assertThat(HOST, is(uri.getHost()));
    assertThat(PROTOCOL, is(uri.getScheme()));
    assertThat(PATH, is(uri.getPath()));
}