Java Code Examples for org.springframework.web.util.UriUtils#encodeQueryParam()

The following examples show how to use org.springframework.web.util.UriUtils#encodeQueryParam() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrcidSmartNames.java    From conciliator with GNU General Public License v3.0 5 votes vote down vote up
private List<Result> searchSmartNames(SearchQuery query, String givenName, String familyName) throws Exception {
    String q = String.format("given-names:%s AND family-name:%s", givenName, familyName);
    String fields = createSearchFieldsQueryString(query);
    if(fields.length() > 0) {
        q += " " + fields;
    }
    String url = String.format("https://pub.orcid.org/v2.1/search/?rows=%d&q=", query.getLimit()) +
            UriUtils.encodeQueryParam(q, "UTF-8");
    return doSearch(query, url);
}
 
Example 2
Source File: OpenLibrary.java    From conciliator with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<Result> search(SearchQuery query) throws Exception {
    List<Result> results = new ArrayList<>();
    int tries = 0;

    // try twice, first with properties; if no results, try just the main search value
    while(results.size() == 0 && tries < 2) {
        String q = createQuery(query, tries == 0);

        String url = "https://openlibrary.org/search.json?q=" + UriUtils.encodeQueryParam(q, "UTF-8");
        getLog().debug("Making request to " + url);

        HttpURLConnection conn = getConnectionFactory().createConnection(url);

        JsonNode root = mapper.readTree(conn.getInputStream());
        JsonNode docs = root.get("docs");
        if(docs.isArray()) {
            Iterator<JsonNode> iter = docs.iterator();
            while(iter.hasNext() && results.size() < query.getLimit()) {
                JsonNode doc = iter.next();
                String title = doc.get("title").asText();
                String key = doc.get("key").asText();
                results.add(new Result(key, title, bookType, 1.0, false));
            }
        }

        tries++;
    }

    return results;
}
 
Example 3
Source File: OTXConnection.java    From OTX-Java-SDK with Apache License 2.0 5 votes vote down vote up
private URI buildURI(OTXEndpoints endpoint, Map<OTXEndpointParameters, ?> endpointParametersMap) throws URISyntaxException, MalformedURLException {

        String endpointString = endpoint.getEndpoint();
        if (endpointParametersMap != null) {
            boolean first = true;
            for (Map.Entry<OTXEndpointParameters, ?> otxEndpointParametersEntry : endpointParametersMap.entrySet()) {
                if (otxEndpointParametersEntry.getKey().isRestVariable()) {
                    endpointString = endpointString.replace("{" + otxEndpointParametersEntry.getKey().getParameterName() + "}", otxEndpointParametersEntry.getValue().toString());
                } else {
                    if (first) {
                        endpointString = endpointString + "?";
                        first = false;
                    }
                    try {
                        String parameterName = otxEndpointParametersEntry.getKey().getParameterName();
                        String value = UriUtils.encodeQueryParam(otxEndpointParametersEntry.getValue().toString(), "UTF-8");
                        endpointString = endpointString + String.format("%s=%s&", parameterName, value);
                    } catch (UnsupportedEncodingException e) {
                        log.error("Unpossible");
                    }
                }
            }
        }
        if (otxPort != null) {
            return new URL(otxScheme, otxHost, otxPort, endpointString).toURI();
        } else {
            return new URL(otxScheme, otxHost, endpointString).toURI();
        }
    }
 
Example 4
Source File: OrcidBase.java    From conciliator with GNU General Public License v3.0 4 votes vote down vote up
protected List<Result> searchKeyword(SearchQuery query) throws Exception {
    String q = createQueryString(query);
    String url = String.format("https://pub.orcid.org/v2.1/search/?rows=%d&q=", query.getLimit()) +
            UriUtils.encodeQueryParam(q, "UTF-8");
    return doSearch(query, url);
}