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:org.apache.solr.servlet.ResponseHeaderTest.java

@Test
public void testHttpResponse() throws SolrServerException, IOException {
    HttpSolrClient client = (HttpSolrClient) getSolrClient();
    HttpClient httpClient = client.getHttpClient();
    URI uri = URI.create(client.getBaseURL() + "/withHeaders?q=*:*");
    HttpGet httpGet = new HttpGet(uri);
    HttpResponse response = httpClient.execute(httpGet);
    Header[] headers = response.getAllHeaders();
    boolean containsWarningHeader = false;
    for (Header header : headers) {
        if ("Warning".equals(header.getName())) {
            containsWarningHeader = true;
            assertEquals("This is a test warning", header.getValue());
            break;
        }/*from  w  w w  .  java 2 s.co m*/
    }
    assertTrue("Expected header not found", containsWarningHeader);
}

From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpRequest.java

/**
 * Adds a query parameter in the format name=value to this request URI.
 * @param paramName The name of the query parameter
 * @param paramValue The value of the query parameter
 * @return this request updated/*ww w .  j  av a 2s .com*/
 */
public SimpleHttpRequest addQueryParam(String paramName, String paramValue) {
    final String newUri;
    if (++queryParams > 0) {
        newUri = String.format("%s&%s=%s", this.getURI().toASCIIString(), paramName, this.encode(paramValue));
    } else {
        newUri = String.format("%s?%s=%s", this.getURI().toASCIIString(), paramName, this.encode(paramValue));
    }

    this.setURI(URI.create(newUri));

    return this;
}

From source file:com.tealeaf.Downloader.java

public HashMap<String, File> download(HashMap<String, String> uris) {
    HashMap<String, File> files = new HashMap<String, File>();
    if (uris == null) {
        return null;
    }// w w w.  j a  v a2s.c om

    String[] urls = new String[uris.size()];
    uris.keySet().toArray(urls);
    for (String url : urls) {
        if (cached(uris.get(url))) {
            logger.log("{downloader}", uris.get(url), "is cached");
            continue;
        }
        File f = http.getFile(URI.create(url), uris.get(url));
        if (f != null) {
            logger.log("{downloader} Downloading updated file", url, "to", f.getAbsolutePath());
            files.put(url, f);
        } else {
            logger.log("{downloader} ERROR: Unable to download file", url);
            return null;
        }
    }
    return files;
}

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

@Test
public void testDoubleTo() throws URISyntaxException {
    requestBuilder.to("http://test/path1").to("/path2");

    assertEquals(URI.create("http://test/path2"), requestBuilder.getUriBuilder().build());
}

From source file:net.rcarz.jiraclient.JiraClient.java

/**
 * Creates an authenticated JIRA client.
 *
 * @param uri Base URI of the JIRA server
 * @param creds Credentials to authenticate with
 * @throws JiraException // w  w w .j a v  a  2 s .c  o m
 */
public JiraClient(String uri, ICredentials creds) throws JiraException {
    DefaultHttpClient httpclient = new DefaultHttpClient();

    restclient = new RestClient(httpclient, creds, URI.create(uri));

    if (creds != null) {
        username = creds.getLogonName();
        //intialize connection if required
        creds.initialize(restclient);
    }
}

From source file:org.jclouds.http.httpnio.util.NioHttpUtilsTest.java

public void testConvertWithQuery() {
    HttpEntityEnclosingRequest apacheRequest = NioHttpUtils.convertToApacheRequest(
            new HttpRequest(HttpMethods.GET, URI.create("https://s3.amazonaws.com:443/?max-keys=0"),
                    ImmutableMultimap.of("Host", "s3.amazonaws.com")));
    assertEquals(apacheRequest.getHeaders("Host")[0].getValue(), "s3.amazonaws.com");
    assertEquals(apacheRequest.getRequestLine().getMethod(), "GET");
    assertEquals(apacheRequest.getRequestLine().getUri(), "/?max-keys=0");
}

