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:no.digipost.api.useragreements.client.filters.request.RequestToSign.java

public String getPath() {
    try {//from  w w  w.  j a v a2  s.co  m
        String path = new URI(clientRequest.getRequestLine().getUri()).getPath();
        return path != null ? path : "";
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:angel.zhuoxiu.library.pusher.PusherConnection.java

public void connect() {
    try {/*from  w  ww.j  a v  a 2  s  .c  o  m*/
        URI url = new URI(pusher.getUrl());
        Log.d(LOG_TAG, "Connecting to " + url.toString());

        mWebSocket = new WebSocketConnection(url);
        mWebSocket.setEventHandler(new WebSocketEventHandler() {
            @Override
            public void onOpen() {
                Log.d(LOG_TAG, "Successfully opened Websocket");
            }

            @Override
            public void onMessage(WebSocketMessage message) {
                Log.d(LOG_TAG, "Received from Websocket " + message.getText());

                try {
                    JSONObject parsed = new JSONObject(message.getText());
                    String eventName = parsed.getString("event");
                    String channelName = parsed.optString("channel", null);
                    String eventData = parsed.getString("data");

                    if (eventName.equals(Pusher.PUSHER_EVENT_CONNECTION_ESTABLISHED)) {
                        JSONObject parsedEventData = new JSONObject(eventData);
                        String socketId = parsedEventData.getString("socket_id");
                        pusher.onConnected(socketId);
                    } else {
                        pusher.dispatchEvents(eventName, eventData, channelName);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onClose() {
                Log.d(LOG_TAG, "Successfully closed Websocket");
            }
        });
        mWebSocket.connect();

    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (WebSocketException e) {
        e.printStackTrace();
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtilsTest.java

@Test
public void testExtractQueryParameters_Empty() throws Exception {
    final Properties properties = ModelUtils.extractQueryPropertiesFromURI(new URI("file://hello"));
    assertTrue(properties.isEmpty());//from  ww  w. j a  va 2s.c o m
}

From source file:com.ibm.watson.app.qaclassifier.ScanLogs.java

public static void getBluemixLogs(String user, String password, String target, String org, String space,
        String app) throws Exception {
    CloudFoundryClient client;/*from  w  ww  .j a va 2s . co  m*/
    if (user == null || user.isEmpty()) {
        System.out.println("No username/password provided, using saved credentials");
        client = new CloudFoundryClient(new CloudCredentials(new TokensFile().retrieveToken(new URI(target))),
                new URL(target), org, space);
    } else {
        client = new CloudFoundryClient(new CloudCredentials(user, password), new URL(target), org, space);
    }

    client.openFile(app, 0, "logs/" + LOG_FILE, new ClientHttpResponseCallback() {
        @Override
        public void onClientHttpResponse(ClientHttpResponse clientHttpResponse) throws IOException {
            Path logDestination = Paths.get(LOG_FILE);
            if (Files.exists(logDestination)) {
                Files.delete(logDestination);
            }
            Files.copy(clientHttpResponse.getBody(), logDestination);
        }
    });
}

From source file:se.kodapan.io.http.HttpGetInputStream.java

public HttpGetInputStream(String uri, HttpClient httpClient) throws URISyntaxException {
    this.uri = new URI(uri);
    this.httpClient = httpClient;
}

From source file:org.grameenfoundation.consulteca.utils.HttpHelpers.java

/**
 * Convenience overload that takes a string
 *//*from w  ww  .  j  av a2  s.  c  o  m*/
public static String fetchContent(String remoteAddress) {
    try {
        return fetchContent(new URI(remoteAddress), null);
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:org.elegosproject.romupdater.JSONParser.java

public static InputStream getJSONData(String url) throws Exception {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
    DefaultHttpClient httpClient = new DefaultHttpClient();
    URI uri;/*from w  w w  . j  a  va  2 s . c  om*/
    InputStream data = null;
    try {
        uri = new URI(url);
        HttpGet method = new HttpGet(uri);
        HttpResponse response = httpClient.execute(method);
        data = response.getEntity().getContent();
    } catch (Exception e) {
        Log.e(TAG, "Unable to download file: " + e);
        throw e;
    }
    return data;
}

From source file:com.arpnetworking.tsdcore.sinks.circonus.api.CheckBundleResponse.java

private CheckBundleResponse(final Builder builder) {
    _cid = builder._cid;//from   www  . j  a va2s  .  co m
    try {
        _url = new URI(builder._config.get("submission_url"));
    } catch (final URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    _displayName = builder._displayName;
}

From source file:Main.java

/** Crea una URI a partir de un nombre de fichero local o una URL.
 * @param file Nombre del fichero local o URL
 * @return URI (<code>file://</code>) del fichero local o URL
 * @throws URISyntaxException Si no se puede crear una URI soportada a partir de la cadena de entrada */
public static URI createURI(final String file) throws URISyntaxException {

    if (file == null || file.isEmpty()) {
        throw new IllegalArgumentException("No se puede crear una URI a partir de un nulo"); //$NON-NLS-1$
    }/*from   ww w  . ja  va  2 s .c om*/

    String filename = file.trim();

    if (filename.isEmpty()) {
        throw new IllegalArgumentException("La URI no puede ser una cadena vacia"); //$NON-NLS-1$
    }

    // Cambiamos los caracteres Windows
    filename = filename.replace('\\', '/');

    // Realizamos los cambios necesarios para proteger los caracteres no
    // seguros
    // de la URL
    filename = filename.replace(" ", "%20") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("<", "%3C") //$NON-NLS-1$ //$NON-NLS-2$
            .replace(">", "%3E") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("\"", "%22") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("{", "%7B") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("}", "%7D") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("|", "%7C") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("^", "%5E") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("[", "%5B") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("]", "%5D") //$NON-NLS-1$ //$NON-NLS-2$
            .replace("`", "%60"); //$NON-NLS-1$ //$NON-NLS-2$

    final URI uri = new URI(filename);

    // Comprobamos si es un esquema soportado
    final String scheme = uri.getScheme();
    for (final String element : SUPPORTED_URI_SCHEMES) {
        if (element.equals(scheme)) {
            return uri;
        }
    }

    // Si el esquema es nulo, aun puede ser un nombre de fichero valido
    // El caracter '#' debe protegerse en rutas locales
    if (scheme == null) {
        filename = filename.replace("#", "%23"); //$NON-NLS-1$ //$NON-NLS-2$
        return createURI("file://" + filename); //$NON-NLS-1$
    }

    // Miramos si el esquema es una letra, en cuyo caso seguro que es una
    // unidad de Windows ("C:", "D:", etc.), y le anado el file://
    // El caracter '#' debe protegerse en rutas locales
    if (scheme.length() == 1 && Character.isLetter((char) scheme.getBytes()[0])) {
        filename = filename.replace("#", "%23"); //$NON-NLS-1$ //$NON-NLS-2$
        return createURI("file://" + filename); //$NON-NLS-1$
    }

    throw new URISyntaxException(filename, "Tipo de URI no soportado"); //$NON-NLS-1$

}

From source file:AIR.Dictionary.DictionaryConnection.java

public String lookup(String word) {

    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        //        // make word url safe
        word = UrlEncoderDecoderUtils.encode(word);

        // create url to send
        String baseUrl = _apiUrl + word;
        URI restAPIURI = new URI(baseUrl + "?key=" + _apiKey);
        // create client
        HttpGet request = new HttpGet(restAPIURI);
        request.setHeader("Accept-Charset", "UTF-8");
        HttpResponse response = httpClient.execute(request);

        String responseXML = EntityUtils.toString(response.getEntity(), "UTF-8");
        return responseXML;

    } catch (Exception e) {
        _logger.error("Error Calling Dictionary rest API ", e);
    }/*www.j ava  2s . c om*/
    return null;
}