Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:org.springside.samples.quickservice.functional.TaskRestServiceTest.java

@Test
public void createUpdateAndDeleteTask() {

    // create/*from  w  w w . j a va2s  .  co m*/
    Task task = randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(new Long(id));
    task.setTitle(RandomData.randomName("Task"));

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);
    Task deletedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(deletedTask).isNull();
}

From source file:org.gradle.internal.resource.transport.http.HttpResourceAccessor.java

@Nullable
public HttpResponseResource getResource(final URI uri) throws IOException {
    abortOpenResources();//from ww w . ja  v a  2s  . c o m
    String location = uri.toString();
    LOGGER.debug("Constructing external resource: {}", location);

    HttpResponse response = http.performGet(location);
    if (response != null) {
        HttpResponseResource resource = wrapResponse(uri, response);
        return recordOpenGetResource(resource);
    }

    return null;
}

From source file:info.rmapproject.api.auth.ApiUserServiceTest.java

/**
 * Tests retrieval of a key URI to be associated with an event.
 * Should retrieve a key URI.//from   www  .j a  v  a 2 s.  c om
 */
@Test
@Ignore //see comment at top of page
public void getKeyUriForEventTest() {
    try {
        URI apiKeyUri = apiUserService.getApiKeyForEvent();
        assertTrue(apiKeyUri.toString().equals("rmap:fakermaptestkey"));
    } catch (RMapApiException e) {
        fail("key not retrieved");
    }

}

From source file:org.kaaproject.kaa.server.common.admin.KaaRestTemplate.java

private URI updateUrl(URI url) {
    String currentUri = url.toString();

    int sufixPartIdx = currentUri.indexOf(restApiSuffix);

    String defaultUriPartWithVariableHostPort = currentUri.substring(0, sufixPartIdx);
    String sufixPart = currentUri.substring(sufixPartIdx);

    defaultUriPartWithVariableHostPort = defaultUriPartWithVariableHostPort.replaceFirst(url.getHost(),
            getCurHost());/*from www .j a  v  a 2s .  c o m*/
    defaultUriPartWithVariableHostPort = defaultUriPartWithVariableHostPort
            .replaceFirst(String.valueOf(url.getPort()), String.valueOf(getCurPort()));

    return URI.create(defaultUriPartWithVariableHostPort + sufixPart);
}

From source file:mobi.jenkinsci.ci.client.JenkinsHttpClient.java

private void ensurePreemptiveAuthRequest(final HttpRequestBase req) {
    final String username = config.getUsername();
    final String password = config.getPassword();
    final URI reqUri = req.getURI();
    final String reqUriString = reqUri.toString();
    if (reqUriString.indexOf(username) < 0) {
        try {/*w  w w .j  av  a  2s  . co m*/
            final String newUriString = reqUriString.replaceAll("://", "://"
                    + URLEncoder.encode(username, "UTF-8") + ":" + URLEncoder.encode(password, "UTF-8") + "@");
            req.setURI(new URI(newUriString));
        } catch (final Exception e) {
            LOG.error("Cannot insert user into URI " + reqUriString, e);
            return;
        }
    }
}

From source file:com.talis.storage.http.ItemResource.java

@PUT
@Consumes("*/*")//from   w w w  .  j  av a 2s.c om
public Response put(@PathParam("id") final String id, @Context HttpHeaders headers, InputStream entityStream) {

    URI tmbURI = makeInternalURI(id);
    LOG.debug(String.format("PUT request to URI : %s", tmbURI.toString()));

    MediaType mediaType = headers.getMediaType();
    try {
        SubmittedItem submitted = itemFactory.newSubmittedItem(mediaType, entityStream);
        myStore.write(tmbURI, submitted);
    } catch (InvalidKeyException e) {
        throw new WebApplicationException(e, 400);
    } catch (IOException e) {
        throw new WebApplicationException(e, 500);
    }

    return Response.created(tmbURI).build();
}

From source file:de.dfki.resc28.flapjack.services.BaseService.java

protected String getCanonicalURL(URI url) {
    if (url.toString().endsWith("/")) {
        return url.toString().substring(0, url.toString().length() - 1);
    }/*from  w  w  w  .  j av  a  2s . co m*/

    return url.toString();
}

From source file:comsat.sample.ui.SampleGroovyTemplateApplicationTests.java

@Test
public void testCreate() throws Exception {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.set("text", "FOO text");
    map.set("summary", "FOO");
    URI location = new TestRestTemplate().postForLocation("http://localhost:" + this.port, map);
    assertTrue("Wrong location:\n" + location, location.toString().contains("localhost:" + this.port));
}

From source file:com.emorym.android_pusher.PusherConnection.java

public void connect() {
    try {/*from ww  w . jav a 2  s.  c o m*/
        URI url = new URI(mPusher.getUrl());
        Log.d(LOG_TAG, "Connecting to " + url.toString());

        mWebSocket = new WebSocketConnection(url);
        mWebSocket.setEventHandler(new WebSocketEventHandler() {
            public void onOpen() {
                Log.d(LOG_TAG, "Successfully opened Websocket");
            }

            public void onMessage(WebSocketMessage message) {
                Log.d(LOG_TAG, "Received from Websocket " + message.getText());

                try {
                    JSONObject parsed = new JSONObject(message.getText());
                    String eventName = parsed.getString("event");
                    String channelName = parsed.optString("channel", null);
                    String eventData = parsed.getString("data");

                    if (eventName.equals(Pusher.PUSHER_EVENT_CONNECTION_ESTABLISHED)) {
                        JSONObject parsedEventData = new JSONObject(eventData);
                        String socketId = parsedEventData.getString("socket_id");
                        mPusher.onConnected(socketId);
                    } else {
                        mPusher.dispatchEvents(eventName, eventData, channelName);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onClose() {
                Log.d(LOG_TAG, "Successfully closed Websocket");
            }
        });
        mWebSocket.connect();

    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (WebSocketException e) {
        e.printStackTrace();
    }
}

From source file:com.lukasz.chat.pusher.PusherConnection.java

public void connect() {
    try {/*from   www . j  a va  2s .c o  m*/
        URI url = new URI(mPusher.getUrl());
        Log.d(LOG_TAG, "Connecting to " + url.toString());

        mWebSocket = new WebSocketConnection(url);
        mWebSocket.setEventHandler(new WebSocketEventHandler() {
            public void onOpen() {
                Log.d(LOG_TAG, "Successfully opened Websocket");
            }

            public void onMessage(WebSocketMessage message) {

                try {
                    JSONObject parsed = new JSONObject(message.getText());
                    String eventName = parsed.getString("event");
                    String channelName = parsed.optString("channel", null);
                    String eventData = parsed.getString("data");

                    if (eventName.equals(Pusher.PUSHER_EVENT_CONNECTION_ESTABLISHED)) {
                        JSONObject parsedEventData = new JSONObject(eventData);
                        String socketId = parsedEventData.getString("socket_id");
                        mPusher.onConnected(socketId);
                    } else {
                        mPusher.dispatchEvents(eventName, eventData, channelName);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onClose() {
                Log.d(LOG_TAG, "Successfully closed Websocket");
            }
        });

        mWebSocket.connect();

    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (WebSocketException e) {
        e.printStackTrace();
    }
}