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:in.rishikeshdarandale.rest.resources.cart.CartResource.java

@POST
@Produces(MediaType.APPLICATION_JSON)//from  w  w  w . j a  va  2 s. c  o  m
public Response create() {
    String id = cartService.create().getId();
    return Response.created(URI.create("http://localhost:8080/carts/" + id)).build();
}

From source file:com.splunk.shuttl.archiver.archive.PathResolver.java

/**
 * Resolves a bucket's unique path of where to archive the {@link Bucket} on
 * the {@link WritableFileSystem} using configured values of
 * {@link ArchiveConfiguration}//  w w  w  .jav  a2s. c o m
 * 
 * @param bucket
 *          to archive.
 * @return URI to archive the bucket
 */
public URI resolveArchivePath(Bucket bucket) {
    String archivePathForBucket = getArchivingPath().toString() + SEPARATOR + bucket.getIndex() + SEPARATOR
            + bucket.getName() + SEPARATOR + bucket.getFormat();
    return URI.create(archivePathForBucket);
}

From source file:com.mgmtp.jfunk.web.util.DumpFileCreator.java

/**
 * Computes the best file to save the response to the current page.
 */// ww  w  .j av a2 s.  com
public File createDumpFile(final File dir, final String extension, final String urlString,
        final String additionalInfo) {
    URI uri = URI.create(urlString);
    String path = uri.getPath();
    if (path == null) {
        log.warn("Cannot create dump file for URI: " + uri);
        return null;
    }

    String name = PATTERN_FIRST_LAST_SLASH.matcher(path).replaceAll("$1");
    name = PATTERN_ILLEGAL_CHARS.matcher(name).replaceAll("_");

    Key key = Key.get(dir.getPath(), extension);
    MutableInt counter = countersMap.get(key);
    if (counter == null) {
        counter = new MutableInt();
        countersMap.put(key, counter);
    }

    int counterValue = counter.intValue();
    counter.increment();

    StringBuilder sb = new StringBuilder();
    sb.append(String.format("%04d", counterValue));
    sb.append('_');
    sb.append(name);
    if (StringUtils.isNotBlank(additionalInfo)) {
        sb.append("_");
        sb.append(additionalInfo);
    }
    sb.append(".");
    sb.append(extension);

    return new File(dir, sb.toString());
}

From source file:net.sf.taverna.t2.biomart.views.TestBiomartActivityContextualView.java

@Before
public void setup() throws Exception {
    activity = new Activity();
    activity.setParent(new Profile());

    Element el = getQueryElement("biomart-query.xml");

    Configuration configuration = new Configuration();
    configuration.setType(URI.create("http://ns.taverna.org.uk/2010/activity/biomart").resolve("#Config"));
    String queryText = new XMLOutputter().outputString(new Document(el));
    ((ObjectNode) configuration.getJson()).put("martQuery", queryText);

    configuration.setConfigures(activity);
}

From source file:io.gravitee.gateway.standalone.DynamicRoutingGatewayTest.java

@Test
public void call_dynamic_api() throws Exception {
    String initialTarget = api.getProxy().getEndpoints().get(0).getTarget();
    String dynamicTarget = create(URI.create("http://localhost:8080/team"), new URL(initialTarget).getPort())
            .toString();//from   w  w  w  .  j a  v a  2s .  c  o m

    org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request
            .Get("http://localhost:8082/test/my_team");
    request.addHeader("X-Dynamic-Routing-URI", dynamicTarget);

    org.apache.http.client.fluent.Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());
}

From source file:io.syndesis.credential.CredentialModuleTest.java

@Test
public void shouldDeserializeFromJson() throws IOException {
    final String json = "{\"type\":\"OAUTH1\",\"accessToken\":{\"value\":\"access-token-value\",\"secret\":\"access-token-secret\"},\"token\":{\"value\":\"token-value\",\"secret\":\"token-secret\"},\"verifier\":\"verifier\",\"key\":\"key\",\"providerId\":\"twitter\",\"returnUrl\":\"https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter\"}";

    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new CredentialModule());

    final OAuth1CredentialFlowState flowState = mapper.readerFor(CredentialFlowState.class).readValue(json);

    final OAuth1CredentialFlowState expected = new OAuth1CredentialFlowState.Builder()
            .accessToken(new OAuthToken("access-token-value", "access-token-secret"))
            .token(new OAuthToken("token-value", "token-secret")).verifier("verifier").key("key")
            .providerId("twitter")
            .returnUrl(URI.create(
                    "https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter"))
            .build();/*from   w  ww  . j  a v  a 2  s.co m*/

    assertThat(flowState).isEqualToIgnoringGivenFields(expected, "accessToken", "token");
    assertThat(flowState.getAccessToken()).isEqualToComparingFieldByField(expected.getAccessToken());
    assertThat(flowState.getToken()).isEqualToComparingFieldByField(expected.getToken());
}

From source file:com.telekom.api.common.webrequest.TelekomJsonWebRequest.java

public <ResponseType> ResponseType executePatched(Class<ResponseType> valueType) throws IOException {
    HttpResponse response = null;/*from w w  w.  j  a v a 2s  .c o m*/
    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(URI.create(this.uri + uriParamBuilder.toString()));
        request.setHeader("Accept", "application/json");
        request.setHeader("User-Agent", "We all love Telekom");
        request.setHeader("Authorization", this.authHeader);
        response = client.execute(request);
    } catch (IOException e) {
        e.printStackTrace();
    }

    InputStream responseStream = response.getEntity().getContent();

    return JsonSerializer.deserialize(responseStream, valueType);
}

From source file:com.clarionmedia.infinitum.web.rest.impl.SharedSecretAuthentication.java

@Override
public void authenticate(RequestWrapper request) {
    if (isHeader()) {
        request.addHeader(getTokenName(), getToken());
    } else {//  w w w.  j a  va 2 s.  co m
        String uri = request.getURI().toString();
        if (uri.contains("?"))
            uri += "&" + getTokenName() + "=" + getToken();
        request.setURI(URI.create(uri));
    }
}

From source file:org.fcrepo.auth.oauth.integration.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];
    assertNotNull("Didn't find authorization code!", authCode);
    logger.debug("with authorization code: {}", authCode);

}

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

public HttpComponentsRequestBuilder(HttpClient httpClient, HttpRequestBase request) {
    this.httpClient = httpClient;
    this.request = request;
    uriBuilder = new URIBuilder(URI.create("http://localhost:8080"));
}