/** @deprecated */ public OAuthMessage invoke(OAuthMessage request, ParameterStyle style) throws IOException, OAuthException { return invoke(request, style.getReplacement()); }
/** @deprecated */ public OAuthResponseMessage access(OAuthMessage request, ParameterStyle style) throws IOException { return access(request, style.getReplacement()); }
@Test public void testGetWebSudoProtectedResourcePermitsOAuthToByPassWebSudo() throws Exception { // setup the consumer first. setUpOAuthConsumer(); OAuthAccessor accessor = createAccessor(CONSUMER_KEY); OAuthClient client = new OAuthClient(new HttpClient4()); // make the request. OAuthMessage response = client.invoke(accessor, getResourceUri().toString(), ImmutableMap.of("oauth_token", "").entrySet()); // assert stuff assertEquals(HttpServletResponse.SC_OK, ((OAuthResponseMessage) response).getHttpResponse().getStatusCode()); assertEquals("hello", response.readBodyAsString()); }
public static OAuthClient newOAuthClient(URI address) throws IOException { return new OAuthClient(new HttpClient4(newClientPool(address))); }
/** * Send a request message to the service provider and get the response. * * @return the response * @throws IOException * failed to communicate with the service provider * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public OAuthMessage invoke(OAuthMessage request, net.oauth.ParameterStyle style) throws IOException, OAuthException { OAuthResponseMessage response = access(request, style); if ((response.getHttpResponse().getStatusCode() / 100) != 2) { throw response.toOAuthProblemException(); } return response; }
/** @return an excerpt from the data copied. */ @SuppressWarnings("resource") public static byte[] copyAll(InputStream from, OutputStream into) throws IOException { final ExcerptInputStream ex = new ExcerptInputStream(from); ex.copyAll(into); return ex.getExcerpt(); }
/** * Construct a request message, send it to the service provider and get the * response. * * @return the response * @throws URISyntaxException * the given url isn't valid syntactically * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ @SuppressWarnings("rawtypes") public OAuthMessage invoke(OAuthAccessor accessor, String url, Collection<? extends Map.Entry> parameters) throws IOException, OAuthException, URISyntaxException { return invoke(accessor, null, url, parameters); }
/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, null); }
@Override protected void completeParameters() throws IOException { super.completeParameters(); String body = readBodyAsString(); if (body != null) { addParameters(OAuth.decodeForm(body.trim())); } }
/** * Encapsulate this message as an exception. Read and close the body of this * message. */ public OAuthProblemException toOAuthProblemException() throws IOException { OAuthProblemException problem = new OAuthProblemException(); try { getParameters(); // decode the response body } catch (IOException ignored) { } problem.getParameters().putAll(getDump()); try { InputStream b = getBodyAsStream(); if (b != null) { b.close(); // release resources } } catch (IOException ignored) { } return problem; }
public final InputStream getBody() throws IOException { if (body == null) { InputStream raw = openBody(); if (raw != null) { body = new ExcerptInputStream(raw); } } return body; }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
/** * Construct an HTTP request from this OAuth message. * * @param style * where to put the OAuth parameters, within the HTTP request * @deprecated use HttpMessage.newRequest */ public HttpMessage toHttpRequest(OAuthClient.ParameterStyle style) throws IOException { return HttpMessage.newRequest(this, style.getReplacement()); }
@Override public void requireParameters(String... names) throws OAuthProblemException, IOException { try { super.requireParameters(names); } catch (OAuthProblemException problem) { problem.getParameters().putAll(getDump()); throw problem; } }
/** * Send a request and return the response. Don't try to decide whether the * response indicates success; merely return it. */ public OAuthResponseMessage access(OAuthMessage request, net.oauth.ParameterStyle style) throws IOException { HttpMessage httpRequest = HttpMessage.newRequest(request, style); HttpResponseMessage httpResponse = http.execute(httpRequest, httpParameters); httpResponse = HttpMessageDecoder.decode(httpResponse); return new OAuthResponseMessage(httpResponse); }
/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @param httpMethod * typically OAuthMessage.POST or OAuthMessage.GET, or null to * use the default method. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor, String httpMethod) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, httpMethod, null); }
/** The first few bytes of data, plus ELLIPSIS if there are more bytes. */ public byte[] getExcerpt() throws IOException { if (taken < excerpt.length) { final int mark = Math.min(given, taken); given = Integer.MAX_VALUE; while (taken < excerpt.length) { read(excerpt, taken, LIMIT - taken); } given = mark; } return excerpt; }
OAuthClient oAuthClient = new OAuthClient(new HttpClient4()); try { oAuthClient.getRequestToken(accessor); } catch (IOException e) { e.printStackTrace(); } catch (OAuthException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }
/** Copy all the data from this stream to the given output stream. */ private void copyAll(OutputStream into) throws IOException { byte[] b = new byte[1024]; for (int n; 0 < (n = read(b));) { into.write(b, 0, n); } }