Skip to content

Commit 1ab10fd

Browse files
committed
style: apply Google Java Format
1 parent a5a3ed2 commit 1ab10fd

File tree

8 files changed

+97
-99
lines changed

8 files changed

+97
-99
lines changed

customer-service-client/src/main/java/io/github/bsayli/openapi/client/adapter/config/CustomerApiClientConfig.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class CustomerApiClientConfig {
2828

2929
@Bean
3030
RestClientCustomizer problemDetailStatusHandler(ObjectMapper om) {
31-
return builder -> builder.defaultStatusHandler(
31+
return builder ->
32+
builder.defaultStatusHandler(
3233
HttpStatusCode::isError,
3334
(request, response) -> {
3435
ProblemDetail pd = ProblemDetailSupport.extract(om, response, log);
@@ -38,30 +39,30 @@ RestClientCustomizer problemDetailStatusHandler(ObjectMapper om) {
3839

3940
@Bean(destroyMethod = "close")
4041
CloseableHttpClient customerHttpClient(
41-
@Value("${customer.api.max-connections-total:64}") int maxTotal,
42-
@Value("${customer.api.max-connections-per-route:16}") int maxPerRoute) {
42+
@Value("${customer.api.max-connections-total:64}") int maxTotal,
43+
@Value("${customer.api.max-connections-per-route:16}") int maxPerRoute) {
4344

4445
var cm =
45-
PoolingHttpClientConnectionManagerBuilder.create()
46-
.setMaxConnTotal(maxTotal)
47-
.setMaxConnPerRoute(maxPerRoute)
48-
.build();
46+
PoolingHttpClientConnectionManagerBuilder.create()
47+
.setMaxConnTotal(maxTotal)
48+
.setMaxConnPerRoute(maxPerRoute)
49+
.build();
4950

5051
return HttpClients.custom()
51-
.setConnectionManager(cm)
52-
.evictExpiredConnections()
53-
.evictIdleConnections(org.apache.hc.core5.util.TimeValue.ofSeconds(30))
54-
.setUserAgent("customer-service-client")
55-
.disableAutomaticRetries()
56-
.build();
52+
.setConnectionManager(cm)
53+
.evictExpiredConnections()
54+
.evictIdleConnections(org.apache.hc.core5.util.TimeValue.ofSeconds(30))
55+
.setUserAgent("customer-service-client")
56+
.disableAutomaticRetries()
57+
.build();
5758
}
5859

5960
@Bean
6061
HttpComponentsClientHttpRequestFactory customerRequestFactory(
61-
CloseableHttpClient customerHttpClient,
62-
@Value("${customer.api.connect-timeout-seconds:10}") long connect,
63-
@Value("${customer.api.connection-request-timeout-seconds:10}") long connReq,
64-
@Value("${customer.api.read-timeout-seconds:15}") long read) {
62+
CloseableHttpClient customerHttpClient,
63+
@Value("${customer.api.connect-timeout-seconds:10}") long connect,
64+
@Value("${customer.api.connection-request-timeout-seconds:10}") long connReq,
65+
@Value("${customer.api.read-timeout-seconds:15}") long read) {
6566

6667
var f = new HttpComponentsClientHttpRequestFactory(customerHttpClient);
6768
f.setConnectTimeout(Duration.ofSeconds(connect));
@@ -72,9 +73,9 @@ HttpComponentsClientHttpRequestFactory customerRequestFactory(
7273

7374
@Bean
7475
RestClient customerRestClient(
75-
RestClient.Builder builder,
76-
HttpComponentsClientHttpRequestFactory customerRequestFactory,
77-
List<RestClientCustomizer> customizers) {
76+
RestClient.Builder builder,
77+
HttpComponentsClientHttpRequestFactory customerRequestFactory,
78+
List<RestClientCustomizer> customizers) {
7879
builder.requestFactory(customerRequestFactory);
7980
if (customizers != null) {
8081
customizers.forEach(c -> c.customize(builder));
@@ -84,12 +85,12 @@ RestClient customerRestClient(
8485

8586
@Bean
8687
ApiClient customerApiClient(
87-
RestClient customerRestClient, @Value("${customer.api.base-url}") String baseUrl) {
88+
RestClient customerRestClient, @Value("${customer.api.base-url}") String baseUrl) {
8889
return new ApiClient(customerRestClient).setBasePath(baseUrl);
8990
}
9091

9192
@Bean
9293
CustomerControllerApi customerControllerApi(ApiClient customerApiClient) {
9394
return new CustomerControllerApi(customerApiClient);
9495
}
95-
}
96+
}

customer-service-client/src/main/java/io/github/bsayli/openapi/client/adapter/support/ProblemDetailSupport.java

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,55 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.util.Optional;
8-
98
import org.slf4j.Logger;
109
import org.springframework.http.HttpStatusCode;
1110
import org.springframework.http.MediaType;
1211
import org.springframework.http.client.ClientHttpResponse;
1312

1413
public final class ProblemDetailSupport {
1514

16-
private ProblemDetailSupport() {}
17-
18-
public static ProblemDetail extract(ObjectMapper om,
19-
ClientHttpResponse response,
20-
Logger log) {
21-
ProblemDetail pd;
22-
MediaType contentType = Optional.ofNullable(response.getHeaders().getContentType())
23-
.orElse(MediaType.ALL);
24-
HttpStatusCode status;
25-
26-
try {
27-
status = response.getStatusCode();
28-
} catch (IOException e) {
29-
log.warn("Unable to read status code from response", e);
30-
status = HttpStatusCode.valueOf(500);
31-
}
32-
33-
try (InputStream is = response.getBody()) {
34-
byte[] bytes = is.readNBytes(200_000);
35-
if (bytes.length > 0) {
36-
pd = om.readValue(bytes, ProblemDetail.class);
37-
} else {
38-
pd = fallback(status, "Empty problem response body");
39-
}
40-
} catch (IOException e) {
41-
log.warn(
42-
"Unable to deserialize ProblemDetail (status={}, contentType={}); using generic fallback",
43-
status, contentType, e);
44-
pd = fallback(status, "Unparseable problem response");
45-
} catch (Exception e) {
46-
log.warn("Unexpected error while parsing ProblemDetail", e);
47-
pd = fallback(status, "Unparseable problem response");
48-
}
49-
50-
return pd;
15+
private ProblemDetailSupport() {}
16+
17+
public static ProblemDetail extract(ObjectMapper om, ClientHttpResponse response, Logger log) {
18+
ProblemDetail pd;
19+
MediaType contentType =
20+
Optional.ofNullable(response.getHeaders().getContentType()).orElse(MediaType.ALL);
21+
HttpStatusCode status;
22+
23+
try {
24+
status = response.getStatusCode();
25+
} catch (IOException e) {
26+
log.warn("Unable to read status code from response", e);
27+
status = HttpStatusCode.valueOf(500);
5128
}
5229

53-
private static ProblemDetail fallback(HttpStatusCode status, String detail) {
54-
ProblemDetail pd = new ProblemDetail();
55-
pd.setStatus(status.value());
56-
pd.setTitle("HTTP error");
57-
pd.setDetail(detail);
58-
return pd;
30+
try (InputStream is = response.getBody()) {
31+
byte[] bytes = is.readNBytes(200_000);
32+
if (bytes.length > 0) {
33+
pd = om.readValue(bytes, ProblemDetail.class);
34+
} else {
35+
pd = fallback(status, "Empty problem response body");
36+
}
37+
} catch (IOException e) {
38+
log.warn(
39+
"Unable to deserialize ProblemDetail (status={}, contentType={}); using generic fallback",
40+
status,
41+
contentType,
42+
e);
43+
pd = fallback(status, "Unparseable problem response");
44+
} catch (Exception e) {
45+
log.warn("Unexpected error while parsing ProblemDetail", e);
46+
pd = fallback(status, "Unparseable problem response");
5947
}
60-
}
48+
49+
return pd;
50+
}
51+
52+
private static ProblemDetail fallback(HttpStatusCode status, String detail) {
53+
ProblemDetail pd = new ProblemDetail();
54+
pd.setStatus(status.value());
55+
pd.setTitle("HTTP error");
56+
pd.setDetail(detail);
57+
return pd;
58+
}
59+
}

customer-service-client/src/main/java/io/github/bsayli/openapi/client/common/error/ClientProblemException.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import java.io.Serializable;
66

77
/**
8-
* Wraps non-2xx HTTP responses decoded into RFC 9457 (“Problem Details for HTTP APIs”)
9-
* {@link ProblemDetail}. Thrown by the RestClient defaultStatusHandler in client config.
10-
* See: <a href="https://www.rfc-editor.org/rfc/rfc9457">...</a>
8+
* Wraps non-2xx HTTP responses decoded into RFC 9457 (“Problem Details for HTTP APIs”) {@link
9+
* ProblemDetail}. Thrown by the RestClient defaultStatusHandler in client config. See: <a
10+
* href="https://www.rfc-editor.org/rfc/rfc9457">...</a>
1111
*/
1212
public final class ClientProblemException extends RuntimeException implements Serializable {
1313

@@ -36,7 +36,7 @@ private static String buildMessage(ProblemDetail pd, int status) {
3636
appendIfNotBlank(sb, " | ", pd.getDetail());
3737

3838
tag(sb, "code", pd.getErrorCode());
39-
tag(sb, "type", pd.getType() != null ? pd.getType().toString() : null);
39+
tag(sb, "type", pd.getType() != null ? pd.getType().toString() : null);
4040
tag(sb, "instance", pd.getInstance() != null ? pd.getInstance().toString() : null);
4141
return sb.toString();
4242
}
@@ -46,7 +46,8 @@ private static void appendIfNotBlank(StringBuilder sb, String sep, String v) {
4646
}
4747

4848
private static void tag(StringBuilder sb, String key, String value) {
49-
if (value != null && !value.isBlank()) sb.append(" [").append(key).append('=').append(value).append(']');
49+
if (value != null && !value.isBlank())
50+
sb.append(" [").append(key).append('=').append(value).append(']');
5051
}
5152

5253
public ProblemDetail getProblem() {

customer-service-client/src/test/java/io/github/bsayli/openapi/client/adapter/CustomerClientErrorIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ void createCustomer_400_problem() {
100100

101101
@Test
102102
@DisplayName(
103-
"DELETE /v1/customers/{id} -> 500 (no body) => throws ClientProblemException with fallback ProblemDetail")
103+
"DELETE /v1/customers/{id} -> 500 (no body) => throws ClientProblemException with fallback ProblemDetail")
104104
void deleteCustomer_500_no_body() {
105105
server.enqueue(
106-
new MockResponse()
107-
.setResponseCode(500)
108-
.addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE));
106+
new MockResponse()
107+
.setResponseCode(500)
108+
.addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE));
109109

110110
var ex = assertThrows(ClientProblemException.class, () -> api.deleteCustomer(1));
111111

customer-service-client/src/test/java/io/github/bsayli/openapi/client/adapter/config/CustomerApiClientConfigStatusHandlerTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CustomerApiClientConfigStatusHandlerTest {
2121

2222
@Test
2323
@DisplayName(
24-
"400 with application/problem+json -> throws ClientProblemException with parsed ProblemDetail")
24+
"400 with application/problem+json -> throws ClientProblemException with parsed ProblemDetail")
2525
void handler_parses_problem_detail_on_4xx() {
2626
// Arrange
2727
var om = new ObjectMapper();
@@ -33,7 +33,7 @@ void handler_parses_problem_detail_on_4xx() {
3333
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
3434

3535
String body =
36-
"""
36+
"""
3737
{
3838
"type":"https://example.org/problem/bad-request",
3939
"title":"Bad Request",
@@ -46,19 +46,19 @@ void handler_parses_problem_detail_on_4xx() {
4646
""";
4747

4848
server
49-
.expect(once(), requestTo("http://localhost/err400"))
50-
.andRespond(
51-
withStatus(HttpStatus.BAD_REQUEST)
52-
.contentType(MediaType.valueOf("application/problem+json"))
53-
.body(body));
49+
.expect(once(), requestTo("http://localhost/err400"))
50+
.andRespond(
51+
withStatus(HttpStatus.BAD_REQUEST)
52+
.contentType(MediaType.valueOf("application/problem+json"))
53+
.body(body));
5454

5555
RestClient client = builder.build();
5656

5757
// Act + Assert
5858
ClientProblemException ex =
59-
assertThrows(
60-
ClientProblemException.class,
61-
() -> client.get().uri("/err400").retrieve().body(String.class));
59+
assertThrows(
60+
ClientProblemException.class,
61+
() -> client.get().uri("/err400").retrieve().body(String.class));
6262

6363
assertEquals(400, ex.getStatus());
6464
ProblemDetail pd = ex.getProblem();
@@ -83,26 +83,26 @@ void handler_handles_empty_body_on_5xx() {
8383
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
8484

8585
server
86-
.expect(once(), requestTo("http://localhost/err500"))
87-
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); // no body, no content-type
86+
.expect(once(), requestTo("http://localhost/err500"))
87+
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); // no body, no content-type
8888

8989
RestClient client = builder.build();
9090

9191
// Act + Assert
9292
ClientProblemException ex =
93-
assertThrows(
94-
ClientProblemException.class,
95-
() -> client.get().uri("/err500").retrieve().body(String.class));
93+
assertThrows(
94+
ClientProblemException.class,
95+
() -> client.get().uri("/err500").retrieve().body(String.class));
9696

9797
assertEquals(500, ex.getStatus());
9898

9999
// Yeni davranış: fallback ProblemDetail DOLU geliyor
100100
ProblemDetail pd = ex.getProblem();
101101
assertNotNull(pd);
102-
assertEquals(500, pd.getStatus()); // fallback status
103-
assertEquals("HTTP error", pd.getTitle()); // fallback title
102+
assertEquals(500, pd.getStatus()); // fallback status
103+
assertEquals("HTTP error", pd.getTitle()); // fallback title
104104
assertEquals("Empty problem response body", pd.getDetail()); // fallback detail
105105

106106
server.verify();
107107
}
108-
}
108+
}

customer-service/src/main/java/io/github/bsayli/customerservice/api/controller/CustomerController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
import io.github.bsayli.customerservice.common.api.response.Meta;
55
import io.github.bsayli.customerservice.common.api.response.Page;
66
import io.github.bsayli.customerservice.common.api.response.ServiceResponse;
7-
import io.github.bsayli.customerservice.common.api.sort.Sort;
87
import io.github.bsayli.customerservice.common.api.sort.SortDirection;
98
import io.github.bsayli.customerservice.common.api.sort.SortField;
109
import io.github.bsayli.customerservice.service.CustomerService;
1110
import jakarta.validation.Valid;
1211
import jakarta.validation.constraints.Max;
1312
import jakarta.validation.constraints.Min;
1413
import java.net.URI;
15-
import java.util.List;
1614
import org.springframework.http.MediaType;
1715
import org.springframework.http.ResponseEntity;
1816
import org.springframework.validation.annotation.Validated;

customer-service/src/main/java/io/github/bsayli/customerservice/common/api/response/Meta.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ public static Meta now(SortField field, SortDirection direction) {
2929
return new Meta(Instant.now(), List.of(new Sort(field, direction)));
3030
}
3131
}
32-

customer-service/src/main/java/io/github/bsayli/customerservice/common/api/response/error/ProblemExtensions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
/**
77
* Container for optional extension fields in {@code application/problem+json}.
8-
* <p>
9-
* Initially includes {@link ErrorItem} list, but designed to be extensible
10-
* for future metadata (traceId, correlationId, pagination info, etc.).
8+
*
9+
* <p>Initially includes {@link ErrorItem} list, but designed to be extensible for future metadata
10+
* (traceId, correlationId, pagination info, etc.).
1111
*/
1212
@JsonInclude(JsonInclude.Include.NON_NULL)
1313
public record ProblemExtensions(List<ErrorItem> errors) {
1414
public static ProblemExtensions ofErrors(List<ErrorItem> errors) {
1515
return new ProblemExtensions(errors);
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)