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:com.netflix.iep.http.ClientConfig.java

/** Create a client config instance based on a URI. */
static ClientConfig fromUri(Configuration config, URI uri) {
    Matcher m;/*from  w ww.jav a 2  s. c  om*/
    ClientConfig cfg;
    switch (uri.getScheme()) {
    case "niws":
        m = NIWS_URI.matcher(uri.toString());
        if (m.matches()) {
            final URI newUri = URI.create(fixPath(relative(uri)));
            cfg = new ClientConfig(config, m.group(1), null, uri, newUri);
        } else {
            throw new IllegalArgumentException("invalid niws uri: " + uri);
        }
        break;
    case "vip":
        m = VIP_URI.matcher(uri.toString());
        if (m.matches()) {
            cfg = new ClientConfig(config, m.group(1), m.group(2), uri, URI.create(relative(uri)));
        } else {
            throw new IllegalArgumentException("invalid vip uri: " + uri);
        }
        break;
    default:
        cfg = new ClientConfig(config, "default", null, uri, uri);
        break;
    }
    return cfg;
}

From source file:org.unitedinternet.cosmo.dav.caldav.report.MultigetReport.java

private static URL normalizeHref(URL context, String href) throws CosmoDavException {
    URL url = null;/*from ww  w.  ja v a  2s  . c  om*/
    try {
        url = new URL(context, href);
        // check that the URL is escaped. it's questionable whether or
        // not we should all unescaped URLs, but at least as of
        // 10/02/2007, iCal 3.0 generates them
        url.toURI();
        return url;
    } catch (URISyntaxException e) {
        try {
            URI escaped = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                    url.getRef());
            return new URL(escaped.toString());
        } catch (URISyntaxException | MalformedURLException e2) {
            throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new BadRequestException("Malformed href " + href + ": " + e.getMessage());
    }
}

From source file:org.altchain.neo4j.database.Database.java

public 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);
    ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
            .entity(relationshipJson).post(ClientResponse.class);

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

    response.close();/*from w ww .  ja v a 2 s  .  c om*/
    return location;
}

From source file:eu.eubrazilcc.lvl.oauth2.rest.UserRegistration.java

private static final String emailActivationMessage(final String username, final String email,
        final String activationCode, final URI portalUri) {
    return "Dear " + username + ",\n\n"
            + "Thank you for registering at Leishmaniasis Virtual Laboratory. Please, validate your email address in "
            + portalUri.toString() + "/#account/validation" + " " + "using the following code:\n\n"
            + activationCode + "\n\n"
            + "You may also validate your email address by clicking on this link or copying and pasting it in your browser:\n\n"
            + portalUri.toString() + "/#account/validation/" + urlEncodeUtf8(email) + "/" + activationCode
            + "\n\n"
            + "After validating your email address, you can log in the portal directly using email and password used for account registration.\n\n"
            + "Leish VirtLab team";

}

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;
    String responseBody = null;/*from w  w w . java  2 s .c o  m*/
    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:org.wrml.runtime.rest.RestUtils.java

public static final URI encodeUri(final URI uri) {

    String uriString;/*from  w  w  w. j a v  a 2s  .com*/
    try {
        uriString = URLEncoder.encode(uri.toString(), DEFAULT_ENCODING);
    } catch (final UnsupportedEncodingException e) {
        return null;
    }

    return URI.create(uriString);
}

From source file:io.druid.storage.s3.S3DataSegmentPuller.java

public static URI checkURI(URI uri) {
    if (uri.getScheme().equalsIgnoreCase(scheme)) {
        uri = URI.create("s3" + uri.toString().substring(scheme.length()));
    } else if (!uri.getScheme().equalsIgnoreCase("s3")) {
        throw new IAE("Don't know how to load scheme for URI [%s]", uri.toString());
    }/*from  w w  w.ja  v a 2  s. com*/
    return uri;
}

From source file:org.altchain.neo4j.database.Database.java

public 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  ava 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();
}

From source file:gobblin.util.ClustersNames.java

private static String normalizeClusterUrl(String clusterIdentifier) {
    try {/*  w  w w. j av a  2 s . c o  m*/
        URI uri = new URI(clusterIdentifier.trim());
        // URIs without protocol prefix
        if (!uri.isOpaque() && null != uri.getHost()) {
            clusterIdentifier = uri.getHost();
        } else {
            clusterIdentifier = uri.toString().replaceAll("[/:]", " ").trim().replaceAll(" ", "_");
        }
    } catch (URISyntaxException e) {
        //leave ID as is
    }

    return clusterIdentifier;
}

From source file:eu.planets_project.tb.impl.services.mockups.workflow.IdentifyWorkflow.java

public static void collectIdentifyResults(List<MeasurementImpl> recs, IdentifyResult ident, DigitalObject dob) {
    if (ident == null)
        return;//from  w w w.j  ava2 s .c  o  m
    if (ident.getTypes() != null) {
        for (URI format_uri : ident.getTypes()) {
            if (format_uri != null) {
                recs.add(new MeasurementImpl(TecRegMockup.PROP_DO_FORMAT, format_uri.toString()));
            }
        }
    }
    if (ident.getMethod() != null) {
        recs.add(new MeasurementImpl(TecRegMockup.PROP_SERVICE_IDENTIFY_METHOD, ident.getMethod().name()));
    }
    // Store the size:
    recs.add(new MeasurementImpl(TecRegMockup.PROP_DO_SIZE, "" + getContentSize(dob)));
    return;
}