Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.IOException;
Expand All @@ -54,7 +54,10 @@ static ObjectMapper mapper() {
if (!isInitialized) {
MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.KebabCaseStrategy.INSTANCE);
// even though using new PropertyNamingStrategy.KebabCaseStrategy() is deprecated
// and PropertyNamingStrategies.KebabCaseStrategy.INSTANCE (introduced in jackson 2.14) is
// recommended, we can't use it because Spark still relies on jackson 2.13.x stuff
MAPPER.setPropertyNamingStrategy(new PropertyNamingStrategy.KebabCaseStrategy());
MAPPER.registerModule(initModule());
isInitialized = true;
}
Expand All @@ -64,7 +67,7 @@ static ObjectMapper mapper() {
return MAPPER;
}

private static SimpleModule initModule() {
public static SimpleModule initModule() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made public here and above so that it can be easier reused

return new SimpleModule()
.addSerializer(ErrorResponse.class, new ErrorResponseSerializer())
.addDeserializer(ErrorResponse.class, new ErrorResponseDeserializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ public String credential() {
return properties().get(OAuth2Properties.CREDENTIAL);
}

/** A Bearer token which will be used for interaction with the server. */
@Nullable
@Value.Lazy
public String token() {
return properties().get(OAuth2Properties.TOKEN);
/** A Bearer token supplier which will be used for interaction with the server. */
@Value.Default
public Supplier<String> token() {
return () -> properties().get(OAuth2Properties.TOKEN);
}

private RESTClient httpClient() {
Expand All @@ -120,19 +119,19 @@ private RESTClient httpClient() {
return HTTP_CLIENT_REF.get();
}

@Value.Lazy
AuthSession authSession() {
if (null != token()) {
private AuthSession authSession() {
String token = token().get();
if (null != token) {
return AuthSession.fromAccessToken(
httpClient(),
TOKEN_REFRESH_EXECUTOR,
token(),
token,
expiresAtMillis(properties()),
new AuthSession(ImmutableMap.of(), token(), null, credential(), SCOPE));
new AuthSession(ImmutableMap.of(), token, null, credential(), SCOPE));
}

if (credentialProvided()) {
AuthSession session = new AuthSession(ImmutableMap.of(), token(), null, credential(), SCOPE);
AuthSession session = new AuthSession(ImmutableMap.of(), null, null, credential(), SCOPE);
long startTimeMillis = System.currentTimeMillis();
OAuthTokenResponse authResponse =
OAuth2Util.fetchToken(httpClient(), session.headers(), credential(), SCOPE);
Expand Down