Skip to content

Commit ae14353

Browse files
committed
optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao)
1 parent e719d25 commit ae14353

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

changelog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[SNAPSHOT]
22
* fix error parsing for Fitbit (thanks to https://github.com/danmana)
3+
* optimize debug log performance impact on prod in OAuth1 and fix
4+
NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao)
35

46
[5.4.0]
57
* fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef)

scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, Strin
4545
}
4646

4747
public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException {
48-
log("obtaining request token from " + api.getRequestTokenEndpoint());
48+
log("obtaining request token from %s", api.getRequestTokenEndpoint());
4949
final OAuthRequest request = prepareRequestTokenRequest();
5050

5151
log("sending request...");
5252
final Response response = execute(request);
5353
final String body = response.getBody();
5454

55-
log("response status code: " + response.getCode());
56-
log("response body: " + body);
55+
log("response status code: %s", response.getCode());
56+
log("response body: %s", body);
5757
return api.getRequestTokenExtractor().extract(response);
5858
}
5959

@@ -62,7 +62,7 @@ public Future<OAuth1RequestToken> getRequestTokenAsync() {
6262
}
6363

6464
public Future<OAuth1RequestToken> getRequestTokenAsync(OAuthAsyncRequestCallback<OAuth1RequestToken> callback) {
65-
log("async obtaining request token from " + api.getRequestTokenEndpoint());
65+
log("async obtaining request token from %s", api.getRequestTokenEndpoint());
6666
final OAuthRequest request = prepareRequestTokenRequest();
6767
return execute(request, callback, new OAuthRequest.ResponseConverter<OAuth1RequestToken>() {
6868
@Override
@@ -78,7 +78,7 @@ protected OAuthRequest prepareRequestTokenRequest() {
7878
if (callback == null) {
7979
callback = OAuthConstants.OOB;
8080
}
81-
log("setting oauth_callback to " + callback);
81+
log("setting oauth_callback to %s", callback);
8282
request.addOAuthParameter(OAuthConstants.CALLBACK, callback);
8383
addOAuthParams(request, "");
8484
appendSignature(request);
@@ -97,12 +97,12 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) {
9797
}
9898
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret));
9999

100-
log("appended additional OAuth parameters: " + request.getOauthParameters());
100+
log("appended additional OAuth parameters: %s", request.getOauthParameters());
101101
}
102102

103103
public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier)
104104
throws IOException, InterruptedException, ExecutionException {
105-
log("obtaining access token from " + api.getAccessTokenEndpoint());
105+
log("obtaining access token from %s", api.getAccessTokenEndpoint());
106106
final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier);
107107
final Response response = execute(request);
108108
return api.getAccessTokenExtractor().extract(response);
@@ -113,8 +113,8 @@ public Future<OAuth1AccessToken> getAccessTokenAsync(OAuth1RequestToken requestT
113113
}
114114

115115
/**
116-
* Start the request to retrieve the access token. The optionally provided
117-
* callback will be called with the Token when it is available.
116+
* Start the request to retrieve the access token. The optionally provided callback will be called with the Token
117+
* when it is available.
118118
*
119119
* @param requestToken request token (obtained previously or null)
120120
* @param oauthVerifier oauth_verifier
@@ -123,7 +123,7 @@ public Future<OAuth1AccessToken> getAccessTokenAsync(OAuth1RequestToken requestT
123123
*/
124124
public Future<OAuth1AccessToken> getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier,
125125
OAuthAsyncRequestCallback<OAuth1AccessToken> callback) {
126-
log("async obtaining access token from " + api.getAccessTokenEndpoint());
126+
log("async obtaining access token from %s", api.getAccessTokenEndpoint());
127127
final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier);
128128
return execute(request, callback, new OAuthRequest.ResponseConverter<OAuth1AccessToken>() {
129129
@Override
@@ -137,19 +137,19 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken
137137
final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
138138
request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
139139
request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier);
140-
log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier);
140+
log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier);
141141
addOAuthParams(request, requestToken.getTokenSecret());
142142
appendSignature(request);
143143
return request;
144144
}
145145

146146
public void signRequest(OAuth1AccessToken token, OAuthRequest request) {
147-
log("signing request: " + request.getCompleteUrl());
147+
log("signing request: %s", request.getCompleteUrl());
148148

149149
if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) {
150150
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
151151
}
152-
log("setting token to: " + token);
152+
log("setting token to: %s", token);
153153
addOAuthParams(request, token.getTokenSecret());
154154
appendSignature(request);
155155
}
@@ -160,8 +160,7 @@ public String getVersion() {
160160
}
161161

162162
/**
163-
* Returns the URL where you should redirect your users to authenticate your
164-
* application.
163+
* Returns the URL where you should redirect your users to authenticate your application.
165164
*
166165
* @param requestToken the request token you need to authorize
167166
* @return the URL where you should redirect your users
@@ -175,8 +174,8 @@ private String getSignature(OAuthRequest request, String tokenSecret) {
175174
final String baseString = api.getBaseStringExtractor().extract(request);
176175
final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret);
177176

178-
log("base string is: " + baseString);
179-
log("signature is: " + signature);
177+
log("base string is: %s", baseString);
178+
log("signature is: %s", signature);
180179
return signature;
181180
}
182181

@@ -205,9 +204,9 @@ public DefaultApi10a getApi() {
205204
return api;
206205
}
207206

208-
public void log(String message) {
207+
public void log(String messagePattern, Object... params) {
209208
if (debugStream != null) {
210-
message += '\n';
209+
final String message = String.format(messagePattern, params) + '\n';
211210
try {
212211
debugStream.write(message.getBytes("UTF8"));
213212
} catch (IOException | RuntimeException e) {

0 commit comments

Comments
 (0)