Skip to content

Commit f5b8df9

Browse files
committed
use own compilet regexp Pattern insteand of synchronized using of the common one
1 parent 9d0d045 commit f5b8df9

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
public class ConstantContactTokenExtractor implements TokenExtractor<OAuth2AccessToken> {
1212

13+
private static final String REGEXP = "\"access_token\"\\s*:\\s*\"([^&\"]+)\"";
14+
1315
protected ConstantContactTokenExtractor() {
1416
}
1517

@@ -27,8 +29,7 @@ public OAuth2AccessToken extract(String response) {
2729
Preconditions.checkEmptyString(response,
2830
"Response body is incorrect. Can't extract a token from an empty string");
2931

30-
final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\"";
31-
final Matcher matcher = Pattern.compile(regex).matcher(response);
32+
final Matcher matcher = Pattern.compile(REGEXP).matcher(response);
3233
if (matcher.find()) {
3334
final String token = OAuthEncoder.decode(matcher.group(1));
3435
return new OAuth2AccessToken(token, response);

scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor {
1111

12-
private static final Pattern ID_TOKEN_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\"");
12+
private static final String REGEXP = "\"id_token\"\\s*:\\s*\"(\\S*?)\"";
1313

1414
protected GoogleJsonTokenExtractor() {
1515
}
@@ -29,7 +29,7 @@ public GoogleToken extract(String response) {
2929
}
3030

3131
private String extractOpenIdToken(String response) {
32-
final Matcher matcher = ID_TOKEN_PATTERN.matcher(response);
32+
final Matcher matcher = Pattern.compile(REGEXP).matcher(response);
3333
if (matcher.find()) {
3434
return matcher.group(1);
3535
}

scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
public abstract class AbstractOAuth1TokenExtractor<T extends OAuth1Token> implements TokenExtractor<T> {
1818

19-
private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)");
20-
private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)");
19+
private static final String OAUTH_TOKEN_REGEXP = "oauth_token=([^&]+)";
20+
private static final String OAUTH_TOKEN_SECRET_REGEXP = "oauth_token_secret=([^&]*)";
2121

2222
/**
2323
* {@inheritDoc}
@@ -26,8 +26,8 @@ public abstract class AbstractOAuth1TokenExtractor<T extends OAuth1Token> implem
2626
public T extract(String response) {
2727
Preconditions.checkEmptyString(response,
2828
"Response body is incorrect. Can't extract a token from an empty string");
29-
final String token = extract(response, TOKEN_REGEX);
30-
final String secret = extract(response, SECRET_REGEX);
29+
final String token = extract(response, Pattern.compile(OAUTH_TOKEN_REGEXP));
30+
final String secret = extract(response, Pattern.compile(OAUTH_TOKEN_SECRET_REGEXP));
3131
return createToken(token, secret, response);
3232
}
3333

scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class OAuth2AccessTokenJsonExtractor implements TokenExtractor<OAuth2AccessToken> {
1010

11-
private static final Pattern ACCESS_TOKEN_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\"");
11+
private static final String ACCESS_TOKENS_REGEXP = "\"access_token\"\\s*:\\s*\"(\\S*?)\"";
1212

1313
protected OAuth2AccessTokenJsonExtractor() {
1414
}
@@ -29,7 +29,7 @@ public OAuth2AccessToken extract(String response) {
2929

3030
protected String extractAccessToken(String response) {
3131
Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String");
32-
final Matcher matcher = ACCESS_TOKEN_PATTERN.matcher(response);
32+
final Matcher matcher = Pattern.compile(ACCESS_TOKENS_REGEXP).matcher(response);
3333
if (matcher.find()) {
3434
return matcher.group(1);
3535
} else {

scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class Preconditions {
1212
private static final String DEFAULT_MESSAGE = "Received an invalid parameter";
1313

1414
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
15-
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
15+
private static final String URL_REGEXP = "^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+";
1616

1717
/**
1818
* Checks that an object is not null.
@@ -63,7 +63,7 @@ public static void checkValidOAuthCallback(String url, String errorMsg) {
6363
}
6464

6565
private static boolean isUrl(String url) {
66-
return URL_PATTERN.matcher(url).matches();
66+
return Pattern.compile(URL_REGEXP).matcher(url).matches();
6767
}
6868

6969
private static void check(boolean requirements, String error) {

0 commit comments

Comments
 (0)