本文整理汇总了Java中oauth.signpost.OAuthConsumer.sign方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthConsumer.sign方法的具体用法?Java OAuthConsumer.sign怎么用?Java OAuthConsumer.sign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth.signpost.OAuthConsumer
的用法示例。
在下文中一共展示了OAuthConsumer.sign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOAuthUri
import oauth.signpost.OAuthConsumer; //导入方法依赖的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";
}
}
}
示例2: requestObjectApi
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private static void requestObjectApi( OAuthConsumer consumer ) throws MalformedURLException, IOException, OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException, UnsupportedEncodingException
{
LOGGER.info( "#################################################################################################" );
URL url =
new URL( "http://sandbox.immobilienscout24.de/restapi/api/search/v1.0/searcher/abc" );
HttpURLConnection apiRequest = (HttpURLConnection) url.openConnection();
consumer.sign( apiRequest );
LOGGER.info( "Sending request..." );
apiRequest.connect();
LOGGER.info( "Expiration "+apiRequest.getExpiration() );
LOGGER.info( "Timeout "+apiRequest.getConnectTimeout() );
LOGGER.info( "URL "+apiRequest.getURL() );
LOGGER.info( "Method "+apiRequest.getRequestMethod() );
LOGGER.info( "Response: "+apiRequest.getResponseCode()+" "
+apiRequest.getResponseMessage() );
LOGGER.info( "#################################################################################################" );
}
示例3: run
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public void run() {
JSONObject statement = buildStatement();
LTIConsumer consumer = user.getConsumer();
String key = consumer.getKey().toString();
String secret = consumer.getSecret().toString();
OAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
try {
HttpPost request = new HttpPost(user.getXapiUrl());
request.setHeader("Content-Type", "application/json");
request.setEntity(new StringEntity(statement.toString(), "UTF-8"));
signer.sign(request);
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() >= 400) {
throw new Exception(response.getStatusLine().getReasonPhrase());
}
} catch (Exception e) {
MinecraftLTI.instance.getLogger().warning("Failed to send duration: "+e.getMessage());
}
}
示例4: doPost
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private JSONObject doPost(Account acct, URL url, JSONObject activity) throws Exception {
Log.i(TAG, "Posting " + activity);
OAuthConsumer cons = OAuth.getConsumerForAccount(getContext(), acct);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
cons.sign(conn);
OutputStream os = conn.getOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(os);
wr.write(activity.toString());
wr.close();
if(conn.getResponseCode() != 200) {
Log.e(TAG, "Error posting: " + Utils.readAll(conn.getErrorStream()));
return null;
}
JSONObject result = new JSONObject(Utils.readAll(conn.getInputStream()));
return result;
}
示例5: stream
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public ContentExchange stream(ContentExchange ex, Symbol... symbols) throws ModelException
{
OAuthConsumer consumer = new JettyOAuthConsumer(ForemanConstants.API_KEY.toString(), ForemanConstants.API_SECRET.toString());
consumer.setTokenWithSecret(ForemanConstants.ACCESS_TOKEN.toString(), ForemanConstants.ACCESS_TOKEN_SECRET.toString());
ex.setMethod(Verb.GET.name());
ex.setURL(APICall.getStreamingQuote(ResponseFormat.XML) + getParameters(symbols));
// sign the request
try
{
consumer.sign(ex);
client.send(ex);
}
catch (IOException | OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e)
{
throw new ModelException("Sent Exchange to Client", e);
}
return ex;
}
示例6: processHttpMessage
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Override
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo)
{
if (messageIsRequest && shouldSign(messageInfo))
{
HttpRequest req = new BurpHttpRequestWrapper(messageInfo);
OAuthConsumer consumer = new DefaultOAuthConsumer(
OAuthConfig.getConsumerKey(),
OAuthConfig.getConsumerSecret());
consumer.setTokenWithSecret(OAuthConfig.getToken(),
OAuthConfig.getTokenSecret());
try {
consumer.sign(req);
} catch (OAuthException oae) {
oae.printStackTrace();
}
}
}
示例7: doOAuth
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public void doOAuth() {
try {
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(ShapewaysApplication.CONSUMER_KEY, ShapewaysApplication.CONSUMER_SECRET);
consumer.setTokenWithSecret(((ShapewaysApplication) getApplicationContext()).getShapewaysClient().getOauthToken(),
((ShapewaysApplication) getApplicationContext()).getShapewaysClient().getOauthTokenSecret());
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e68
HttpGet request = new HttpGet(ShapewaysClient.API_URL_BASE + ShapewaysClient.API_PATH);
consumer.sign(request);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.d(LOG_TAG, "response=" + response.getStatusLine());
Log.d(LOG_TAG, "response=" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
Log.e(LOG_TAG, "doOAuth", e);
}
}
示例8: addOAuthAuthorizationHeader
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
/**
* Signs the connection with an OAuth authentication header
*
* @param connection the connection
*
* @throws OsmTransferException thrown if there is currently no OAuth Access Token configured
* @throws OsmTransferException thrown if signing fails
*/
protected void addOAuthAuthorizationHeader(HttpURLConnection connection) throws OsmTransferException {
if (oauthParameters == null) {
oauthParameters = OAuthParameters.createDefault();
}
OAuthConsumer consumer = oauthParameters.buildDefaultConsumer();
OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
if (! holder.containsAccessToken())
throw new MissingOAuthAccessTokenException();
consumer.setTokenWithSecret(holder.getAccessTokenKey(), holder.getAccessTokenSecret());
try {
consumer.sign(connection);
} catch(OAuthException e) {
throw new OsmTransferException("Failed to sign a HTTP connection with an OAuth Authentication header", e);
}
}
示例9: makeRequest
import oauth.signpost.OAuthConsumer; //导入方法依赖的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: signRequestWithConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private void signRequestWithConsumer(final HttpURLConnection req, final OAuthConsumer consumer) {
try {
consumer.sign(req);
} catch (final OAuthException oaEx) {
throw new RuntimeException(oaEx);
}
}
示例11: doInBackground
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Override
protected RestResult doInBackground(String... args) {
try {
request = createRequest();
if (isCancelled())
throw new InterruptedException();
OAuthConsumer consumer = Session.getInstance().getOAuthConsumer();
if (consumer != null) {
AccessToken accessToken = Session.getInstance().getAccessToken();
if (accessToken != null) {
consumer.setTokenWithSecret(accessToken.getKey(), accessToken.getSecret());
}
consumer.sign(request);
}
request.setHeader("Accept-Language", Locale.getDefault().getLanguage());
request.setHeader("API-Client", String.format("uservoice-android-%s", UserVoice.getVersion()));
AndroidHttpClient client = AndroidHttpClient.newInstance(String.format("uservoice-android-%s", UserVoice.getVersion()), Session.getInstance().getContext());
if (isCancelled())
throw new InterruptedException();
// TODO it would be nice to find a way to abort the request on cancellation
HttpResponse response = client.execute(request);
if (isCancelled())
throw new InterruptedException();
HttpEntity responseEntity = response.getEntity();
StatusLine responseStatus = response.getStatusLine();
int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;
String body = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
client.close();
if (isCancelled())
throw new InterruptedException();
return new RestResult(statusCode, new JSONObject(body));
} catch (Exception e) {
return new RestResult(e);
}
}
示例12: signRequest
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Override
public void signRequest(HttpURLConnection apiRequest) {
OAuthConsumer consumer = new DefaultOAuthConsumer(apiConsumerKey, apiConsumerSecret);
consumer.setTokenWithSecret(accessToken, accessSecret);
try {
consumer.sign(apiRequest);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例13: prepare
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private HttpURLConnection prepare(URL url, String method) {
if (this.username != null && this.password != null && this.scheme != null) {
String authString = null;
switch (this.scheme) {
case BASIC: authString = basicAuthHeader(); break;
default: throw new RuntimeException("Scheme " + this.scheme + " not supported by the UrlFetch WS backend.");
}
this.headers.put("Authorization", authString);
}
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(this.followRedirects);
connection.setReadTimeout(this.timeout * 1000);
for (String key: this.headers.keySet()) {
connection.setRequestProperty(key, headers.get(key));
}
checkFileBody(connection);
if (this.oauthToken != null && this.oauthSecret != null) {
OAuthConsumer consumer = new DefaultOAuthConsumer(oauthInfo.consumerKey, oauthInfo.consumerSecret);
consumer.setTokenWithSecret(oauthToken, oauthSecret);
consumer.sign(connection);
}
return connection;
} catch(Exception e) {
throw new RuntimeException(e);
}
}
示例14: main
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
BrickLinkClient client = new BrickLinkClient(configuration);
OAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(configuration.getProperty(ConfigurationProperty.CONSUMER_KEY), configuration.getProperty(ConfigurationProperty.CONSUMER_SECRET));
oAuthConsumer.setTokenWithSecret(configuration.getProperty(ConfigurationProperty.TOKEN_VALUE), configuration.getProperty(ConfigurationProperty.TOKEN_SECRET));
try {
OrdersResponse ordersResponse = client.execute(new OrdersRequest());
for (Order order : ordersResponse.getOrders()) {
HttpGet request = new HttpGet(BASE_URL + "/orders/" + order.getId());
oAuthConsumer.sign(request);
CloseableHttpResponse httpResponse = client.execute(request);
try {
System.out.println("Code: " + httpResponse.getStatusLine().getStatusCode() + ',' + httpResponse.getStatusLine().getReasonPhrase());
String body = EntityUtils.toString(httpResponse.getEntity());
ObjectMapper mapper = new ObjectMapper();
Response<Order> response = mapper.readValue(body, new TypeReference<Response<Order>>() { /* anonymous subclass */ });
if (null != response.getData().getShipping().getAddress().getAddress1()) {
System.out.println(body);
}
System.out.println(response);
} finally {
httpResponse.close();
}
}
} finally {
client.close();
}
}
示例15: testSignature
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Test
public void testSignature() throws Exception {
HttpRequest hr = reqWrapForTestInput(1);
OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678");
consumer.setTokenWithSecret("9ABC", "DEF0");
consumer.sign(hr);
}