From source file:com.github.fge.jsonschema.load.URIManagerTest.java

@Test
public void downloaderProblemsShouldBeReportedAsSuch() throws IOException {
    final URI uri = URI.create("foo://bar");
    final Exception foo = new IOException("foo");

    when(mock.fetch(any(URI.class))).thenThrow(foo);

    final LoadingConfiguration cfg = LoadingConfiguration.newBuilder().addScheme("foo", mock).freeze();

    final URIManager manager = new URIManager(cfg);

    try {//from w ww .  j a v a 2 s . c  om
        manager.getContent(uri);
    } catch (ProcessingException e) {
        assertMessage(e.getProcessingMessage()).hasMessage(BUNDLE.getString("uriIOError")).hasField("uri", uri)
                .hasLevel(LogLevel.FATAL).hasField("exceptionMessage", "foo");
    }
}

From source file:net.sf.taverna.t2.activities.biomart.BiomartActivityFactory.java

@Override
public URI getActivityType() {
    return URI.create(BiomartActivity.URI);
}

From source file:com.vrs.qrw100s.NetworkReader.java

@Override
public void run() {
    Thread.currentThread().setName("Network Reader");

    HttpResponse res;//from w ww . jav  a 2  s  .  c om
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpParams httpParams = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 5 * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000);

    Log.d(TAG, "1. Sending http request");
    try {
        res = httpclient.execute(new HttpGet(URI.create(myURL)));
        Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode());
        if (res.getStatusLine().getStatusCode() == 401) {
            return;
        }

        DataInputStream bis = new DataInputStream(res.getEntity().getContent());
        ByteArrayOutputStream jpgOut = new ByteArrayOutputStream(10000);

        int prev = 0;
        int cur;

        while ((cur = bis.read()) >= 0 && _runThread) {
            if (prev == 0xFF && cur == 0xD8) {
                // reset the output stream
                if (!skipFrame) {
                    jpgOut.reset();
                    jpgOut.write((byte) prev);
                }
            }

            if (!skipFrame) {
                if (jpgOut != null) {
                    jpgOut.write((byte) cur);
                }
            }

            if (prev == 0xFF && cur == 0xD9) {
                if (!skipFrame) {
                    synchronized (curFrame) {
                        curFrame = jpgOut.toByteArray();
                    }

                    skipFrame = true;

                    Message threadMessage = mainHandler.obtainMessage();
                    threadMessage.obj = curFrame;
                    mainHandler.sendMessage(threadMessage);
                } else {
                    if (skipNum < frameDecrement) {
                        skipNum++;
                    } else {
                        skipNum = 0;
                        skipFrame = false;
                    }
                }

            }
            prev = cur;
        }
    } catch (ClientProtocolException e) {
        Log.d(TAG, "Request failed-ClientProtocolException", e);
    } catch (IOException e) {
        Log.d(TAG, "Request failed-IOException", e);
    }

}

From source file:org.deeplearning4j.cli.schemes.BaseSchemeTest.java

@Test
public void testScheme() throws Exception {
    Scheme scheme = getScheme();/* ww w .j a  va2 s . c  om*/
    RecordReader recordReader = scheme.createReader(new ClassPathResource("iris.txt").getURI());

    assertTrue(recordReader.hasNext());
    while (recordReader.hasNext()) {
        Collection<Writable> record = recordReader.next();
        assertEquals(1, record.size());
    }

    recordReader = scheme.createReader(new ClassPathResource("iris.txt").getURI());

    List<Collection<Writable>> records = new ArrayList<>();
    int count = 0;
    RecordWriter writer = scheme.createWriter(URI.create("test_out.txt"));

    for (Collection<Writable> record : records) {
        writer.write(record);
        assertEquals(1, record.size());
    }

    recordReader = scheme.createReader(URI.create("test_out.txt"));

    while (recordReader.hasNext()) {
        Collection<Writable> record = recordReader.next();
        records.add(record);
        assertEquals(1, record.size());
        count++;
    }

    assertEquals(1, count);
    writer.close();
}