private String encode(String value) { try { //return URLEncoder.encode(value,"UTF-8"); return UriUtils.encodeQueryParam(value, "UTF-8"); } catch (UnsupportedEncodingException x) { throw new IllegalArgumentException(x); } }
qs.append(UriUtils.encodeQueryParam(param.getName(), encoding)); if (param.getValue() != null) { qs.append("="); qs.append(UriUtils.encodeQueryParam(param.getValue(), encoding));
@Test public void encodeQueryParam() { assertEquals("Invalid encoded result", "foobar", UriUtils.encodeQueryParam("foobar", CHARSET)); assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeQueryParam("foo bar", CHARSET)); assertEquals("Invalid encoded result", "foo%26bar", UriUtils.encodeQueryParam("foo&bar", CHARSET)); }
qs.append(UriUtils.encodeQueryParam(param.getName(), encoding)); if (param.getValue() != null) { qs.append("="); qs.append(UriUtils.encodeQueryParam(param.getValue(), encoding));
public URI build() { StringBuilder builder = new StringBuilder(url); try { if (!params.isEmpty()) { builder.append("?"); boolean first = true; for (String key : params.keySet()) { if (!first) { builder.append("&"); } else { first = false; } for (String value : params.get(key)) { builder.append(key + "=" + UriUtils.encodeQueryParam(value, "UTF-8")); } } } return new URI(builder.toString()); } catch (UnsupportedEncodingException ex) { // should not happen, UTF-8 is always supported throw new IllegalStateException(ex); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not create URI from [" + builder + "]: " + ex, ex); } }
/** * Encodes the given request parameter value. * * @param source must not be {@literal null}. * @return */ public static String encodeParameter(Object source) { Assert.notNull(source, "Request parameter value must not be null!"); try { return UriUtils.encodeQueryParam(source.toString(), ENCODING); } catch (Throwable e) { throw new IllegalStateException(e); } }
@Test void authorization_code_missing_required_scopes() throws Exception { String username = "testuser" + generator.generate(); String userScopes = "uaa.user"; ScimUser user = setUpUser(username, userScopes, OriginKeys.UAA, IdentityZone.getUaa().getId()); String clientId = "testclient" + generator.generate(); BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "uaa.user,other.scope", GRANT_TYPE_AUTHORIZATION_CODE, "uaa.resource", "http://localhost"); clientDetails.setClientSecret(SECRET); clientDetails.addAdditionalInformation(REQUIRED_USER_GROUPS, Arrays.asList("uaa.admin")); clientDetailsService.addClientDetails(clientDetails); String location = mockMvc.perform( get("/oauth/authorize") .param(RESPONSE_TYPE, "code") .param(CLIENT_ID, clientId) .session(getAuthenticatedSession(user)) .accept(MediaType.TEXT_HTML)) .andExpect(status().isFound()) .andReturn().getResponse().getHeader("Location"); assertThat(location, containsString("http://localhost")); MultiValueMap<String, String> queryParams = UriComponentsBuilder.fromUri(new URI(location)).build().getQueryParams(); assertNotNull(queryParams); assertNotNull(queryParams.getFirst("error")); assertNotNull(queryParams.getFirst("error_description")); assertThat( queryParams.getFirst("error_description"), containsString(UriUtils.encodeQueryParam("User does not meet the client's required group criteria.", "ISO-8859-1")) ); }
.toString(); String encodedRedirectUri = UriUtils.encodeQueryParam(redirectUri, "ISO-8859-1");
/** * Encodes the given request parameter value. * * @param source must not be {@literal null}. * @return */ public static String encodeParameter(Object source) { Assert.notNull(source, "Request parameter value must not be null!"); try { return UriUtils.encodeQueryParam(source.toString(), ENCODING); } catch (Throwable o_O) { throw new IllegalStateException(o_O); } }
public String createURL(SearchQuery query) throws Exception { String urlTemplate = getConfigProperties().getProperty(PROP_URL_QUERY); return urlTemplate.replace("{{QUERY}}", UriUtils.encodeQueryParam(query.getQuery(), "UTF-8")) .replace("{{ROWS}}", String.valueOf(query.getLimit())); }
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); }
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); }
return ""; return extraEncodeQuery(UriUtils.encodeQueryParam(value, "UTF-8"));
@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; }
UriUtils.encodeQueryParam(cql, "UTF-8"), query.getLimit());