Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:org.cruk.genologics.api.jaxb.URIAdapter.java

/**
 * Remove any "state=" parameter from the given URI.
 *
 * @param uri The URI to modify./*  ww  w . j a  v a 2s .  c o m*/
 *
 * @return A new URI which is {@code uri} without the state information.
 */
public static URI removeStateParameter(URI uri) {
    if (uri != null) {
        try {
            uri = new URI(removeStateParameter(uri.toString()));
        } catch (URISyntaxException e) {
            throw new AssertionError(
                    "Removing state information from URI " + uri + " failed: " + e.getMessage());
        }
    }
    return uri;
}

From source file:com.orange.ngsi.server.NgsiValidation.java

private static boolean nullOrEmpty(URI e) {
    return e == null || e.toString().isEmpty();
}

From source file:email.mandrill.MandrillApiHandler.java

public static List<Map<String, Object>> getTags() {
    List<Map<String, Object>> mandrillTagList = new ArrayList<>();

    try {//from  www  .j  a v a 2 s .com

        HttpClient httpclient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("https://mandrillapp.com/api/1.0/tags/list.json");
        URI uri = new URIBuilder(httpGet.getURI()).addParameter("key", SendEmail.MANDRILL_KEY).build();
        logger.info("Getting mandrill tags: " + uri.toString());
        Gson gson = new Gson();
        httpGet.setURI(uri);

        //Execute and get the response.
        HttpResponse response = httpclient.execute(httpGet);
        HttpEntity responseEntity = response.getEntity();
        if (responseEntity != null) {
            String jsonContent = EntityUtils.toString(responseEntity);
            logger.info(jsonContent);
            // Create a Reader from String
            Reader stringReader = new StringReader(jsonContent);

            // Pass the string reader to JsonReader constructor
            JsonReader reader = new JsonReader(stringReader);
            reader.setLenient(true);
            mandrillTagList = gson.fromJson(reader, List.class);

        }

    } catch (URISyntaxException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParseException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return mandrillTagList;
}

From source file:Neo4JDataExporter.java

private static URI addRelationship(URI startNode, URI endNode, String relationshipType, String jsonAttributes)
        throws URISyntaxException {
    URI fromUri = new URI(startNode.toString() + "/relationships");
    String relationshipJson = generateJsonRelationship(endNode, relationshipType, jsonAttributes);

    WebResource resource = Client.create().resource(fromUri);
    // POST JSON to the relationships URI
    ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
            .entity(relationshipJson).post(ClientResponse.class);

    final URI location = response.getLocation();
    System.out.println(String.format("POST to [%s], status code [%d], location header [%s]", fromUri,
            response.getStatus(), location.toString()));

    response.close();//from w  ww .j a va  2s.c om
    return location;
}

From source file:net.modelbased.proasense.storage.registry.RestRequest.java

public static String deleteSensor(URI uri, Sensor sensor) {
    URI target = null;//from www  .  j  a v a 2s .c  om
    try {
        target = new URI(uri.toString() + SENSOR_PATH + "/" + sensor.getName());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    HttpClient client = new DefaultHttpClient();
    HttpDelete request = new HttpDelete(target);
    request.setHeader("Content-type", "application/json");
    String response = null;
    try {
        response = resolveResponse(client.execute(request));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return response;
}

From source file:Main.java

public static Node readXML(URI uri) {
    try {//  w  ww .ja  v  a 2 s.c  om
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();

        Document doc = builder.parse(uri.toString());
        return doc.getDocumentElement();
    } catch (SAXException saxEx) {
        throw new IllegalArgumentException("readXML() Caught SAXException: ", saxEx);
    } catch (IOException ioEx) {
        throw new IllegalArgumentException("readXML() Caught IOException: " + ioEx.getMessage(), ioEx);
    } catch (ParserConfigurationException parsEx) {
        throw new IllegalArgumentException("readXML() Caught ParserConfigurationException: ", parsEx);
    } // try - catch
}

From source file:net.modelbased.proasense.storage.registry.RestRequest.java

public static String putData(URI uri, String data) {
    URI target = null;/* w w  w  .j  a  va  2  s . c o  m*/
    try {
        target = new URI(uri.toString() + DISPATCHER_PATH);
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
    }
    HttpClient client = new DefaultHttpClient();
    HttpPut request = new HttpPut(target);
    request.setHeader("Content-type", "application/json");
    String response = null;
    try {
        StringEntity seContent = new StringEntity(data);
        seContent.setContentType("text/json");
        request.setEntity(seContent);
        response = resolveResponse(client.execute(request));
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (response.trim().length() > 2) {
        throw new IllegalAccessError("Sensor not registred: " + response);
    }
    return response;
}

From source file:email.mandrill.MandrillApiHandler.java

public static Map<String, Object> getEmailDetails(String mandrillEmailId)
        throws URISyntaxException, IOException {
    Map<String, Object> emailDetails = new HashMap<>();
    HttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet("https://mandrillapp.com/api/1.0/messages/info.json");
    URI uri = new URIBuilder(httpGet.getURI()).addParameter("key", SendEmail.MANDRILL_KEY)
            .addParameter("id", mandrillEmailId).build();
    logger.info("Getting Email details: " + uri.toString());
    Gson gson = new Gson();
    httpGet.setURI(uri);//  ww w .j  a  va 2 s  .  c om

    //Execute and get the response.
    HttpResponse response = httpclient.execute(httpGet);
    HttpEntity responseEntity = response.getEntity();
    if (responseEntity != null) {
        String jsonContent = EntityUtils.toString(responseEntity);
        logger.info(jsonContent);
        // Create a Reader from String
        Reader stringReader = new StringReader(jsonContent);

        // Pass the string reader to JsonReader constructor
        JsonReader reader = new JsonReader(stringReader);
        reader.setLenient(true);
        Map<String, Object> mandrillEmailDetails = gson.fromJson(reader, Map.class);
        emailDetails.put("sent_on", mandrillEmailDetails.get("ts"));
        emailDetails.put("mandrill_id", mandrillEmailDetails.get("_id"));
        emailDetails.put("email_state", mandrillEmailDetails.get("state"));
        emailDetails.put("subject", mandrillEmailDetails.get("subject"));
        emailDetails.put("email", mandrillEmailDetails.get("email"));
        emailDetails.put("tags", mandrillEmailDetails.get("tags"));
        emailDetails.put("opens", mandrillEmailDetails.get("opens"));
        emailDetails.put("clicks", mandrillEmailDetails.get("clicks"));
        emailDetails.put("sender", mandrillEmailDetails.get("sender"));

    }

    return emailDetails;
}

From source file:org.soyatec.windowsazure.authenticate.HttpRequestAccessor.java

/**
 * Given the host suffix part, service name and account name, this method
 * constructs the account Uri/*  w  w  w.j a v  a 2 s  . co m*/
 * 
 * @param hostSuffix
 * @param accountName
 * @return URI
 */
private static URI constructHostStyleAccountUri(URI hostSuffix, String accountName) {
    URI serviceUri = hostSuffix;
    String hostString = hostSuffix.toString();
    if (!hostString.startsWith(HttpHost.DEFAULT_SCHEME_NAME)) {
        hostString = HttpHost.DEFAULT_SCHEME_NAME + "://" + hostString;
        serviceUri = URI.create(hostString);
    }
    // Example:
    // Input: serviceEndpoint="http://blob.windows.net/",
    // accountName="youraccount"
    // Output: accountUri="http://youraccount.blob.windows.net/"
    // serviceUri in our example would be "http://blob.windows.net/"
    String accountUriString = null;
    if (serviceUri.getPort() == -1) {
        accountUriString = MessageFormat.format("{0}{1}{2}.{3}/",
                Utilities.isNullOrEmpty(serviceUri.getScheme()) ? HttpHost.DEFAULT_SCHEME_NAME
                        : serviceUri.getScheme(),
                SCHEME_DELIMITER, accountName, serviceUri.getHost());
    } else {
        accountUriString = MessageFormat.format("{0}{1}{2}.{3}:{4}/",
                Utilities.isNullOrEmpty(serviceUri.getScheme()) ? HttpHost.DEFAULT_SCHEME_NAME
                        : serviceUri.getScheme(),
                SCHEME_DELIMITER, accountName, serviceUri.getHost(), serviceUri.getPort());
    }

    return URI.create(accountUriString);
}

From source file:Neo4JDataExporter.java

private static String generateJsonRelationship(URI endNode, String relationshipType, String... jsonAttributes) {
    StringBuilder sb = new StringBuilder();
    sb.append("{ \"to\" : \"");
    sb.append(endNode.toString());
    sb.append("\", ");

    sb.append("\"type\" : \"");
    sb.append(relationshipType);//from w w  w  . j a  v  a  2  s . c o  m
    if (jsonAttributes == null || jsonAttributes.length < 1) {
        sb.append("\"");
    } else {
        sb.append("\", \"data\" : ");
        for (int i = 0; i < jsonAttributes.length; i++) {
            sb.append(jsonAttributes[i]);
            if (i < jsonAttributes.length - 1) { // Miss off the final comma
                sb.append(", ");
            }
        }
    }

    sb.append(" }");
    return sb.toString();
}