private Error(OAuthException exception) { this.exception = exception; if (this.exception instanceof OAuthMessageSignerException) { this.type = Type.MESSAGE_SIGNER; } else if (this.exception instanceof OAuthNotAuthorizedException) { this.type = Type.NOT_AUTHORIZED; } else if (this.exception instanceof OAuthExpectationFailedException) { this.type = Type.EXPECTATION_FAILED; } else if (this.exception instanceof OAuthCommunicationException) { this.type = Type.COMMUNICATION; } else { this.type = Type.OTHER; } this.details = exception.getMessage(); }
public void signRequest(HttpRequest request) { int retries = 3; if (consumer == null) { buildConsumer(); } while (retries-- > 0) { try { if (consumer != null) { // We need to remove the previous Authorization header // because signpost fails to sign a second time otherwise. request.removeHeaders("Authorization"); consumer.sign(request); return; } } catch (OAuthException e) { e.printStackTrace(); } login(); } }
HttpURLConnection sign( HttpURLConnection request, final HttpEntity body ) throws IOException { try { // OAuth Sign. // Note that the request body must be repeatable even though it is an input stream. if ( body == null ) return (HttpURLConnection)oauth.sign( request ).unwrap(); else return (HttpURLConnection)oauth.sign( new HttpURLConnectionRequestAdapter(request) { /* @Override */ public InputStream getMessagePayload() throws IOException { return body.getContent(); } }).unwrap(); } catch ( final OAuthException ex ) { // throw new IOException( "OAuth signing error", ex ); // 1.6 only! throw new IOException( "OAuth signing error: " + ex.getMessage() ) { private static final long serialVersionUID = -13848840190384656L; /* @Override */ public Throwable getCause() { return ex; } }; } } }
HttpURLConnection sign( HttpURLConnection request, final HttpEntity body ) throws IOException { try { // OAuth Sign. // Note that the request body must be repeatable even though it is an input stream. if ( body == null ) return (HttpURLConnection)oauth.sign( request ).unwrap(); else return (HttpURLConnection)oauth.sign( new HttpURLConnectionRequestAdapter(request) { /* @Override */ public InputStream getMessagePayload() throws IOException { return body.getContent(); } }).unwrap(); } catch ( final OAuthException ex ) { // throw new IOException( "OAuth signing error", ex ); // 1.6 only! throw new IOException( "OAuth signing error: " + ex.getMessage() ) { private static final long serialVersionUID = -13848840190384656L; /* @Override */ public Throwable getCause() { return ex; } }; } } }