Example usage for java.net URI create

List of usage examples for java.net URI create

Introduction

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

Prototype

public static URI create(String str) 

Source Link

Document

Creates a URI by parsing the given string.

Usage

From source file:com.microsoft.projectoxford.face.rest.HttpDeleteWithBody.java

public HttpDeleteWithBody(final String uri) {
    this(URI.create(uri));
}

From source file:com.yahoo.gondola.container.client.ApacheHttpComponentProxyClientTest.java

@BeforeMethod
public void setUp() throws Exception {
    targetUri = getTargetUri(server.getHost());

    MockitoAnnotations.initMocks(this);
    URI uri = URI.create(targetUri + TEST_PATH);
    when(uriInfo.getRequestUri()).thenReturn(uri);
    when(request.getUriInfo()).thenReturn(uriInfo);
    when(request.getEntityStream()).thenReturn(new ByteArrayInputStream(RESPONSE_CONTENT.getBytes()));
    MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
    headers.add(TEST_HEADER_NAME, TEST_HEADER_VALUE);
    when(request.getHeaders()).thenReturn(headers);

    client = new ApacheHttpComponentProxyClient();
}

From source file:com.github.jknack.handlebars.io.ServletContextTemplateLoaderTest.java

@Test
public void defaultLoad() throws IOException {
    InputStream is = createMock(InputStream.class);
    is.close();//from   w w w  .  j av  a 2 s  . co m
    expectLastCall();

    ServletContext servletContext = createMock(ServletContext.class);
    expect(servletContext.getResourceAsStream("/template.hbs")).andReturn(is);

    replay(servletContext, is);

    TemplateLoader locator = new ServletContextTemplateLoader(servletContext);
    Reader reader = locator.load(URI.create("template"));
    assertNotNull(reader);
    IOUtils.closeQuietly(reader);

    verify(servletContext, is);
}

From source file:com.microsoft.alm.plugin.context.ServerContextTest.java

@Test
public void constructor() {
    ServerContext context = new ServerContext(ServerContext.Type.TFS, null, null, null, null, null, null, null,
            null);//from   w w  w  . ja  va 2 s .c  o m
    Assert.assertEquals(ServerContext.Type.TFS, context.getType());
    Assert.assertNull(context.getAuthenticationInfo());
    Assert.assertNull(context.getUri());
    Assert.assertNull(context.getGitRepository());
    Assert.assertNull(context.getTeamProjectCollectionReference());
    Assert.assertNull(context.getTeamProjectReference());
    Assert.assertFalse(context.hasClient());
    context.dispose();

    URI serverUri = URI.create("http://server");
    AuthenticationInfo info = new AuthenticationInfo("", "", "", "");
    TeamProjectCollectionReference collection = new TeamProjectCollectionReference();
    TeamProjectReference project = new TeamProjectReference();
    GitRepository repo = new GitRepository();
    ServerContext context2 = new ServerContext(ServerContext.Type.TFS, info, null, serverUri, serverUri, null,
            collection, project, repo);
    Assert.assertEquals(ServerContext.Type.TFS, context.getType());
    Assert.assertEquals(info, context2.getAuthenticationInfo());
    Assert.assertEquals(serverUri, context2.getUri());
    Assert.assertEquals(repo, context2.getGitRepository());
    Assert.assertEquals(collection, context2.getTeamProjectCollectionReference());
    Assert.assertEquals(project, context2.getTeamProjectReference());
    Assert.assertFalse(context2.hasClient());
    context2.dispose();
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.ProxyHttpClientBuilderExtension.java

@Override
public CredentialsProvider extendCredentialProvider(HttpClientBuilder httpClientBuilder,
        CredentialsProvider credentialsProvider, GerritAuthData authData) {
    HttpConfigurable proxySettings = HttpConfigurable.getInstance();
    IdeaWideProxySelector ideaWideProxySelector = new IdeaWideProxySelector(proxySettings);

    // This will always return at least one proxy, which can be the "NO_PROXY" instance.
    List<Proxy> proxies = ideaWideProxySelector.select(URI.create(authData.getHost()));

    // Find the first real proxy with an address type we support.
    for (Proxy proxy : proxies) {
        SocketAddress socketAddress = proxy.address();

        if (HttpConfigurable.isRealProxy(proxy) && socketAddress instanceof InetSocketAddress) {
            InetSocketAddress address = (InetSocketAddress) socketAddress;
            HttpHost proxyHttpHost = new HttpHost(address.getHostName(), address.getPort());
            httpClientBuilder.setProxy(proxyHttpHost);

            // Here we use the single username/password that we got from IDEA's settings. It feels kinda strange
            // to use these credential but it's probably what the user expects.
            if (proxySettings.PROXY_AUTHENTICATION) {
                AuthScope authScope = new AuthScope(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT);
                UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
                        proxySettings.PROXY_LOGIN, proxySettings.getPlainProxyPassword());
                credentialsProvider.setCredentials(authScope, credentials);
                break;
            }//  w  w  w.ja v a  2  s .c o m
        }
    }
    return credentialsProvider;
}

