Skip to content

Commit bca2e81

Browse files
committed
Apply spring-javaformat-maven-plugin
Signed-off-by: Hyunwoo Jung <[email protected]>
1 parent a88a278 commit bca2e81

File tree

186 files changed

+4248
-4357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+4248
-4357
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575

7676
<build>
7777
<plugins>
78+
<plugin>
79+
<groupId>io.spring.javaformat</groupId>
80+
<artifactId>spring-javaformat-maven-plugin</artifactId>
81+
</plugin>
7882
<plugin>
7983
<groupId>org.apache.maven.plugins</groupId>
8084
<artifactId>maven-checkstyle-plugin</artifactId>

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSCompanionAutoConfiguration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
import org.springframework.context.support.GenericApplicationContext;
2626
import org.springframework.util.CollectionUtils;
2727

28-
2928
/**
30-
*
3129
* @author Oleg Zhurakousky
3230
* @since 3.2
3331
*
@@ -38,8 +36,8 @@ public class AWSCompanionAutoConfiguration {
3836
@Bean
3937
public AWSTypesMessageConverter awsTypesMessageConverter(GenericApplicationContext applicationContext) {
4038
JsonMapper jsonMapper = CollectionUtils.isEmpty(applicationContext.getBeansOfType(JsonMapper.class).values())
41-
? new JacksonMapper(new ObjectMapper())
42-
: applicationContext.getBean(JsonMapper.class);
39+
? new JacksonMapper(new ObjectMapper()) : applicationContext.getBean(JsonMapper.class);
4340
return new AWSTypesMessageConverter(jsonMapper);
4441
}
42+
4543
}

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.springframework.util.StreamUtils;
4343

4444
/**
45-
*
4645
* @author Oleg Zhurakousky
4746
* @author Anton Barkan
4847
*
@@ -79,13 +78,13 @@ static boolean isSupportedAWSType(Type type) {
7978
type = FunctionTypeUtils.getImmediateGenericType(type, 0);
8079
}
8180
Class<?> rawType = FunctionTypeUtils.getRawType(type);
82-
return rawType != null && rawType.getPackage() != null &&
83-
rawType.getPackage().getName().startsWith(
84-
"com.amazonaws.services.lambda.runtime.events");
81+
return rawType != null && rawType.getPackage() != null
82+
&& rawType.getPackage().getName().startsWith("com.amazonaws.services.lambda.runtime.events");
8583
}
8684

8785
@SuppressWarnings("rawtypes")
88-
public static Message generateMessage(InputStream payload, Type inputType, boolean isSupplier, JsonMapper jsonMapper, Context context) throws IOException {
86+
public static Message generateMessage(InputStream payload, Type inputType, boolean isSupplier,
87+
JsonMapper jsonMapper, Context context) throws IOException {
8988
if (inputType != null && FunctionTypeUtils.isMessage(inputType)) {
9089
inputType = FunctionTypeUtils.getImmediateGenericType(inputType, 0);
9190
}
@@ -101,7 +100,8 @@ public static Message generateMessage(InputStream payload, Type inputType, boole
101100
}
102101
}
103102

104-
public static Message<byte[]> generateMessage(byte[] payload, Type inputType, boolean isSupplier, JsonMapper jsonMapper) {
103+
public static Message<byte[]> generateMessage(byte[] payload, Type inputType, boolean isSupplier,
104+
JsonMapper jsonMapper) {
105105
return generateMessage(payload, inputType, isSupplier, jsonMapper, null);
106106
}
107107

@@ -124,10 +124,8 @@ public static Message<byte[]> generateMessage(byte[] payload, Type inputType, bo
124124

125125
Message<byte[]> requestMessage;
126126

127-
MessageBuilder builder = MessageBuilder
128-
.withPayload(structMessage instanceof Map msg && msg.containsKey("payload")
129-
? (msg.get("payload"))
130-
: payload);
127+
MessageBuilder builder = MessageBuilder.withPayload(
128+
structMessage instanceof Map msg && msg.containsKey("payload") ? (msg.get("payload")) : payload);
131129
if (isApiGateway) {
132130
builder.setHeader(AWSLambdaUtils.AWS_API_GATEWAY, true);
133131
if (JsonMapper.isJsonStringRepresentsCollection(((Map) structMessage).get("body"))) {
@@ -165,7 +163,8 @@ private static Object convertFromJsonIfNecessary(Object value, JsonMapper object
165163
}
166164

167165
@SuppressWarnings("unchecked")
168-
public static byte[] generateOutputFromObject(Message<?> requestMessage, Object output, JsonMapper objectMapper, Type functionOutputType) {
166+
public static byte[] generateOutputFromObject(Message<?> requestMessage, Object output, JsonMapper objectMapper,
167+
Type functionOutputType) {
169168
Message<byte[]> responseMessage = null;
170169
if (output instanceof Publisher<?>) {
171170
List<Object> result = new ArrayList<>();
@@ -209,25 +208,27 @@ else if (result.size() > 1) {
209208
}
210209

211210
@SuppressWarnings({ "rawtypes", "unchecked" })
212-
public static byte[] generateOutput(Message requestMessage, Message<?> responseMessage,
213-
JsonMapper objectMapper, Type functionOutputType) {
211+
public static byte[] generateOutput(Message requestMessage, Message<?> responseMessage, JsonMapper objectMapper,
212+
Type functionOutputType) {
214213

215214
if (isSupportedAWSType(functionOutputType)) {
216215
return extractPayload((Message<Object>) responseMessage, objectMapper);
217216
}
218217

219-
byte[] responseBytes = responseMessage == null ? "\"OK\"".getBytes() : extractPayload((Message<Object>) responseMessage, objectMapper);
220-
if (requestMessage.getHeaders().containsKey(AWS_API_GATEWAY) && ((boolean) requestMessage.getHeaders().get(AWS_API_GATEWAY))) {
218+
byte[] responseBytes = responseMessage == null ? "\"OK\"".getBytes()
219+
: extractPayload((Message<Object>) responseMessage, objectMapper);
220+
if (requestMessage.getHeaders().containsKey(AWS_API_GATEWAY)
221+
&& ((boolean) requestMessage.getHeaders().get(AWS_API_GATEWAY))) {
221222
Map<String, Object> response = new HashMap<String, Object>();
222-
response.put(IS_BASE64_ENCODED, responseMessage != null && responseMessage.getHeaders().containsKey(IS_BASE64_ENCODED)
223-
? responseMessage.getHeaders().get(IS_BASE64_ENCODED) : false);
223+
response.put(IS_BASE64_ENCODED,
224+
responseMessage != null && responseMessage.getHeaders().containsKey(IS_BASE64_ENCODED)
225+
? responseMessage.getHeaders().get(IS_BASE64_ENCODED) : false);
224226

225227
AtomicReference<MessageHeaders> headers = new AtomicReference<>();
226228
int statusCode = HttpStatus.OK.value();
227229
if (responseMessage != null) {
228230
headers.set(responseMessage.getHeaders());
229-
statusCode = headers.get().containsKey(STATUS_CODE)
230-
? (int) headers.get().get(STATUS_CODE)
231+
statusCode = headers.get().containsKey(STATUS_CODE) ? (int) headers.get().get(STATUS_CODE)
231232
: HttpStatus.OK.value();
232233
}
233234

@@ -237,8 +238,8 @@ public static byte[] generateOutput(Message requestMessage, Message<?> responseM
237238
response.put("statusDescription", httpStatus.toString());
238239
}
239240

240-
String body = responseMessage == null
241-
? "\"OK\"" : new String(extractPayload((Message<Object>) responseMessage, objectMapper), StandardCharsets.UTF_8);
241+
String body = responseMessage == null ? "\"OK\"" : new String(
242+
extractPayload((Message<Object>) responseMessage, objectMapper), StandardCharsets.UTF_8);
242243
response.put(BODY, body);
243244
if (responseMessage != null) {
244245
Map<String, String> responseHeaders = new HashMap<>();
@@ -259,4 +260,5 @@ public static byte[] generateOutput(Message requestMessage, Message<?> responseM
259260
private static boolean isRequestKinesis(Message<Object> requestMessage) {
260261
return requestMessage.getHeaders().containsKey("Records");
261262
}
263+
262264
}

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSTypesMessageConverter.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@
3737
import org.springframework.util.MimeType;
3838

3939
/**
40-
* Implementation of {@link MessageConverter} which uses Jackson or Gson libraries to do the
41-
* actual conversion via {@link JsonMapper} instance.
40+
* Implementation of {@link MessageConverter} which uses Jackson or Gson libraries to do
41+
* the actual conversion via {@link JsonMapper} instance.
4242
*
4343
* @author Oleg Zhurakousky
44-
*
4544
* @since 3.2
4645
*/
4746
class AWSTypesMessageConverter extends JsonMessageConverter {
@@ -52,8 +51,9 @@ class AWSTypesMessageConverter extends JsonMessageConverter {
5251
private final AtomicReference<S3EventSerializer> s3EventSerializer = new AtomicReference<>();
5352

5453
AWSTypesMessageConverter(JsonMapper jsonMapper) {
55-
this(jsonMapper, new MimeType("application", "json"), new MimeType(CloudEventMessageUtils.APPLICATION_CLOUDEVENTS.getType(),
56-
CloudEventMessageUtils.APPLICATION_CLOUDEVENTS.getSubtype() + "+json"));
54+
this(jsonMapper, new MimeType("application", "json"),
55+
new MimeType(CloudEventMessageUtils.APPLICATION_CLOUDEVENTS.getType(),
56+
CloudEventMessageUtils.APPLICATION_CLOUDEVENTS.getSubtype() + "+json"));
5757
}
5858

5959
AWSTypesMessageConverter(JsonMapper jsonMapper, MimeType... supportedMimeTypes) {
@@ -69,9 +69,10 @@ protected boolean canConvertFrom(Message<?> message, @Nullable Class<?> targetCl
6969
if (message.getHeaders().containsKey(AWSLambdaUtils.AWS_EVENT)) {
7070
return ((boolean) message.getHeaders().get(AWSLambdaUtils.AWS_EVENT));
7171
}
72-
//TODO Do we really need the ^^ above? It seems like the line below dows the trick
73-
else if (targetClass.getPackage() != null &&
74-
targetClass.getPackage().getName().startsWith("com.amazonaws.services.lambda.runtime.events")) {
72+
// TODO Do we really need the ^^ above? It seems like the line below dows the
73+
// trick
74+
else if (targetClass.getPackage() != null
75+
&& targetClass.getPackage().getName().startsWith("com.amazonaws.services.lambda.runtime.events")) {
7576
return true;
7677
}
7778
return false;
@@ -82,12 +83,12 @@ protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @
8283
if (message.getPayload().getClass().isAssignableFrom(targetClass)) {
8384
return message.getPayload();
8485
}
85-
if (targetClass.getPackage() != null &&
86-
targetClass.getPackage().getName().startsWith("com.amazonaws.services.lambda.runtime.events")) {
87-
PojoSerializer<?> serializer = LambdaEventSerializers.serializerFor(targetClass, Thread.currentThread().getContextClassLoader());
86+
if (targetClass.getPackage() != null
87+
&& targetClass.getPackage().getName().startsWith("com.amazonaws.services.lambda.runtime.events")) {
88+
PojoSerializer<?> serializer = LambdaEventSerializers.serializerFor(targetClass,
89+
Thread.currentThread().getContextClassLoader());
8890
byte[] payloadBytes = message.getPayload() instanceof String
89-
? ((String) message.getPayload()).getBytes(StandardCharsets.UTF_8)
90-
: (byte[]) message.getPayload();
91+
? ((String) message.getPayload()).getBytes(StandardCharsets.UTF_8) : (byte[]) message.getPayload();
9192
Object event = serializer.fromJson(new ByteArrayInputStream(payloadBytes));
9293
return event;
9394
}
@@ -118,24 +119,24 @@ protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers)
118119
return true;
119120
}
120121

121-
122122
@SuppressWarnings("unchecked")
123123
@Override
124124
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
125125
@Nullable Object conversionHint) {
126-
if (payload instanceof String && headers.containsKey(AWSLambdaUtils.IS_BASE64_ENCODED) && (boolean) headers.get(AWSLambdaUtils.IS_BASE64_ENCODED)) {
126+
if (payload instanceof String && headers.containsKey(AWSLambdaUtils.IS_BASE64_ENCODED)
127+
&& (boolean) headers.get(AWSLambdaUtils.IS_BASE64_ENCODED)) {
127128
return ((String) payload).getBytes(StandardCharsets.UTF_8);
128129
}
129130
if (payload.getClass().getName().equals("com.amazonaws.services.lambda.runtime.events.S3Event")) {
130131
if (this.s3EventSerializer.get() == null) {
131-
this.s3EventSerializer.set(new S3EventSerializer<>().withClassLoader(ClassUtils.getDefaultClassLoader()));
132+
this.s3EventSerializer
133+
.set(new S3EventSerializer<>().withClassLoader(ClassUtils.getDefaultClassLoader()));
132134
}
133135
ByteArrayOutputStream stream = new ByteArrayOutputStream();
134136
this.s3EventSerializer.get().toJson(payload, stream);
135137
return stream.toByteArray();
136138
}
137139

138-
139140
return jsonMapper.toJson(payload);
140141
}
141142

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeEventLoop.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
import static org.apache.http.HttpHeaders.USER_AGENT;
5656

5757
/**
58-
* Event loop and necessary configurations to support AWS Lambda
59-
* Custom Runtime - https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html.
58+
* Event loop and necessary configurations to support AWS Lambda Custom Runtime -
59+
* https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html.
6060
*
6161
* @author Oleg Zhurakousky
6262
* @author Mark Sailes
@@ -69,13 +69,15 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
6969
private static Log logger = LogFactory.getLog(CustomRuntimeEventLoop.class);
7070

7171
static final String LAMBDA_VERSION_DATE = "2018-06-01";
72+
7273
private static final String LAMBDA_ERROR_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/{2}/error";
74+
7375
private static final String LAMBDA_RUNTIME_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/next";
76+
7477
private static final String LAMBDA_INVOCATION_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/{2}/response";
75-
private static final String USER_AGENT_VALUE = String.format(
76-
"spring-cloud-function/%s-%s",
77-
System.getProperty("java.runtime.version"),
78-
extractVersion());
78+
79+
private static final String USER_AGENT_VALUE = String.format("spring-cloud-function/%s-%s",
80+
System.getProperty("java.runtime.version"), extractVersion());
7981

8082
private final ConfigurableApplicationContext applicationContext;
8183

@@ -125,7 +127,9 @@ private void eventLoop(ConfigurableApplicationContext context) {
125127
logger.debug("Event URI: " + eventUri);
126128
}
127129

128-
RequestEntity<Void> requestEntity = RequestEntity.get(URI.create(eventUri)).header(USER_AGENT, USER_AGENT_VALUE).build();
130+
RequestEntity<Void> requestEntity = RequestEntity.get(URI.create(eventUri))
131+
.header(USER_AGENT, USER_AGENT_VALUE)
132+
.build();
129133
FunctionCatalog functionCatalog = context.getBean(FunctionCatalog.class);
130134
RestTemplate rest = new RestTemplate();
131135
JsonMapper mapper = context.getBean(JsonMapper.class);
@@ -144,18 +148,22 @@ private void eventLoop(ConfigurableApplicationContext context) {
144148
if (response != null && response.hasBody()) {
145149
String requestId = response.getHeaders().getFirst("Lambda-Runtime-Aws-Request-Id");
146150
try {
147-
FunctionInvocationWrapper function = locateFunction(environment, functionCatalog, response.getHeaders());
151+
FunctionInvocationWrapper function = locateFunction(environment, functionCatalog,
152+
response.getHeaders());
148153

149-
ByteArrayInputStream is = new ByteArrayInputStream(response.getBody().getBytes(StandardCharsets.UTF_8));
150-
Message<?> requestMessage = AWSLambdaUtils.generateMessage(is, function.getInputType(), function.isSupplier(), mapper, clientContext);
154+
ByteArrayInputStream is = new ByteArrayInputStream(
155+
response.getBody().getBytes(StandardCharsets.UTF_8));
156+
Message<?> requestMessage = AWSLambdaUtils.generateMessage(is, function.getInputType(),
157+
function.isSupplier(), mapper, clientContext);
151158
requestMessage = enrichTraceHeaders(response.getHeaders(), requestMessage);
152159

153160
Object functionResponse = function.apply(requestMessage);
154161

155-
byte[] responseBytes = AWSLambdaUtils.generateOutputFromObject(requestMessage, functionResponse, mapper, function.getOutputType());
162+
byte[] responseBytes = AWSLambdaUtils.generateOutputFromObject(requestMessage, functionResponse,
163+
mapper, function.getOutputType());
156164

157-
String invocationUrl = MessageFormat
158-
.format(LAMBDA_INVOCATION_URL_TEMPLATE, runtimeApi, LAMBDA_VERSION_DATE, requestId);
165+
String invocationUrl = MessageFormat.format(LAMBDA_INVOCATION_URL_TEMPLATE, runtimeApi,
166+
LAMBDA_VERSION_DATE, requestId);
159167

160168
ResponseEntity<Object> result = rest.exchange(RequestEntity.post(URI.create(invocationUrl))
161169
.header(USER_AGENT, USER_AGENT_VALUE)
@@ -179,9 +187,7 @@ private Message<?> enrichTraceHeaders(HttpHeaders headers, Message<?> message) {
179187
String headerTrace = trim(headers.getFirst("X-Amzn-Trace-Id"));
180188

181189
// prefer Lambda runtime header, then environment, then inbound header
182-
String resolved = runtimeTrace != null ? runtimeTrace
183-
: envTrace != null ? envTrace
184-
: headerTrace;
190+
String resolved = runtimeTrace != null ? runtimeTrace : envTrace != null ? envTrace : headerTrace;
185191

186192
if (resolved != null) {
187193
System.setProperty("com.amazonaws.xray.traceHeader", resolved);
@@ -280,7 +286,8 @@ public String toString() {
280286
return context;
281287
}
282288

283-
private void propagateAwsError(String requestId, Exception e, JsonMapper mapper, String runtimeApi, RestTemplate rest) {
289+
private void propagateAwsError(String requestId, Exception e, JsonMapper mapper, String runtimeApi,
290+
RestTemplate rest) {
284291
String errorMessage = e.getMessage();
285292
String errorType = e.getClass().getSimpleName();
286293
StringWriter sw = new StringWriter();
@@ -293,10 +300,11 @@ private void propagateAwsError(String requestId, Exception e, JsonMapper mapper,
293300
em.put("stackTrace", stackTrace);
294301
byte[] outputBody = mapper.toJson(em);
295302
try {
296-
String errorUrl = MessageFormat.format(LAMBDA_ERROR_URL_TEMPLATE, runtimeApi, LAMBDA_VERSION_DATE, requestId);
297-
ResponseEntity<Object> result = rest.exchange(RequestEntity.post(URI.create(errorUrl))
298-
.header(USER_AGENT, USER_AGENT_VALUE)
299-
.body(outputBody), Object.class);
303+
String errorUrl = MessageFormat.format(LAMBDA_ERROR_URL_TEMPLATE, runtimeApi, LAMBDA_VERSION_DATE,
304+
requestId);
305+
ResponseEntity<Object> result = rest.exchange(
306+
RequestEntity.post(URI.create(errorUrl)).header(USER_AGENT, USER_AGENT_VALUE).body(outputBody),
307+
Object.class);
300308
if (logger.isInfoEnabled()) {
301309
logger.info("Result ERROR status: " + result.getStatusCode());
302310
}
@@ -366,8 +374,8 @@ private FunctionInvocationWrapper locateFunction(Environment environment, Functi
366374
this.routingFunction = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME, "application/json");
367375
if (this.routingFunction != null && logger.isInfoEnabled()) {
368376
logger.info("Will default to RoutingFunction, since multiple functions available in FunctionCatalog."
369-
+ "Expecting 'spring.cloud.function.definition' or 'spring.cloud.function.routing-expression' as Message headers. "
370-
+ "If invocation is over API Gateway, Message headers can be provided as HTTP headers.");
377+
+ "Expecting 'spring.cloud.function.definition' or 'spring.cloud.function.routing-expression' as Message headers. "
378+
+ "If invocation is over API Gateway, Message headers can be provided as HTTP headers.");
371379
}
372380
function = this.routingFunction;
373381
}
@@ -399,4 +407,5 @@ private static String extractVersion() {
399407
}
400408

401409
}
410+
402411
}

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeInitializer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ private boolean isCustomRuntime(Environment environment) {
6767
return false;
6868
}
6969

70-
7170
private boolean isWebExportEnabled(GenericApplicationContext context) {
7271
Boolean enabled = context.getEnvironment()
73-
.getProperty("spring.cloud.function.web.export.enabled", Boolean.class);
72+
.getProperty("spring.cloud.function.web.export.enabled", Boolean.class);
7473
return enabled != null && enabled;
7574
}
7675

0 commit comments

Comments
 (0)