Skip to content

Commit 03a8ba7

Browse files
committed
refactor: Move static Request accessors to internal LegacyRequestAccess
1 parent ff7e633 commit 03a8ba7

13 files changed

Lines changed: 32 additions & 32 deletions

src/main/java/com/retailsvc/http/internal/DispatchHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.retailsvc.http.internal;
22

33
import com.retailsvc.http.MissingOperationHandlerException;
4-
import com.retailsvc.http.Request;
54
import com.sun.net.httpserver.HttpExchange;
65
import com.sun.net.httpserver.HttpHandler;
76
import java.io.IOException;
@@ -16,7 +15,7 @@ public DispatchHandler(Map<String, HttpHandler> handlers) {
1615

1716
@Override
1817
public void handle(HttpExchange exchange) throws IOException {
19-
String opId = Request.operationId();
18+
String opId = LegacyRequestAccess.operationId();
2019
HttpHandler h = handlers.get(opId);
2120
if (h == null) {
2221
throw new MissingOperationHandlerException(opId);

src/main/java/com/retailsvc/http/Request.java renamed to src/main/java/com/retailsvc/http/internal/LegacyRequestAccess.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.retailsvc.http;
1+
package com.retailsvc.http.internal;
22

3-
import com.retailsvc.http.internal.RequestContext;
43
import java.util.Map;
54

65
/**
@@ -13,13 +12,16 @@
1312
* <p>If a handler dispatches work to a non-structured executor (i.e. not a {@code
1413
* StructuredTaskScope}-managed thread), it must capture the values it needs before submitting — the
1514
* {@link ScopedValue} is not visible from arbitrary worker threads.
15+
*
16+
* @deprecated Temporary scaffolding; will be deleted in a future task.
1617
*/
17-
public final class Request {
18+
@Deprecated
19+
public final class LegacyRequestAccess {
1820

1921
/** Bound by {@code RequestPreparationFilter} for the duration of each request. */
2022
public static final ScopedValue<RequestContext> CONTEXT = ScopedValue.newInstance();
2123

22-
private Request() {}
24+
private LegacyRequestAccess() {}
2325

2426
/**
2527
* Returns the full per-request context. Use this when a handler reads more than one field — every

src/main/java/com/retailsvc/http/internal/RequestContext.java

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

77
/**
88
* Immutable per-request data populated by {@link RequestPreparationFilter} and read by handlers via
9-
* {@link com.retailsvc.http.Request}. Bound to a {@link ScopedValue} for the duration of a single
10-
* request — never written to the {@code HttpExchange}'s context-shared attribute map.
9+
* {@link LegacyRequestAccess}. Bound to a {@link ScopedValue} for the duration of a single request
10+
* — never written to the {@code HttpExchange}'s context-shared attribute map.
1111
*
1212
* <p>{@code equals}, {@code hashCode}, and {@code toString} are overridden because the record
1313
* carries a {@code byte[]} component: the auto-generated implementations use reference equality on

src/main/java/com/retailsvc/http/internal/RequestPreparationFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.retailsvc.http.MethodNotAllowedException;
44
import com.retailsvc.http.NotFoundException;
5-
import com.retailsvc.http.Request;
65
import com.retailsvc.http.TypeMapper;
76
import com.retailsvc.http.ValidationException;
87
import com.retailsvc.http.spec.HttpMethod;
@@ -71,7 +70,7 @@ public void doFilter(HttpExchange exchange, Chain chain) throws IOException {
7170
private static void runWithRequestContext(RequestContext ctx, IORunnable work)
7271
throws IOException {
7372
try {
74-
ScopedValue.where(Request.CONTEXT, ctx)
73+
ScopedValue.where(LegacyRequestAccess.CONTEXT, ctx)
7574
.call(
7675
() -> {
7776
work.run();

src/test/java/com/retailsvc/http/RequestTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
55

6+
import com.retailsvc.http.internal.LegacyRequestAccess;
67
import com.retailsvc.http.internal.RequestContext;
78
import java.util.Map;
89
import java.util.NoSuchElementException;
@@ -21,13 +22,13 @@ void readsBoundContext() throws Exception {
2122
AtomicReference<String> seenOpId = new AtomicReference<>();
2223
AtomicReference<Map<String, String>> seenPathParams = new AtomicReference<>();
2324

24-
ScopedValue.where(Request.CONTEXT, ctx)
25+
ScopedValue.where(LegacyRequestAccess.CONTEXT, ctx)
2526
.call(
2627
() -> {
27-
seenBytes.set(Request.bytes());
28-
seenParsed.set(Request.parsed());
29-
seenOpId.set(Request.operationId());
30-
seenPathParams.set(Request.pathParams());
28+
seenBytes.set(LegacyRequestAccess.bytes());
29+
seenParsed.set(LegacyRequestAccess.parsed());
30+
seenOpId.set(LegacyRequestAccess.operationId());
31+
seenPathParams.set(LegacyRequestAccess.pathParams());
3132
return null;
3233
});
3334

@@ -39,6 +40,6 @@ void readsBoundContext() throws Exception {
3940

4041
@Test
4142
void readingOutsideScopeThrows() {
42-
assertThrows(NoSuchElementException.class, Request::bytes);
43+
assertThrows(NoSuchElementException.class, LegacyRequestAccess::bytes);
4344
}
4445
}

src/test/java/com/retailsvc/http/TypeMapperRegistrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.assertj.core.api.Assertions.assertThat;
77
import static org.assertj.core.api.Assertions.assertThatThrownBy;
88

9+
import com.retailsvc.http.internal.LegacyRequestAccess;
910
import com.sun.net.httpserver.HttpHandler;
1011
import java.net.URI;
1112
import java.net.http.HttpClient;
@@ -24,7 +25,7 @@ class TypeMapperRegistrationTest extends ServerBaseTest {
2425
void gsonFallbackIsAutoRegisteredWhenNoJsonMapperConfigured() throws Exception {
2526
HttpHandler echo =
2627
ex -> {
27-
Object parsed = Request.parsed();
28+
Object parsed = LegacyRequestAccess.parsed();
2829
byte[] out = gson.toJson(parsed).getBytes(StandardCharsets.UTF_8);
2930
ex.getResponseHeaders().add("Content-Type", "application/json");
3031
ex.sendResponseHeaders(200, out.length);

src/test/java/com/retailsvc/http/internal/DispatchHandlerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.mockito.Mockito.mock;
55

66
import com.retailsvc.http.MissingOperationHandlerException;
7-
import com.retailsvc.http.Request;
87
import com.sun.net.httpserver.HttpExchange;
98
import com.sun.net.httpserver.HttpHandler;
109
import java.util.Map;
@@ -16,7 +15,7 @@ class DispatchHandlerTest {
1615
private static void withOperationId(
1716
String operationId, ScopedValue.CallableOp<Void, Exception> body) throws Exception {
1817
RequestContext ctx = new RequestContext(new byte[0], null, operationId, Map.of());
19-
ScopedValue.where(Request.CONTEXT, ctx).call(body);
18+
ScopedValue.where(LegacyRequestAccess.CONTEXT, ctx).call(body);
2019
}
2120

2221
@Test

src/test/java/com/retailsvc/http/internal/RequestPreparationFilterTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import com.retailsvc.http.MethodNotAllowedException;
88
import com.retailsvc.http.NotFoundException;
9-
import com.retailsvc.http.Request;
109
import com.retailsvc.http.TypeMapper;
1110
import com.retailsvc.http.ValidationException;
1211
import com.retailsvc.http.spec.HttpMethod;
@@ -100,8 +99,8 @@ void successPathBindsRequestContextDuringChain() throws Exception {
10099
Filter.Chain chain = mock(Filter.Chain.class);
101100
Mockito.doAnswer(
102101
inv -> {
103-
seenOpId.set(Request.operationId());
104-
seenPathParams.set(Request.pathParams());
102+
seenOpId.set(LegacyRequestAccess.operationId());
103+
seenPathParams.set(LegacyRequestAccess.pathParams());
105104
return null;
106105
})
107106
.when(chain)

src/test/java/com/retailsvc/http/start/EchoHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.retailsvc.http.start;
22

3-
import com.retailsvc.http.Request;
3+
import com.retailsvc.http.internal.LegacyRequestAccess;
44
import com.sun.net.httpserver.HttpExchange;
55
import com.sun.net.httpserver.HttpHandler;
66
import java.io.IOException;
@@ -15,7 +15,7 @@ public class EchoHandler implements HttpHandler {
1515

1616
@Override
1717
public void handle(HttpExchange exchange) throws IOException {
18-
byte[] bytes = Request.bytes();
18+
byte[] bytes = LegacyRequestAccess.bytes();
1919

2020
if (bytes.length == 0) {
2121
LOG.debug("No bytes available to read from the request body");

src/test/java/com/retailsvc/http/start/FormEchoHandler.java

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

33
import static java.net.HttpURLConnection.HTTP_OK;
44

5-
import com.retailsvc.http.Request;
5+
import com.retailsvc.http.internal.LegacyRequestAccess;
66
import com.sun.net.httpserver.HttpExchange;
77
import com.sun.net.httpserver.HttpHandler;
88
import java.io.IOException;
@@ -13,7 +13,7 @@ public class FormEchoHandler implements HttpHandler {
1313

1414
@Override
1515
public void handle(HttpExchange exchange) throws IOException {
16-
Object parsed = Request.parsed();
16+
Object parsed = LegacyRequestAccess.parsed();
1717
byte[] body = String.valueOf(parsed).getBytes(StandardCharsets.UTF_8);
1818
try (exchange) {
1919
exchange.getResponseHeaders().add("Content-Type", "text/plain; charset=utf-8");

0 commit comments

Comments
 (0)