Skip to content

Commit 7dce029

Browse files
authored
4.x: Refactor Http class (helidon-io#7570)
* Move HTTP method to a top level class * Move HTTP status to a top level class * Move HTTP HeaderName to a top level class * Move HTTP HeaderNames to a top level class * Move HTTP Header to a top level class * Move HTTP Headers to a top level class HeaderValues * Move HTTP DateTime to a top level class * Tying loose ends (archetypes, deprecation)
1 parent c4860f1 commit 7dce029

475 files changed

Lines changed: 5576 additions & 5172 deletions

File tree

Some content is hidden

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

archetypes/helidon/src/main/archetype/common/extra.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
110110
<list key="modules">
111111
<value if="${flavor} == 'mp'">io.helidon.microprofile.faulttolerance</value>
112112
</list>
113-
<list key="Main-helidon-imports" if="${flavor} == 'mp'">
114-
<value>io.helidon.http.Http</value>
115-
</list>
116113
<list key="Main-other-imports" if="${flavor} == 'mp'">
117114
<value>java.util.concurrent.TimeoutException</value>
118115
</list>
@@ -325,9 +322,9 @@ restrictive-cors:
325322
<value>io.helidon.cors.CrossOriginConfig</value>
326323
</list>
327324
<list key="MainTest-static-imports" if="${flavor} == 'se'">
328-
<value>io.helidon.http.Http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN</value>
329-
<value>io.helidon.http.Http.HeaderNames.HOST</value>
330-
<value>io.helidon.http.Http.HeaderNames.ORIGIN</value>
325+
<value>io.helidon.http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN</value>
326+
<value>io.helidon.http.HeaderNames.HOST</value>
327+
<value>io.helidon.http.HeaderNames.ORIGIN</value>
331328
</list>
332329
<list key="MainTest-static-imports">
333330
<value if="${flavor} == 'se'">org.hamcrest.CoreMatchers.containsString</value>

archetypes/helidon/src/main/archetype/common/media.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
try (Http1ClientResponse response = client.get("/greet")
5454
.request()) {
5555
56-
assertThat(response.status(), is(Http.Status.OK_200));
56+
assertThat(response.status(), is(Status.OK_200));
5757
JsonObject json = response.as(JsonObject.class);
5858
assertThat(json.getString("message"), is("Hello World!"));
5959
}
@@ -113,15 +113,15 @@
113113
@Test
114114
void testGreet() {
115115
try (Http1ClientResponse response = client.get("/greet").request()) {
116-
assertThat(response.status(), is(Http.Status.OK_200));
116+
assertThat(response.status(), is(Status.OK_200));
117117
assertThat(response.as(Message.class).getMessage(), is("Hello World!"));
118118
}
119119
}
120120
121121
@Test
122122
void testGreetJoe() {
123123
try (Http1ClientResponse response = client.get("/greet/Joe").request()) {
124-
assertThat(response.status(), is(Http.Status.OK_200));
124+
assertThat(response.status(), is(Status.OK_200));
125125
assertThat(response.as(Message.class).getMessage(), is("Hello Joe!"));
126126
}
127127
}
@@ -171,14 +171,16 @@
171171
<value>jersey.media.multipart</value>
172172
</list>
173173
<list key="Main-helidon-imports" if="${flavor} == 'se'">
174-
<value>io.helidon.http.Http</value>
175-
<value>io.helidon.http.Http.Header</value>
174+
<value>io.helidon.http.Header</value>
175+
<value>io.helidon.http.Status</value>
176+
<value>io.helidon.http.HeaderNames</value>
177+
<value>io.helidon.http.HeaderValues</value>
176178
<value>io.helidon.webserver.staticcontent.StaticContentService</value>
177179
</list>
178180
<list key="Main-routing-builder" if="${flavor} == 'se'">
179181
<value order="1"><![CDATA[.any("/", (req, res) -> {
180-
res.status(Http.Status.MOVED_PERMANENTLY_301);
181-
res.header(Http.Headers.createCached(Http.HeaderNames.LOCATION, "/ui"));
182+
res.status(Status.MOVED_PERMANENTLY_301);
183+
res.header(HeaderValues.createCached(HeaderNames.LOCATION, "/ui"));
182184
res.send();
183185
})
184186
.register("/ui", StaticContentService.builder("WEB")
@@ -191,7 +193,7 @@
191193
@Test
192194
void testFileService() {
193195
try (Http1ClientResponse response = client.get("/api").request()) {
194-
assertThat(response.status(), is(Http.Status.OK_200));
196+
assertThat(response.status(), is(Status.OK_200));
195197
}
196198
}
197199
]]></value>

archetypes/helidon/src/main/archetype/common/observability.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ curl -s -X GET http://localhost:8080/health
547547
@Test
548548
void testHealth() {
549549
try (Http1ClientResponse response = client.get("/observe/health").request()) {
550-
assertThat(response.status(), is(Http.Status.OK_200));
550+
assertThat(response.status(), is(Status.OK_200));
551551
assertThat(response.as(String.class), containsString("status\":\"UP"));
552552
}
553553
}

archetypes/helidon/src/main/archetype/mp/custom/files/src/test/java/__pkg__/TestCORS.java.mustache

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package {{package}};
22

3-
import io.helidon.http.Http;
3+
import io.helidon.http.HeaderNames;
44
import io.helidon.config.Config;
55
import io.helidon.cors.CrossOriginConfig;
66
import io.helidon.microprofile.tests.junit5.HelidonTest;
@@ -29,46 +29,46 @@ class TestCORS {
2929
void testAnonymousGreetWithCors() {
3030
Response r = target.path("/simple-greet")
3131
.request()
32-
.header(Http.HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
33-
.header(Http.HeaderNames.HOST.defaultCase(), "here.com")
32+
.header(HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
33+
.header(HeaderNames.HOST.defaultCase(), "here.com")
3434
.get();
3535
3636
assertThat("HTTP response", r.getStatus(), is(200));
3737
String payload = fromPayload(r);
3838
assertThat("HTTP response payload", payload.contains("Hello World!"), is(true));
3939
assertThat("CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN,
40-
r.getHeaders().getFirst(Http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
40+
r.getHeaders().getFirst(HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
4141
is("http://foo.com"));
4242
}
4343

4444
@Test
4545
void testCustomGreetingWithCors() {
4646
Response r = target.path("/simple-greet")
4747
.request()
48-
.header(Http.HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
49-
.header(Http.HeaderNames.HOST.defaultCase(), "here.com")
48+
.header(HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
49+
.header(HeaderNames.HOST.defaultCase(), "here.com")
5050
.header("Access-Control-Request-Method", "PUT")
5151
.options();
5252
5353
assertThat("pre-flight status", r.getStatus(), is(200));
5454
MultivaluedMap<String, Object> responseHeaders = r.getHeaders();
5555
assertThat("Header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_METHODS,
56-
r.getHeaders().getFirst(Http.HeaderNames.ACCESS_CONTROL_ALLOW_METHODS.defaultCase()),
56+
r.getHeaders().getFirst(HeaderNames.ACCESS_CONTROL_ALLOW_METHODS.defaultCase()),
5757
is("PUT"));
5858
assertThat( "Header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN,
59-
r.getHeaders().getFirst(Http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
59+
r.getHeaders().getFirst(HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
6060
is("http://foo.com"));
6161
6262
Invocation.Builder builder = target.path("/simple-greet")
6363
.request()
6464
.headers(responseHeaders)
65-
.header(Http.HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
66-
.header(Http.HeaderNames.HOST.defaultCase(), "here.com");
65+
.header(HeaderNames.ORIGIN.defaultCase(), "http://foo.com")
66+
.header(HeaderNames.HOST.defaultCase(), "here.com");
6767
6868
r = putResponse("Cheers", builder);
6969
assertThat("HTTP response3", r.getStatus(), is(200));
7070
assertThat( "Header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN,
71-
r.getHeaders().getFirst(Http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
71+
r.getHeaders().getFirst(HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.defaultCase()),
7272
is("http://foo.com"));
7373
assertThat(fromPayload(r), containsString("Cheers World!"));
7474
}
@@ -77,8 +77,8 @@ class TestCORS {
7777
void testGreetingChangeWithCorsAndOtherOrigin() {
7878
Invocation.Builder builder = target.path("/simple-greet")
7979
.request()
80-
.header(Http.HeaderNames.ORIGIN.defaultCase(), "http://other.com")
81-
.header(Http.HeaderNames.HOST.defaultCase(), "here.com");
80+
.header(HeaderNames.ORIGIN.defaultCase(), "http://other.com")
81+
.header(HeaderNames.HOST.defaultCase(), "here.com");
8282
8383
Response r = putResponse("Ahoy", builder);
8484
boolean isOverriding = Config.create().get("cors").exists();

archetypes/helidon/src/main/archetype/se/common/common-se.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<value>io.helidon.webserver.http.HttpRouting</value>
5858
</list>
5959
<list key="MainTest-helidon-imports">
60-
<value>io.helidon.http.Http</value>
60+
<value>io.helidon.http.Status</value>
6161
<value>io.helidon.config.Config</value>
6262
<value>io.helidon.webserver.testing.junit5.SetUpRoute</value>
6363
<value>io.helidon.webclient.http1.Http1Client</value>

archetypes/helidon/src/main/archetype/se/custom/custom-se.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
@Test
4747
void testSimpleGreet() {
4848
try (Http1ClientResponse response = client.get("/simple-greet").request()) {
49-
assertThat(response.status(), is(Http.Status.OK_200));
49+
assertThat(response.status(), is(Status.OK_200));
5050
assertThat(response.as(String.class), is("Hello World!"));
5151
}
5252
}

archetypes/helidon/src/main/archetype/se/custom/extra.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
</map>
3030
</list>
3131
<list key="Main-helidon-imports" if="${extra} contains 'fault-tolerance'">
32-
<value>io.helidon.http.Http</value>
32+
<value>io.helidon.http.Status</value>
3333
<value>io.helidon.faulttolerance.BulkheadException</value>
3434
<value>io.helidon.faulttolerance.CircuitBreakerOpenException</value>
3535
<value>io.helidon.faulttolerance.TimeoutException</value>
3636
</list>
3737
<list key="Main-routing-builder" if="${extra} contains 'fault-tolerance'">
3838
<value><![CDATA[.register("/", new FtService())
3939
.error(BulkheadException.class,
40-
(req, res, ex) -> res.status(Http.Status.SERVICE_UNAVAILABLE_503).send("bulkhead"))
40+
(req, res, ex) -> res.status(Status.SERVICE_UNAVAILABLE_503).send("bulkhead"))
4141
.error(CircuitBreakerOpenException.class,
42-
(req, res, ex) -> res.status(Http.Status.SERVICE_UNAVAILABLE_503).send("circuit breaker"))
42+
(req, res, ex) -> res.status(Status.SERVICE_UNAVAILABLE_503).send("circuit breaker"))
4343
.error(TimeoutException.class,
44-
(req, res, ex) -> res.status(Http.Status.REQUEST_TIMEOUT_408).send("timeout"))
44+
(req, res, ex) -> res.status(Status.REQUEST_TIMEOUT_408).send("timeout"))
4545
.error(Throwable.class,
46-
(req, res, ex) -> res.status(Http.Status.INTERNAL_SERVER_ERROR_500)
46+
(req, res, ex) -> res.status(Status.INTERNAL_SERVER_ERROR_500)
4747
.send(ex.getClass().getName() + ": " + ex.getMessage()))]]></value>
4848
</list>
4949
<list key="Abstract-tests" if="${extra} contains 'fault-tolerance'">
@@ -75,7 +75,7 @@
7575
7676
try (Http1ClientResponse third = client.get().path("/bulkhead/10000").request()) {
7777
// registered an error handler in Main
78-
assertThat(third.status(), is(Http.Status.OK_200));
78+
assertThat(third.status(), is(Status.OK_200));
7979
assertThat(third.as(String.class), is("Call rejected: 1"));
8080
}
8181
}
@@ -114,7 +114,7 @@
114114
.request();
115115
116116
// registered an error handler in Main
117-
assertThat(clientResponse.status(), is(Http.Status.SERVICE_UNAVAILABLE_503));
117+
assertThat(clientResponse.status(), is(Status.SERVICE_UNAVAILABLE_503));
118118
assertThat(clientResponse.as(String.class), is("circuit breaker"));
119119
}
120120
@@ -163,7 +163,7 @@
163163
.request()) {
164164
165165
// no error handler specified
166-
assertThat(clientResponse.status(), is(Http.Status.INTERNAL_SERVER_ERROR_500));
166+
assertThat(clientResponse.status(), is(Status.INTERNAL_SERVER_ERROR_500));
167167
assertThat(clientResponse.as(String.class), is("java.lang.RuntimeException: reactive failure"));
168168
}
169169
}
@@ -181,7 +181,7 @@
181181
.path("/timeout/1000")
182182
.request()) {
183183
// error handler specified in Main
184-
assertThat(clientResponse.status(), is(Http.Status.REQUEST_TIMEOUT_408));
184+
assertThat(clientResponse.status(), is(Status.REQUEST_TIMEOUT_408));
185185
assertThat(clientResponse.as(String.class), is("timeout"));
186186
}
187187
}

archetypes/helidon/src/main/archetype/se/custom/files/src/main/java/__pkg__/FileService.java.multipart.mustache

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import java.util.Map;
1010
import java.util.stream.Stream;
1111

1212
import io.helidon.http.ContentDisposition;
13-
import io.helidon.http.Http;
14-
import io.helidon.http.Http.Header;
13+
import io.helidon.http.Header;
14+
import io.helidon.http.HeaderValues;
15+
import io.helidon.http.HeaderNames;
1516
import io.helidon.http.ServerResponseHeaders;
1617
import io.helidon.common.media.type.MediaTypes;
1718
import io.helidon.http.media.multipart.MultiPart;
@@ -25,15 +26,15 @@ import jakarta.json.Json;
2526
import jakarta.json.JsonArrayBuilder;
2627
import jakarta.json.JsonBuilderFactory;
2728

28-
import static io.helidon.http.Http.Status.BAD_REQUEST_400;
29-
import static io.helidon.http.Http.Status.MOVED_PERMANENTLY_301;
30-
import static io.helidon.http.Http.Status.NOT_FOUND_404;
29+
import static io.helidon.http.Status.BAD_REQUEST_400;
30+
import static io.helidon.http.Status.MOVED_PERMANENTLY_301;
31+
import static io.helidon.http.Status.NOT_FOUND_404;
3132

3233
/**
3334
* File service.
3435
*/
3536
final class FileService implements HttpService {
36-
private static final Http.Header UI_LOCATION = Http.Headers.createCached(Http.HeaderNames.LOCATION, "/ui");
37+
private static final Header UI_LOCATION = HeaderValues.createCached(HeaderNames.LOCATION, "/ui");
3738
private final JsonBuilderFactory jsonFactory;
3839
private final Path storage;
3940

archetypes/helidon/src/main/archetype/se/custom/files/src/main/java/__pkg__/GreetService.java.json.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.util.concurrent.atomic.AtomicReference;
55
{{#GreetService-imports}}
66
{{.}}
77
{{/GreetService-imports}}
8-
import io.helidon.http.Http;
8+
import io.helidon.http.Status;
99
import io.helidon.webserver.http.HttpRules;
1010
import io.helidon.webserver.http.HttpService;
1111
import io.helidon.webserver.http.ServerRequest;
@@ -80,13 +80,13 @@ public class GreetService implements HttpService {
8080
if (message.getGreeting() == null) {
8181
Message errorMessage = new Message();
8282
errorMessage.setMessage("No greeting provided");
83-
response.status(Http.Status.BAD_REQUEST_400)
83+
response.status(Status.BAD_REQUEST_400)
8484
.send(errorMessage);
8585
return;
8686
}
8787

8888
greeting.set(message.getGreeting());
89-
response.status(Http.Status.NO_CONTENT_204).send();
89+
response.status(Status.NO_CONTENT_204).send();
9090
}
9191

9292
/**

archetypes/helidon/src/main/archetype/se/custom/files/src/main/java/__pkg__/GreetService.java.jsonp.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicReference;
66
{{#GreetService-imports}}
77
{{.}}
88
{{/GreetService-imports}}
9-
import io.helidon.http.Http;
9+
import io.helidon.http.Status;
1010
import io.helidon.webserver.http.HttpRules;
1111
import io.helidon.webserver.http.HttpService;
1212
import io.helidon.webserver.http.ServerRequest;
@@ -105,13 +105,13 @@ class GreetService implements HttpService {
105105
JsonObject jsonErrorObject = JSON.createObjectBuilder()
106106
.add("error", "No greeting provided")
107107
.build();
108-
response.status(Http.Status.BAD_REQUEST_400)
108+
response.status(Status.BAD_REQUEST_400)
109109
.send(jsonErrorObject);
110110
return;
111111
}
112112

113113
greeting.set(jo.getString("greeting"));
114-
response.status(Http.Status.NO_CONTENT_204).send();
114+
response.status(Status.NO_CONTENT_204).send();
115115
}
116116

117117
/**

0 commit comments

Comments
 (0)