Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:de.hanbei.resources.http.HttpResourceLocator.java

public HttpResourceLocator(String base) throws URISyntaxException {
    this(new URI(base));
}

From source file:com.jilk.ros.rosbridge.implementation.ROSBridgeWebSocketClient.java

public static ROSBridgeWebSocketClient create(String URIString) {
    ROSBridgeWebSocketClient client = null;
    try {//from w  w  w  .  j a  v a  2s  .co  m
        URI uri = new URI(URIString);
        client = new ROSBridgeWebSocketClient(uri);
    } catch (URISyntaxException ex) {
        ex.printStackTrace();
    }
    return client;
}

From source file:net.krks.android.roidcast.RoidcastDataHttpGet.java

/**
 * uri??????inputstream?/*from  w  w w .  j  a v  a  2  s .  com*/
 * 
 * @param uri
 * @return InputStream
 */
public InputStream getImputStreamOnWeb(String uri) {
    Log.d(Roidcast.TAG, "getImputStreamOnWeb:" + uri);

    try {
        httpGet.setURI(new URI(uri));
    } catch (URISyntaxException ex) {
        new RoidcastUtil().eLog(ex);
        return null;
    }

    HttpResponse response = null;

    try {
        response = execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        Log.d(Roidcast.TAG, "statusCode:" + statusCode);
        // success
        if (HttpStatus.SC_OK != statusCode) {
            throw new IOException();
        }
        return response.getEntity().getContent();
    } catch (ClientProtocolException e) {
        new RoidcastUtil().eLog(e);
    } catch (IOException e) {
        new RoidcastUtil().eLog(e);
    }

    return null;
}

From source file:test.pl.chilldev.web.spring.config.XmlnsBeanDefinitionParserTest.java

@Test
public void parse() throws URISyntaxException {
    GenericBeanDefinition bean = new GenericBeanDefinition();
    XmlnsBeanDefinitionParser parser = new XmlnsBeanDefinitionParser(bean);

    String alias = "cdv";
    String namespace = "http://chilldev.pl/";

    when(this.element.getAttribute("alias")).thenReturn(alias);
    when(this.element.getAttribute("namespace")).thenReturn(namespace);

    parser.parse(this.element, null);

    URI uri = new URI(namespace);
    Map<URI, String> xmlNamespaces = (Map<URI, String>) bean.getPropertyValues()
            .getPropertyValue(XmlnsBeanDefinitionParser.PROPERTY_XMLNAMESPACES).getValue();

    assertTrue("XmlnsBeanDefinitionParser.parse() should register XML namespace.",
            xmlNamespaces.containsKey(uri));
    assertEquals("XmlnsBeanDefinitionParser.parse() should register alias for XML namespace.", alias,
            xmlNamespaces.get(uri));/*from   w  ww . java2s  .  c o m*/
}

From source file:org.epop.dataprovider.googlescholar.GoogleScholarGetterFromId.java

static List<Literature> getFromId(String userId) {
    // http://scholar.google.it/citations?user=q21xxm4AAAAJ&pagesize=100
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("user", userId));
    qparams.add(new BasicNameValuePair("pagesize", "100"));

    URI uri;/*from ww  w  . j ava 2  s. c o m*/
    String responseBody = null;
    try {
        uri = URIUtils.createURI("http", GOOGLE_SCHOLAR, -1, "", URLEncodedUtils.format(qparams, "UTF-8"),
                null);
        uri = new URI(uri.toString().replace("citations/?", "citations?"));
        HttpGet httpget = new HttpGet(uri);
        System.out.println(httpget.getURI());
        HttpClient httpclient = new DefaultHttpClient();
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpget, responseHandler);
        //System.out.println(responseBody);
        int counter = 1;
        String newResponseBody = responseBody;
        while (newResponseBody.contains("class=\"cit-dark-link\">Next &gt;</a>")) {
            URI newUri = new URI(uri.toString() + "&cstart=" + counter * 100);
            httpget = new HttpGet(newUri);
            System.out.println(httpget.getURI());
            httpclient = new DefaultHttpClient();
            newResponseBody = httpclient.execute(httpget, responseHandler);
            //System.out.println(newResponseBody);
            responseBody = responseBody + newResponseBody;
            counter++;
        }
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // return the result as string
    return parsePage(new StringReader(responseBody));
}

From source file:com.rusticisoftware.tincan.Verb.java

public Verb(String id) throws URISyntaxException {
    this(new URI(id));
}

From source file:eu.bittrade.libs.steemj.BaseIT.java

/**
 * Call this method in case the tests should be fired against a WebSocket
 * endpoint instead of using the default HTTPS endpoint.
 * /*from  w w  w  .  j a  v a 2 s.co  m*/
 * @throws URISyntaxException
 *             If the URL is wrong.
 */
public static void configureSteemWebSocketEndpoint() throws URISyntaxException {
    ArrayList<Pair<URI, Boolean>> endpoints = new ArrayList<>();

    ImmutablePair<URI, Boolean> webSocketEndpoint;
    webSocketEndpoint = new ImmutablePair<>(new URI("wss://steemd.steemit.com"), true);

    endpoints.add(webSocketEndpoint);
    config.setEndpointURIs(endpoints);
}

From source file:interactivespaces.service.web.client.internal.netty.NettyWebSocketClientService.java

@Override
public WebSocketClient newWebSocketClient(String uri, WebSocketHandler handler, Log log) {
    try {//  w  w w .  j  a v  a2 s  . c om
        URI u = new URI(uri);

        return new NettyWebSocketClient(u, handler, getSpaceEnvironment().getExecutorService(), log);
    } catch (URISyntaxException e) {
        throw new InteractiveSpacesException(String.format("Bad URI syntax for web socket URI: %s", uri), e);
    }
}

From source file:org.cloudfoundry.tools.io.compiler.ResourceFileObject.java

public ResourceFileObject(File file) {
    Assert.notNull(file, "File must not be null");
    this.file = file;
    try {/*w  ww .j  a v  a2  s. c  om*/
        this.uri = new URI(ResourceURL.PROTOCOL + ":" + getName());
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.econcept.pingconnectionutility.utility.PingConnectionUtility.java

private static void httpPingable(String targetURI) throws IOException, URISyntaxException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet();
    httpGet.setURI(new URI(targetURI));
    CloseableHttpResponse response = httpClient.execute(httpGet);

    int currentCode = response.getStatusLine().getStatusCode();
    try {//from w w  w.  j a  va2  s.  co  m

        if (currentCode >= 200 && currentCode < 300) {
            HttpEntity entity = response.getEntity();

            InputStream responseStream = entity.getContent();

            StringWriter writer = new StringWriter();

            IOUtils.copy(responseStream, writer, "UTF-8");

            System.out.println("Target Server are ok: " + currentCode);
            System.out.println(writer.toString());

            EntityUtils.consume(entity);
        } // if
        else {
            System.out.println("Target Server are not ok: " + currentCode);
        } // else
    } // try
    finally {
        response.close();
    } // finally

}