public static HttpParameters decodeForm(InputStream content) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( content)); StringBuilder sb = new StringBuilder(); String line = reader.readLine(); while (line != null) { sb.append(line); line = reader.readLine(); } return decodeForm(sb.toString()); }
/** * Collects HTTP GET query string parameters as per OAuth Core 1.0 spec * section 9.1.1 */ protected void collectQueryParameters(HttpRequest request, HttpParameters out) { String url = request.getRequestUrl(); int q = url.indexOf('?'); if (q >= 0) { // Combine the URL query string with the other parameters: out.putAll(OAuth.decodeForm(url.substring(q + 1)), true); } }
/** * Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec * section 9.1.1 */ protected void collectBodyParameters(HttpRequest request, HttpParameters out) throws IOException { // collect x-www-form-urlencoded body params String contentType = request.getContentType(); if (contentType != null && contentType.startsWith(OAuth.FORM_ENCODED)) { InputStream payload = request.getMessagePayload(); out.putAll(OAuth.decodeForm(payload), true); } }
@Test public void shouldCorrectlyFormDecodeParameters() { HttpParameters params = OAuth.decodeForm("one=" + reservedCharactersEncoded + "&" + "one=another&" + reservedCharactersEncoded + "=" + rfc3986UnreservedCharacters); assertTrue(params.size() == 3); Iterator<String> iter1 = params.get("one").iterator(); assertEquals(rfc3986ReservedCharacters, iter1.next()); assertEquals("another", iter1.next()); Iterator<String> iter2 = params.get(rfc3986ReservedCharacters).iterator(); assertEquals(rfc3986UnreservedCharacters, iter2.next()); }
@Test public void shouldSignUrl() throws Exception { OAuthConsumer consumer = buildConsumer(CONSUMER_KEY, CONSUMER_SECRET, null); consumer.setTokenWithSecret(TOKEN, TOKEN_SECRET); String result = consumer.sign("http://www.example.com?q=1"); assertNotNull(result); String[] parts = result.split("\\?"); assertEquals("parameters are missing", 2, parts.length); assertEquals("http://www.example.com", parts[0]); HttpParameters params = OAuth.decodeForm(parts[1]); assertAllOAuthParametersExist(params); assertEquals("1", params.getFirst("q")); }
public static HttpParameters decodeForm(InputStream content) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( content)); StringBuilder sb = new StringBuilder(); String line = reader.readLine(); while (line != null) { sb.append(line); line = reader.readLine(); } return decodeForm(sb.toString()); }
/** * Collects HTTP GET query string parameters as per OAuth Core 1.0 spec * section 9.1.1 */ protected void collectQueryParameters(HttpRequest request, HttpParameters out) { String url = request.getRequestUrl(); int q = url.indexOf('?'); if (q >= 0) { // Combine the URL query string with the other parameters: out.putAll(OAuth.decodeForm(url.substring(q + 1)), true); } }
HttpParameters responseParams = OAuth.decodeForm(response.getContent());
/** * Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec * section 9.1.1 */ protected void collectBodyParameters(HttpRequest request, HttpParameters out) throws IOException { // collect x-www-form-urlencoded body params String contentType = request.getContentType(); if (contentType != null && contentType.startsWith(OAuth.FORM_ENCODED)) { InputStream payload = request.getMessagePayload(); out.putAll(OAuth.decodeForm(payload), true); } }
HttpParameters responseParams = OAuth.decodeForm(response.getContent());