/** * Construct a form-urlencoded document containing the given sequence of * name/parameter pairs. */ private static String percentEncode(Iterable<? extends Map.Entry<String, String[]>> parameters) { ByteArrayOutputStream b = new ByteArrayOutputStream(); // IOException should not be throws as we are not messing around with it between creation and use // (e.g. by closing it) but the methods on the OutputStream interface don't know that try { percentEncode(parameters, b); return new String(b.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } }
private static String canonicalizeQueryParameters(CanonicalHttpRequest request) throws UnsupportedEncodingException { String result = ""; if (null != request.getParameterMap()) { List<ComparableParameter> parameterList = new ArrayList<ComparableParameter>(request.getParameterMap().size()); for (Map.Entry<String, String[]> parameter : request.getParameterMap().entrySet()) { if (!JwtConstants.JWT_PARAM_NAME.equals(parameter.getKey())) { parameterList.add(new ComparableParameter(parameter)); } } Collections.sort(parameterList); result = percentEncode(getParameters(parameterList)); } return result; }