From source file:de.dan_nrw.android.scroid.dao.wallpapers.parsing.JsonWallpaperParser.java

@Override
public List<Wallpaper> parse(String data) throws ParseException {
    try {/*  ww  w . j  a v  a 2s  .  c  o  m*/
        JSONArray array = new JSONArray(data);
        List<Wallpaper> wallpapers = new ArrayList<Wallpaper>();

        for (int i = 0; i < array.length(); i++) {
            JSONObject jsonWallpaper = array.getJSONObject(i);

            wallpapers.add(new Wallpaper(jsonWallpaper.getString("id"), jsonWallpaper.getString("title"),
                    URI.create(jsonWallpaper.getString("thumburl")),
                    URI.create(jsonWallpaper.getString("previewurl")),
                    URI.create(jsonWallpaper.getString("url")), jsonWallpaper.getString("text")));
        }

        return wallpapers;
    } catch (JSONException ex) {
        throw new ParseException(ex.getMessage(), 0);
    }
}

From source file:org.fcrepo.integration.auth.oauth.api.AuthzEndpointIT.java

@Test
public void testGetAuthzCode() throws ClientProtocolException, IOException {
    // we want to grab the auth code, not get redirected
    client.getParams().setBooleanParameter(HANDLE_REDIRECTS, false);
    logger.debug("Entering testGetAuthzCode()...");
    final HttpResponse response = client.execute(new HttpGet(
            authzEndpoint + "?client_id=CLIENT-ID&redirect_uri=http://example.com&response_type=code"));
    logger.debug("Retrieved authorization endpoint response.");
    final String redirectHeader = response.getFirstHeader("Location").getValue();
    final String authCode = URI.create(redirectHeader).getQuery().split("&")[0].split("=")[1];
    Assert.assertNotNull("Didn't find authorization code!", authCode);
    logger.debug("with authorization code: {}", authCode);

}

From source file:com.arpnetworking.jackson.OptionalSerializerTest.java

@Test
public void testSerializationUri() throws IOException {
    final URI expectedUri = URI.create("/hosts/v1/query?name=test-app1.com");
    final Optional<URI> optionalUri = Optional.of(expectedUri);
    final String serializedUri = OBJECT_MAPPER.writeValueAsString(optionalUri);

    Assert.assertEquals("\"/hosts/v1/query?name=test-app1.com\"", serializedUri);
}

From source file:de.otto.jsonhome.generator.SpringJsonHomeGenerator.java

@Value("${jsonhome.varTypeBaseUri}")
public void setVarTypeBaseUri(final String varTypeBaseUri) {
    if (varTypeBaseUri != null && !varTypeBaseUri.isEmpty()) {
        this.varTypeBaseUri = URI.create(varTypeBaseUri);
    }//from  w w  w .  j  a v a2s  .  c o  m
}

From source file:net.javacrumbs.restfire.httpcomponents.HttpComponentsRequestBuilderTest.java

@Test
public void testToPathWithParams() throws URISyntaxException {
    requestBuilder.withUri("http://localhost:8080");
    requestBuilder.to("/test?q=1");

    assertEquals(URI.create("http://localhost:8080/test?q=1"), requestBuilder.getUriBuilder().build());
}