Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

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

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java

@Test
public void testGetFileObjectByUri() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}

From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java

@Test
public void testGetFileObjectByUriStringParam() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI().toString());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}

From source file:fr.free.movierenamer.scrapper.impl.image.TMDbImagesScrapper.java

private String imdbIDLookUp(String imdbId) throws Exception {
    URL searchUrl = new URL("http", host, "/" + version + "/movie/" + imdbId + "?api_key=" + apikey);
    JSONObject json = URIRequest.getJsonDocument(searchUrl.toURI());
    return JSONUtils.selectString("id", json);
}

From source file:com.atypon.wayf.request.ResponseWriter.java

protected String buildLinkHeaderValue() {
    Boolean hasAnotherPage = RequestContextAccessor.get().getHasAnotherDbPage();

    if (hasAnotherPage) {
        int currentLimit = RequestContextAccessor.get().getLimit();
        int currentOffset = RequestContextAccessor.get().getOffset();
        int newOffset = currentOffset + currentLimit;

        String urlStr = null;/*  w  ww . j  a v a 2  s  . c o  m*/

        try {
            URL url = new URL(RequestContextAccessor.get().getRequestUrl());

            urlStr = new URIBuilder(url.toURI())
                    .setParameter(RequestReader.LIMIT_QUERY_PARAM, String.valueOf(currentLimit))
                    .setParameter(RequestReader.OFFSET_QUERY_PARAM, String.valueOf(newOffset)).build()
                    .toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return new StringBuilder().append("<").append(urlStr).append(">; rel=\"next\"").toString();
    }

    return StringUtils.EMPTY;
}

From source file:ch.mbae.pusher.transport.HttpClientPusherTransport.java

public PusherResponse fetch(URL url, String jsonData) throws PusherTransportException {
    PusherResponse response = new PusherResponse();
    try {//from ww w .ja  va 2  s  . com
        HttpPost post = new HttpPost(url.toURI());

        post.addHeader("Content-Type", "application/json");
        post.setEntity(new StringEntity(jsonData));
        // executr post request
        HttpResponse httpResponse = this.httpClient.execute(post);

        // get the content
        response.setContent(EntityUtils.toByteArray(httpResponse.getEntity()));
        // extract and set headers
        response.setHeaders(this.extractHeaders(httpResponse));
        // set http status
        response.setResponseCode(httpResponse.getStatusLine().getStatusCode());

    } catch (URISyntaxException ex) {
        throw new PusherTransportException("bad uri syntax", ex);
    } catch (ClientProtocolException ex) {
        throw new PusherTransportException("bad client protocol", ex);
    } catch (IOException ex) {
        throw new PusherTransportException("i/o failed", ex);
    }

    return response;
}

From source file:org.netvogue.server.webmvc.pusher.HttpClientPusherTransport.java

@Override
public PusherResponse fetch(URL url, String jsonData) throws PusherTransportException {
    PusherResponse response = new PusherResponse();
    try {/*from  w  w w  . j  a  v  a  2s .  c om*/
        HttpPost post = new HttpPost(url.toURI());

        post.addHeader("Content-Type", "application/json");
        post.setEntity(new StringEntity(jsonData));
        // executr post request
        HttpResponse httpResponse = this.httpClient.execute(post);

        // get the content
        response.setContent(EntityUtils.toByteArray(httpResponse.getEntity()));
        // extract and set headers
        response.setHeaders(this.extractHeaders(httpResponse));
        // set http status
        response.setResponseCode(httpResponse.getStatusLine().getStatusCode());

    } catch (URISyntaxException ex) {
        throw new PusherTransportException("bad uri syntax", ex);
    } catch (ClientProtocolException ex) {
        throw new PusherTransportException("bad client protocol", ex);
    } catch (IOException ex) {
        throw new PusherTransportException("i/o failed", ex);
    }

    return response;
}

From source file:edu.wisc.doit.tcrypt.ant.filter.AntTasksTest.java

protected File getResourceFile(final String file) throws URISyntaxException {
    final URL buildResource = this.getClass().getResource(file);
    final File buildFile = new File(buildResource.toURI());
    return buildFile;
}

From source file:io.cloudslang.lang.compiler.modeller.transformers.ResultsTransformerTest.java

private List getResultsFromOperationFile(String fileName) throws URISyntaxException {
    URL resource = getClass().getResource(fileName);
    ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI())));
    Map<String, Object> op = file.getOperation();
    return (List) op.get(SlangTextualKeys.RESULTS_KEY);
}

From source file:com.google.appengine.tck.blobstore.support.FileUploader.java

private String getUploadUrl(URL url, Method method, Map<String, String> params)
        throws URISyntaxException, IOException {
    URIBuilder builder = new URIBuilder(url.toURI());
    for (Map.Entry<String, String> entry : params.entrySet()) {
        builder.addParameter(entry.getKey(), entry.getValue());
    }//from w  w  w.ja  va 2  s .  co m
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpUriRequest request;
        switch (method) {
        case GET:
            request = new HttpGet(builder.build());
            break;
        case POST:
            request = new HttpPost(builder.build());
            break;
        default:
            throw new IllegalArgumentException(String.format("No such method: %s", method));
        }
        HttpResponse response = httpClient.execute(request);
        return EntityUtils.toString(response.getEntity()).trim();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:org.jboss.as.test.integration.web.customerrors.CustomErrorsUnitTestCase.java

private void testURL(URL url, int expectedCode, String expectedPage, String expectedError) throws Exception {
    HttpGet httpget = new HttpGet(url.toURI());
    DefaultHttpClient httpclient = new DefaultHttpClient();

    log.info("executing request" + httpget.getRequestLine());
    HttpResponse response = httpclient.execute(httpget);

    int statusCode = response.getStatusLine().getStatusCode();
    Header page = response.getFirstHeader("X-CustomErrorPage");
    Header error = response.getFirstHeader("X-ExceptionType");

    assertTrue("Wrong response code: " + statusCode, statusCode == expectedCode);
    if (expectedPage != null) {
        assertTrue("X-CustomErrorPage(" + page + ") is " + expectedPage, page.getValue().equals(expectedPage));
    }/*from w w  w.  jav  a2 s.  c o m*/
    if (expectedError != null) {
        assertTrue("X-ExceptionType(" + error + ") is " + expectedError,
                error.getValue().equals(expectedError));
    }
}