Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:io.spring.initializr.web.project.MainControllerEnvIntegrationTests.java

@Test
public void downloadCliWithCustomRepository() throws Exception {
    ResponseEntity<?> entity = getRestTemplate().getForEntity(createUrl("/spring"), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    String expected = "https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin.zip";
    assertThat(entity.getHeaders().getLocation()).isEqualTo(new URI(expected));
}

From source file:com.thoughtworks.go.server.web.IgnoreResolver.java

private boolean isStaticFile(HttpServletRequest request) throws URISyntaxException {
    String path = new URI(request.getRequestURI()).getPath().toLowerCase();
    for (String ext : STATIC_FILE_EXT) {
        if (path.endsWith(ext)) {
            return true;
        }//w  w w. j  a v a2  s  . c  o  m
    }
    return false;
}

From source file:info.ajaxplorer.client.http.PydioClient.java

public static URI returnUriFromString(String url) throws URISyntaxException {
    URI uri = null;// ww  w . jav  a2  s  . c o m
    try {
        uri = new URI(url);
    } catch (Exception e) {
    }
    return uri;
}

From source file:org.apache.marmotta.ldclient.provider.phpbb.mapping.PHPBBForumHrefMapper.java

@Override
public List<Value> map(String resourceUri, Element selectedValue, ValueFactory factory) {
    String baseUriSite = resourceUri.substring(0, resourceUri.lastIndexOf('/'));
    String baseUriTopic = baseUriSite + "/viewforum.php?";

    try {//from   w  w w  .j av a2s.  com
        URI uri = new URI(selectedValue.absUrl("href"));
        Map<String, String> params = new HashMap<String, String>();
        for (NameValuePair p : URLEncodedUtils.parse(uri, "UTF-8")) {
            params.put(p.getName(), p.getValue());
        }

        return Collections.singletonList((Value) factory.createURI(baseUriTopic + "f=" + params.get("f")));
    } catch (URISyntaxException ex) {
        throw new RuntimeException("invalid syntax for URI", ex);
    }
}

From source file:org.apache.storm.elasticsearch.common.EsConfig.java

static URI toURI(String url) throws IllegalArgumentException {
    try {//from w  w  w .  j a va  2  s.co  m
        return new URI(url);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid url " + url);
    }
}

From source file:biz.gabrys.lesscss.extended.compiler.source.FtpSourceFactory.java

public FtpSource createRelativeSource(final LessSource source, final String importRelativePath) {
    try {//w w w . j  a  va  2 s  .c o  m
        final String sourcePath = source.getPath();
        final String parentPath = sourcePath.substring(0, sourcePath.lastIndexOf('/'));
        final URI importUri = new URI(parentPath + '/' + importRelativePath).normalize();
        return new FtpSource(importUri.toURL(), source.getEncoding());
    } catch (final URISyntaxException e) {
        throw new SourceFactoryException("Cannot normalize URL", e);
    } catch (final MalformedURLException e) {
        throw new SourceFactoryException("Cannot create relative URL", e);
    }
}

From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java

@Override
public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) {
    Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials");
    String id = (String) serviceData.get("name");
    try {//from   w w w . j av a 2  s.  c  o m
        URI uri = new URI((String) credentials.get("url"));
        String scheme = uri.getScheme();
        int port = uri.getPort();
        String host = uri.getHost();
        String path = uri.getPath();
        String query = uri.getQuery();
        String fragment = uri.getFragment();
        String url = new URI(scheme, "", host, port, path, query, fragment).toString();
        String[] userInfo = uri.getUserInfo().split(":");
        return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url);
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:com.github.wnameless.spring.papertrail.test.jpa.AfterPaperTrailCallbackTest.java

@Test
public void testAfter() throws Exception {
    RequestEntity<Void> req = RequestEntity.post(new URI(host + "/after")).header("Authorization", encodedAuth)
            .build();// ww  w  . j av a2  s. co  m
    template.exchange(req, String.class);

    JpaPaperTrail trail = repo.findByRequestUri("/after");
    assertEquals("AFTER", trail.getUserId());
    assertEquals("127.0.0.1", trail.getRemoteAddr());
    assertEquals("POST", trail.getHttpMethod().toString());
    assertEquals("/after", trail.getRequestUri());
    assertEquals(201, trail.getHttpStatus());
    assertNotNull(trail.getCreatedAt());
}

From source file:gobblin.source.extractor.extract.kafka.ConfigStoreUtils.java

/**
 * Will return the list of URIs given which are importing tag {@param tagUri}
 *///w w w. j  a  va  2  s  .co m
public static Collection<URI> getTopicsURIFromConfigStore(ConfigClient configClient, Path tagUri,
        String filterString, Optional<Config> runtimeConfig) {
    try {
        Collection<URI> importedBy = configClient.getImportedBy(new URI(tagUri.toString()), true,
                runtimeConfig);
        return importedBy.stream().filter((URI u) -> u.toString().contains(filterString))
                .collect(Collectors.toList());
    } catch (URISyntaxException | ConfigStoreFactoryDoesNotExistsException | ConfigStoreCreationException e) {
        throw new Error(e);
    }
}

From source file:com.github.wnameless.spring.papertrail.test.jpa.AroundPaperTrailCallbackTest.java

@Test
public void testAround() throws Exception {
    RequestEntity<Void> req = RequestEntity.post(new URI(host + "/around")).header("Authorization", encodedAuth)
            .build();//from w w  w.ja  va2  s .com
    template.exchange(req, String.class);

    JpaPaperTrail trail = repo.findByRequestUri("/around");
    assertEquals("AROUND", trail.getUserId());
    assertEquals("127.0.0.1", trail.getRemoteAddr());
    assertEquals("POST", trail.getHttpMethod().toString());
    assertEquals("/around", trail.getRequestUri());
    assertEquals(201, trail.getHttpStatus());
    assertNotNull(trail.getCreatedAt());
}