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:cn.dsgrp.field.stock.functional.rest.TaskRestFT.java

/**
 * //.//from  w  w  w .j  ava  2  s. c  om
 */
@Test
@Category(Smoke.class)
public void createUpdateAndDeleteTask() {

    // create
    Task task = TaskData.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(BigInteger.valueOf(Long.parseLong(id)));
    task.setTitle(TaskData.randomTitle());

    restTemplate.put(createdTaskUri, task);

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

    // delete
    restTemplate.delete(createdTaskUri);

    try {
        restTemplate.getForObject(createdTaskUri, Task.class);
        fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}

From source file:se.vgregion.urlservice.repository.jpa.JpaLongUrlRepository.java

@Override
@Transactional(propagation = Propagation.MANDATORY, readOnly = true)
public LongUrl findByUrl(URI url) {
    try {// ww w.  j  a v  a 2 s  .  c o m
        return (LongUrl) entityManager.createQuery("select l from LongUrl l where l.url = :url")
                .setParameter("url", url.toString()).getSingleResult();

    } catch (NoResultException e) {
        return null;
    }
}

From source file:core.net.DriveRequest.java

/**
 * Retrieves file and folder metadata/*from www.java2 s .c o  m*/
 * @param path The relative path to the file or folder
 * @return JSON String
 * @throws URISyntaxException Invalid URI
 * @throws IOException Bad request
 */
public String list(String ID) throws URISyntaxException, IOException {
    URI uri;
    uri = Param.create().setUrl(ROOT_META).setParam(MAX_RESULTS, RESULTS_LIMIT_VALUE).buildURI();
    String struri = uri.toString();
    struri = setquery(struri, ID);
    struri = settoken(struri, token.getToken().toString());
    System.out.println(struri);
    return Request.Get(struri).execute().returnContent().asString();
}

From source file:com.asiainfo.tfsPlatform.web.functional.rest.TaskRestFT.java

/**
 * //./* w w w. j  a v  a 2s .co  m*/
 */
@Test
@Category(Smoke.class)
public void createUpdateAndDeleteTask() {

    // create
    TaskDto task = TaskData.randomTask();

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

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

    restTemplate.put(createdTaskUri, task);

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

    // delete
    restTemplate.delete(createdTaskUri);

    try {
        restTemplate.getForObject(createdTaskUri, TaskDto.class);
        fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}

From source file:com.googlecode.jsonschema2pojo.SchemaStore.java

/**
 * Create or look up a new schema which has the given ID and read the
 * contents of the given ID as a URL. If a schema with the given ID is
 * already known, then a reference to the original schema will be returned.
 * /* w w w .  j a va  2  s . co m*/
 * @param id
 *            the id of the schema being created
 * @return a schema object containing the contents of the given path
 */
public synchronized Schema create(URI id) {

    if (!schemas.containsKey(id)) {

        JsonNode content = contentResolver.resolve(removeFragment(id));

        if (id.toString().contains("#")) {
            content = fragmentResolver.resolve(content, '#' + substringAfter(id.toString(), "#"));
        }

        schemas.put(id, new Schema(id, content));
    }

    return schemas.get(id);
}

From source file:org.nuclos.common.activemq.NuclosHttpTransportFactory.java

@Override
protected Transport createTransport(URI location, WireFormat wf) throws IOException {
    if (location.getScheme().equals("myhttp")) {
        try {/*from  ww w . j  ava2s  .co  m*/
            location = new URI(location.toString().substring(2));
        } catch (URISyntaxException e) {
            throw new IOException(e);
        }
    }
    final HttpClientTransport result = (HttpClientTransport) super.createTransport(location, wf);
    result.setSoTimeout(NuclosHttpClientFactory.SO_TIMEOUT_MILLIS);
    final HttpClient httpClient = getHttpClient();
    result.setReceiveHttpClient(httpClient);
    result.setSendHttpClient(httpClient);
    return result;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.MapperProxy.java

public InputStream getMapperValueAsStream(URI mapper, String name) {
    String mapperUrl = mapper.toString();
    if (mapperUrl == null) {
        return null;
    }//w w  w .  j a  v a2s. c o  m

    String url = mapperUrl + "/json/" + name;
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response;

    try {
        response = httpclient.execute(httpget);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException(String.format("%d -- %s", response.getStatusLine().getStatusCode(),
                    response.getStatusLine().getReasonPhrase()));
        }
        HttpEntity entity = response.getEntity();
        return entity.getContent();
    } catch (Exception e) {
        LOG.error("Can not access " + url, e);
    }
    return null;
}

From source file:org.neo4j.ogm.session.SessionFactory.java

/**
 * Opens a new Neo4j mapping {@link Session} against the specified Neo4j database.
 * The url may optionally contain the username and password to use while authenticating
 * for example, http://username:password@neo-server:port
 * Otherwise, if authentication is required, the username and password will be read from System properties.
 *
 * @param url The base URL of the Neo4j database with which to communicate.
 * @return A new {@link Session}/*w w w. ja  v  a  2 s  . c  om*/
 */
public Session openSession(String url) {
    try {
        URI uri = new URI(url);
        String username = null;
        String password = null;
        String uriStr = uri.toString();
        String auth = uri.getUserInfo();
        if (auth != null && !auth.trim().isEmpty()) {
            username = auth.split(":")[0];
            password = auth.split(":")[1];

            uriStr = uri.getScheme() + "://"
                    + uri.toString().substring(uri.toString().indexOf(auth) + auth.length() + 1);
        }

        if (username != null && password != null) {
            return new Neo4jSession(metaData, uriStr, httpClient, objectMapper,
                    new UsernamePasswordCredentials(username, password));

        }
        return new Neo4jSession(metaData, uriStr, httpClient, objectMapper);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:$.TaskRestFT.java

/**
     * //./*from ww w .j  a v a  2s. co  m*/
     */
    @Test
    @Category(Smoke.class)
    public void createUpdateAndDeleteTask() {

        // create
        Task task = TaskData.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(TaskData.randomTitle());

        restTemplate.put(createdTaskUri, task);

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

        // delete
        restTemplate.delete(createdTaskUri);

        try {
            restTemplate.getForObject(createdTaskUri, Task.class);
            fail("Get should fail while feth a deleted task");
        } catch (HttpStatusCodeException e) {
            assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
        }
    }

From source file:ca.sfu.federation.action.ShowWebSiteAction.java

/**
 * Handle action performed event./* ww  w  . j  av  a  2 s.c  om*/
 * @param ae Event
 */
public void actionPerformed(ActionEvent ae) {
    try {
        URI uri = new URI(ApplicationContext.PROJECT_WEBSITE_URL);
        // open the default web browser for the HTML page
        logger.log(Level.INFO, "Opening desktop browser to {0}", uri.toString());
        Desktop.getDesktop().browse(uri);
    } catch (Exception ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "Could not open browser for URL {0}\n\n{1}",
                new Object[] { ApplicationContext.PROJECT_WEBSITE_URL, stack });
    }
}