本文整理汇总了Java中oauth.signpost.exception.OAuthException类的典型用法代码示例。如果您正苦于以下问题:Java OAuthException类的具体用法?Java OAuthException怎么用?Java OAuthException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuthException类属于oauth.signpost.exception包,在下文中一共展示了OAuthException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildReplaceResult
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
String dataXml = "";
if (resultData != null) {
String format = isUrl ? resultDataUrl : resultDataText;
dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
}
//*LAMS* the following line was added by LAMS and also messageIdentifier was added to the line after it
String messageIdentifier = UUID.randomUUID().toString();
String xml = String.format(replaceResultMessage, messageIdentifier, StringEscapeUtils.escapeXml(sourcedid),
StringEscapeUtils.escapeXml(score), dataXml);
HttpParameters parameters = new HttpParameters();
String hash = getBodyHash(xml);
parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/xml");
request.setEntity(new StringEntity(xml, "UTF-8"));
signer.setAdditionalParameters(parameters);
signer.sign(request);
return request;
}
示例2: startAuthentication
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Starts the OAuth authentication flow.
*/
public synchronized void startAuthentication(String accountId) {
WithingsAccount withingsAccount = getAccount(accountId);
if (withingsAccount == null) {
logger.warn("Couldn't find Credentials of Account '{}'. Please check openhab.cfg or withings.cfg.", accountId);
return;
}
OAuthConsumer consumer = withingsAccount.createConsumer();
provider = new DefaultOAuthProvider(OAUTH_REQUEST_TOKEN_ENDPOINT,
OAUTH_ACCESS_TOKEN_ENDPOINT_URL, OAUTH_AUTHORIZE_ENDPOINT_URL);
try {
String url = provider.retrieveRequestToken(consumer, this.redirectUrl);
printSetupInstructions(url);
} catch (OAuthException ex) {
logger.error(ex.getMessage(), ex);
printAuthenticationFailed(ex);
}
}
示例3: getOAuthUri
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
private static final String getOAuthUri(String uri, List<NameValuePair> params, String key, String secret) {
final OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters additionalParameters = new HttpParameters();
additionalParameters.put("oauth_timestamp", String.valueOf(getDate().getTime() / 1000));
consumer.setAdditionalParameters(additionalParameters);
try {
return consumer.sign(uri + "?" + URLEncodedUtils.format(params, "UTF-8"));
} catch (OAuthException e) {
try {
return uri + "web/error.html?message=" + URLEncoder.encode(e.getMessage(), "UTF-8");
} catch (UnsupportedEncodingException f) {
return uri + "web/error.html?message=Unknown%20Error";
}
}
}
示例4: main
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Main function.
*
* @param args
* command line arguments
*/
public static void main( String[] args )
{
AbstractClient client = new DefaultClient(
WEBSERVICE_URL, CONSUMER_KEY, CONSUMER_SECRET );
// authorize at the webservice with the access token
try
{
client.authorize( ACCESS_KEY, ACCESS_SECRET );
}
catch (OAuthException ex)
{
throw new RuntimeException( "Authorization failed!", ex );
}
// from now on the webservice is accessible for the client
}
示例5: _get
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
private static org.openestate.is24.restapi.xml.attachmentsorder.List _get( AbstractClient client, String url ) throws IOException, OAuthException, JAXBException, RequestFailedException
{
// send request
Response response = client.sendXmlRequest( new URL( url ), RequestMethod.GET, null );
// parse result from response body after successful execution
if (response.statusCode==Response.OK)
{
return ((JAXBElement<org.openestate.is24.restapi.xml.attachmentsorder.List>)
XmlUtils.unmarshal( response.body )).getValue();
}
// throw an error for any other status codes
else
{
String msg = StringUtils.trimToNull( response.statusMessage );
if (msg==null) msg = "Request failed!";
msg += " (" + response.statusCode + ")";
throw new RequestFailedException( response, msg );
}
}
示例6: doInBackground
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
try {
oAuthProvider.retrieveAccessToken(oAuthConsumer, verifier);
// Store token in preferences for future use
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
Editor editor = prefs.edit();
editor.putString(OSMTracker.Preferences.KEY_OSM_OAUTH_TOKEN, oAuthConsumer.getToken());
editor.putString(OSMTracker.Preferences.KEY_OSM_OAUTH_SECRET, oAuthConsumer.getTokenSecret());
editor.commit();
} catch (OAuthException oe) {
Log.e(TAG, "Could not retrieve access token", oe);
oAuthException = oe;
cancel(false);
}
return null;
}
示例7: doVerificationRequest
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Create a verification request and show a page with the verification link.
*
* @param req incoming GET request
* @param resp outgoing response
* @throws IOException
* @throws ServletException
*/
protected void doVerificationRequest( HttpServletRequest req, HttpServletResponse resp ) throws IOException, ServletException
{
Verification verification = null;
try
{
verification = this.getWebserviceVerification( req );
}
catch (OAuthException ex)
{
throw new IOException( "Can't fetch verification!", ex );
}
// store verification informations
this.storeVerification( verification );
// put verification informations into request attributes
req.setAttribute( "url", verification.verificationUrl );
req.setAttribute( "token", verification.requestToken );
req.setAttribute( "secret", verification.requestTokenSecret );
// show JSP view
resp.setCharacterEncoding( "UTF-8" );
RequestDispatcher d = req.getRequestDispatcher( "/WEB-INF/views/verification-request.jsp" );
d.include( req, resp );
}
示例8: doInBackground
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
@Override
protected List<String> doInBackground() throws OAuthException {
provider.retrieveAccessToken(consumer, verificationCode);
// must use an own connection here and not the normal singleton because since the
// authorization process is not finished, the new authorized consumer is not applied yet
OsmConnection osm = new OsmConnection(OSM_API_URL, ApplicationConstants.USER_AGENT, consumer);
return new PermissionsDao(osm).get();
}
示例9: makeRequest
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Makes a one-legged OAuth 1.0a request for the specified URL.
*
* @param url the URL being requested
* @return an HttpResponse
* @since 1.0.0
*/
private HttpResponse<JsonNode> makeRequest(String url) {
try {
final OAuthConsumer consumer = new DefaultOAuthConsumer(this.consumerKey, this.consumerSecret);
final String signed = consumer.sign(url);
return Unirest.get(signed).header("X-User-Agent", USER_AGENT).asJson();
} catch (OAuthException | UnirestException e) {
LOGGER.error("An error occurred making request: " + url, e);
}
return null;
}
示例10: sendReplaceResult
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
public static void sendReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
HttpPost request = buildReplaceResult(url, key, secret, sourcedid, score, resultData, isUrl);
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() >= 400) {
throw new HttpResponseException(response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase());
}
}
示例11: prepareConnection
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
@Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
super.prepareConnection(connection, httpMethod);
try {
consumer.sign(connection);
log.debug("Signed request to {}", connection.getURL());
} catch (OAuthException e) {
log.error("Could not sign request to {}", connection.getURL(), e);
throw new IOException("Could not sign request to " + connection.getURL(), e);
}
}
示例12: intercept
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
if (original.header(ApiConstants.OAUTH_ENABLE_HEADER) != null) {
try {
original = (Request) consumer.sign(original).unwrap();
} catch (OAuthException e) {
throw new IOException("Could not sign request", e);
}
}
return chain.proceed(original);
}
示例13: retrieveRequestToken
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Request the request token and secret.
*
* @param callbackURL the URL where the provider should redirect to (usually a URL on the current app)
* @return A Right(RequestToken) in case of success, Left(OAuthException) otherwise
*/
public RequestToken retrieveRequestToken(String callbackURL) {
OAuthConsumer consumer = new DefaultOAuthConsumer(info.key.key, info.key.secret);
try {
provider.retrieveRequestToken(consumer, callbackURL);
return new RequestToken(consumer.getToken(), consumer.getTokenSecret());
} catch(OAuthException ex) {
throw new RuntimeException(ex);
}
}
示例14: retrieveAccessToken
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
/**
* Exchange a request token for an access token.
*
* @param token the token/secret pair obtained from a previous call
* @param verifier a string you got through your user, with redirection
* @return A Right(RequestToken) in case of success, Left(OAuthException) otherwise
*/
public RequestToken retrieveAccessToken(RequestToken token, String verifier) {
OAuthConsumer consumer = new DefaultOAuthConsumer(info.key.key, info.key.secret);
consumer.setTokenWithSecret(token.token, token.secret);
try {
provider.retrieveAccessToken(consumer, verifier);
return new RequestToken(consumer.getToken(), consumer.getTokenSecret());
} catch (OAuthException ex) {
throw new RuntimeException(ex);
}
}
示例15: sendRequest
import oauth.signpost.exception.OAuthException; //导入依赖的package包/类
private HttpURLConnection sendRequest(
String call, String method, boolean authenticate, ApiRequestWriter writer)
throws IOException, OAuthException
{
HttpURLConnection connection = openConnection(call);
if(method != null)
{
connection.setRequestMethod(method);
}
if(writer != null && writer.getContentType() != null)
{
connection.setRequestProperty("Content-Type", writer.getContentType());
connection.setRequestProperty("charset", CHARSET.toLowerCase(Locale.UK));
}
if(authenticate)
{
createOAuthConsumer().sign(connection);
}
if(writer != null)
{
sendRequestPayload(connection, writer);
}
return connection;
}