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 scheme, String userInfo, String host, int port, String path, String query, String fragment)
        throws URISyntaxException 

Source Link

Document

Constructs a hierarchical URI from the given components.

Usage

From source file:Main.java

public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("http", "userInfo", "java2s.com", 80, "/path", "query", "fragment");

    System.out.println(uri);/* w w w.  ja  v a2  s .c  om*/
}

From source file:com.mobius.software.mqtt.performance.controller.ControllerRunner.java

public static void main(String[] args) {
    try {//  w  w w.  j  a  va 2  s  .c o m
        /*URI baseURI = URI.create(args[0].replace("-baseURI=", ""));
        configFile = args[1].replace("-configFile=", "");*/
        String userDir = System.getProperty("user.dir");
        System.out.println("user.dir: " + userDir);
        setConfigFilePath(userDir + "/config.properties");
        Properties prop = new Properties();
        prop.load(new FileInputStream(configFile));
        System.out.println("properties loaded...");

        String hostname = prop.getProperty("hostname");
        Integer port = Integer.parseInt(prop.getProperty("port"));
        URI baseURI = new URI(null, null, hostname, port, null, null, null);

        configureConsoleLogger();
        System.out.println("starting http server...");
        JerseyServer server = new JerseyServer(baseURI);
        System.out.println("http server started");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("press any key to stop: ");
        br.readLine();
        server.terminate();
    } catch (Throwable e) {
        logger.error("AN ERROR OCCURED: " + e.getMessage());
        e.printStackTrace();
    } finally {
        System.exit(0);
    }
}

From source file:Main.java

/**
 * Combine a host and port into an authority string.
 *///from  w w  w  . jav  a 2 s  . co m
public static String authorityFromHostAndPort(String host, int port) {
    try {
        return new URI(null, null, host, port, null, null, null).getAuthority();
    } catch (URISyntaxException ex) {
        throw new IllegalArgumentException("Invalid host or port: " + host + " " + port, ex);
    }
}

From source file:Main.java

private static String escapeUrlString(String urlString) throws MalformedURLException, URISyntaxException {
    URL url = new URL(urlString);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    return uri.toURL().toString();
}

From source file:Main.java

public static String encodeDocumentUrl(String urlString) {
    try {//from w  ww .j  a  v  a2  s.c o m

        URL url = new URL(urlString);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());

        return uri.toASCIIString();

    } catch (MalformedURLException e) {
        return null;
    } catch (URISyntaxException e) {
        return null;
    }

}

From source file:io.syndesis.credential.BaseCredentialProvider.java

protected static String callbackUrlFor(final URI baseUrl,
        final MultiValueMap<String, String> additionalParams) {
    final String path = baseUrl.getPath();

    final String callbackPath = path + "credentials/callback";

    try {/*from ww w .j  a  v  a2 s . c  om*/
        final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath,
                null, null);

        return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString();
    } catch (final URISyntaxException e) {
        throw new IllegalStateException("Unable to generate callback URI", e);
    }
}

From source file:org.apache.hyracks.tests.integration.TestUtil.java

static URI uri(String path) throws URISyntaxException {
    return new URI("http", null, HOST, PORT, path, null, null);
}

From source file:com.jbsoft.musync.providers.ArtistImageProvider.java

public String getArtistPhotoUrl() {

    String string_url = "http://developer.echonest.com/api/v4/artist/images?api_key=" + API_KEY + "&name="
            + query + "&license=cc-by-sa";

    // First formate the url to accept any format/paramaters

    try {//from   www.j  a v a2s. c o m
        url = new URL(string_url);
        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    try {

        Log.d("GoogleImageProvider", "URL IS " + string_url);

        final JSONParser jsonParser = new JSONParser();
        HttpUrlConnection mConnection = new HttpUrlConnection();

        String response = mConnection.sslhttpgetdata(url.toString());

        if (response != null) {
            JSONObject jObject = jsonParser.getJSONFromString(response);

            JSONObject object = jObject.getJSONObject("response");
            JSONArray array = object.getJSONArray("images");
            Log.d(TAG, "Response is " + object.toString());

            JSONObject first = array.getJSONObject(0);
            Log.d(TAG, "Images[0] is " + first.toString());
            link = first.getString("url");
            mLinks.add(link);
            Log.d(TAG, "URL IS " + link);
        } else {
            Log.d(TAG, "Response returned NULL");
        }

    } catch (JSONException e) {

        e.printStackTrace();
    }

    Log.d(TAG, "Link is " + link);
    return link;

}

From source file:com.foundationdb.http.HttpThreadedLoginIT.java

private static int openRestURL(String userInfo, int port, String path) throws Exception {
    HttpClient client = new DefaultHttpClient();
    URI uri = new URI("http", userInfo, "localhost", port, path, null, null);
    HttpGet get = new HttpGet(uri);
    HttpResponse response = client.execute(get);
    int code = response.getStatusLine().getStatusCode();
    EntityUtils.consume(response.getEntity());
    client.getConnectionManager().shutdown();
    return code;/*from  ww  w  .  ja va 2 s.  c o m*/
}

From source file:com.netflix.curator.ensemble.exhibitor.DefaultExhibitorRestClient.java

@Override
public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception {
    URI uri = new URI(useSsl ? "https" : "http", null, hostname, port, uriPath, null, null);
    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    connection.addRequestProperty("Accept", mimeType);
    StringBuilder str = new StringBuilder();
    InputStream in = new BufferedInputStream(connection.getInputStream());
    try {//ww  w  .ja  v  a  2  s . c o  m
        for (;;) {
            int b = in.read();
            if (b < 0) {
                break;
            }
            str.append((char) (b & 0xff));
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
    return str.toString();
}