Skip to content

Commit 35e81e6

Browse files
fix: Fixed Java SDK bugs after QA testing (#1249)
- Fixed bugs due to description of: #1248 - Reimplemented allowList/denyList logic - Updated tests
1 parent 65b7c0d commit 35e81e6

File tree

22 files changed

+395
-130
lines changed

22 files changed

+395
-130
lines changed

packages/java/examples/SpringMetricsExample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<groupId>com.readme</groupId>
2525
<artifactId>metrics-spring</artifactId>
2626
<!-- <artifactId>metrics-spring2</artifactId>-->
27-
<version>0.1.0</version>
27+
<version>0.1.1</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.springframework.boot</groupId>

packages/java/examples/SpringMetricsExample/src/main/java/com/owl/example/CustomUserDataCollectorConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ public UserDataCollector<ServletDataPayloadAdapter> customUserDataCollector() {
4242
@Bean
4343
public LogOptions logOptions() {
4444
return LogOptions.builder()
45-
.baseLogUrl("http://baseurl.abcd")
45+
.baseLogUrl("http://base.log.url")
4646
.bufferLength(1)
47+
.denylist(List.of("denied-param"))
4748
.build();
4849
}
4950
}

packages/java/examples/SpringMetricsExample/src/main/java/com/owl/example/OwlController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@ public ResponseEntity<String> createOwl(@PathVariable String owlName, @RequestBo
4141
UUID birdId = UUID.randomUUID();
4242
owlStorage.put(birdId.toString(), owlName);
4343

44-
String responseBody = "Bird " + owlName + " created a bird with id: " + birdId + "\n" +
45-
"Creation request body: \n" + body;
46-
4744
HttpHeaders headers = new HttpHeaders();
4845
headers.add("bird-id", birdId.toString());
4946
headers.add("bird-token", Base64.getEncoder()
5047
.encodeToString(birdId.toString()
5148
.getBytes()));
49+
headers.add("denied-param", "test");
5250

5351
return ResponseEntity.status(HttpStatus.CREATED.getCode())
5452
.headers(headers)
55-
.body(responseBody);
53+
.contentType(MediaType.APPLICATION_JSON)
54+
.body(body);
5655
}
5756

5857
@PutMapping(value = "/owl/urlencoded/{owlName}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)

packages/java/metrics-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<groupId>com.readme</groupId>
2828
<name>metrics-core</name>
2929
<artifactId>metrics-core</artifactId>
30-
<version>0.1.0</version>
30+
<version>0.1.1</version>
3131
<description>Core library for Readme.io JVM related SDKs</description>
3232

3333
<properties>
Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.readme.core.dataextraction;
22

3-
4-
import lombok.Builder;
5-
import lombok.Value;
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
import org.jetbrains.annotations.NotNull;
66

77
import java.util.List;
8+
import java.util.Locale;
9+
import java.util.Objects;
10+
import java.util.Set;
11+
import java.util.stream.Collectors;
812

9-
@Value
10-
@Builder
13+
@Getter
14+
@ToString
1115
public class LogOptions {
1216

1317
/**
@@ -17,33 +21,95 @@ public class LogOptions {
1721
* If set, the denylist will be ignored.
1822
*/
1923

20-
List<String> allowlist;
24+
private Set<String> allowlist;
2125

2226
/**
2327
* An array of values to redact from the incoming and outgoing headers, parameters and body.
2428
*/
25-
List<String> denylist;
29+
private Set<String> denylist;
2630

2731
/**
2832
* If true, the logs will be marked as development logs.
2933
*/
30-
boolean development;
34+
private boolean development;
3135

3236
/**
3337
* If true, this will return the log details without waiting for a response from the Metrics
3438
* servers.
3539
*/
36-
boolean fireAndForget;
40+
private boolean fireAndForget;
3741

3842
/**
3943
* URL for your documentation site
4044
*/
41-
String baseLogUrl;
45+
private String baseLogUrl;
4246

4347
/**
4448
* Buffer size
4549
*/
46-
@Builder.Default
47-
int bufferLength = 1;
50+
int bufferLength;
51+
52+
private LogOptions(Builder builder) {
53+
this.allowlist = builder.allowlist;
54+
this.denylist = builder.denylist;
55+
this.development = builder.development;
56+
this.fireAndForget = builder.fireAndForget;
57+
this.baseLogUrl = builder.baseLogUrl;
58+
this.bufferLength = builder.bufferLength;
59+
}
60+
61+
public static Builder builder() {
62+
return new Builder();
63+
}
64+
65+
public static class Builder {
66+
private Set<String> allowlist;
67+
private Set<String> denylist;
68+
private boolean development;
69+
private boolean fireAndForget;
70+
private String baseLogUrl;
71+
private int bufferLength = 1; // default
72+
73+
@NotNull
74+
private static Set<String> castToSetWithLowercase(List<String> allowlist) {
75+
return allowlist.stream()
76+
.filter(Objects::nonNull)
77+
.map(a -> a.toLowerCase(Locale.ROOT))
78+
.collect(Collectors.toSet());
79+
}
80+
81+
public Builder allowlist(List<String> allowlist) {
82+
this.allowlist = castToSetWithLowercase(allowlist);
83+
return this;
84+
}
85+
86+
public Builder denylist(List<String> denylist) {
87+
this.denylist = castToSetWithLowercase(denylist);;
88+
return this;
89+
}
90+
91+
public Builder development(boolean development) {
92+
this.development = development;
93+
return this;
94+
}
95+
96+
public Builder fireAndForget(boolean fireAndForget) {
97+
this.fireAndForget = fireAndForget;
98+
return this;
99+
}
100+
101+
public Builder baseLogUrl(String baseLogUrl) {
102+
this.baseLogUrl = baseLogUrl;
103+
return this;
104+
}
105+
106+
public Builder bufferLength(int bufferLength) {
107+
this.bufferLength = bufferLength;
108+
return this;
109+
}
48110

111+
public LogOptions build() {
112+
return new LogOptions(this);
113+
}
114+
}
49115
}

packages/java/metrics-core/src/main/java/com/readme/core/dataextraction/payload/PayloadData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.Value;
77

88
import java.util.Date;
9+
import java.util.UUID;
910

1011
/**
1112
* Represents the complete payload for logging an API interaction, combining user-specific data, detailed API request
@@ -35,4 +36,9 @@ public class PayloadData {
3536
*/
3637
Date responseEndDateTime;
3738

39+
/**
40+
* Log ID - randomly generated during collecting request/response data
41+
*/
42+
UUID logId;
43+
3844
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.readme.core.dataextraction.payload.requestresponse;
2+
3+
import lombok.Data;
4+
import lombok.experimental.SuperBuilder;
5+
6+
import java.util.Map;
7+
8+
@Data
9+
@SuperBuilder
10+
public abstract class BaseRequestResponseData {
11+
12+
/**
13+
* Request body prepared for logging
14+
*/
15+
String body;
16+
17+
/**
18+
* A map of HTTP headers included in the request.
19+
*/
20+
Map<String, String> headers;
21+
22+
}

packages/java/metrics-core/src/main/java/com/readme/core/dataextraction/payload/requestresponse/RequestData.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.readme.core.dataextraction.payload.requestresponse;
22

3-
import lombok.Builder;
4-
import lombok.Data;
5-
import lombok.Setter;
6-
import lombok.Value;
3+
import lombok.*;
4+
import lombok.experimental.SuperBuilder;
75

86
import java.util.Map;
97

@@ -13,13 +11,9 @@
1311
* request body, and metadata related to the request.
1412
*/
1513
@Data
16-
@Builder
17-
public class RequestData {
18-
19-
/**
20-
* Request body prepared for logging
21-
*/
22-
private String body;
14+
@SuperBuilder
15+
@EqualsAndHashCode
16+
public class RequestData extends BaseRequestResponseData {
2317

2418
/**
2519
* The route path associated with the request (e.g., "/api/v1/resource").
@@ -46,15 +40,9 @@ public class RequestData {
4640
*/
4741
private String method;
4842

49-
/**
50-
* A map of HTTP headers included in the request.
51-
*/
52-
private Map<String, String> headers;
53-
5443
/**
5544
* A map of query parameters extracted from the request URL.
5645
*/
5746
private Map<String, String> requestParameters;
5847

59-
6048
}

packages/java/metrics-core/src/main/java/com/readme/core/dataextraction/payload/requestresponse/ResponseData.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.readme.core.dataextraction.payload.requestresponse;
22

3-
import lombok.Builder;
4-
import lombok.Value;
3+
import lombok.*;
4+
import lombok.experimental.SuperBuilder;
55

66
import java.util.Map;
77

@@ -10,20 +10,10 @@
1010
* This class encapsulates key response attributes such as status code, headers,
1111
* response body, and status message.
1212
*/
13-
@Value
14-
@Builder
15-
public class ResponseData {
16-
17-
/**
18-
* The response body sent back to the client.
19-
*/
20-
String body;
21-
22-
/**
23-
* A map of HTTP headers included in the response.
24-
*/
25-
Map<String, String> headers;
26-
13+
@Data
14+
@SuperBuilder
15+
@EqualsAndHashCode
16+
public class ResponseData extends BaseRequestResponseData {
2717
/**
2818
* The HTTP status code of the response (e.g., 200 for OK, 404 for Not Found).
2919
*/

packages/java/metrics-core/src/main/java/com/readme/core/datatransfer/HttpDataSender.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.List;
1212

1313
import static com.readme.core.config.ReadmeApiConfig.README_METRICS_URL;
14-
import static com.readme.core.datatransfer.BaseLogUrlFetcher.fetchBaseLogUrl;
1514
import static com.readme.core.datatransfer.ReadmeApiKeyEncoder.encode;
1615

1716
/**
@@ -84,15 +83,11 @@ private static Request createRequest(List<OutgoingLogBody> payloadData, LogOptio
8483
RequestBody body = RequestBody
8584
.create(outgoingLogBody, MediaType.get(APPLICATION_JSON_TYPE));
8685

87-
String baseLogUrl = logOptions.getBaseLogUrl() != null ? logOptions.getBaseLogUrl() : fetchBaseLogUrl(encodedReadmeApiKey);
88-
89-
9086
return new Request.Builder()
9187
.url(README_METRICS_URL)
9288
.header("Accept", APPLICATION_JSON_TYPE)
9389
.header("Content-Type", APPLICATION_JSON_TYPE)
9490
.header("Authorization", encodedReadmeApiKey)
95-
.header("x-documentation-url", baseLogUrl)
9691
.method("POST", body)
9792
.build();
9893
}

0 commit comments

Comments
 (0)