Skip to content

Commit 9df68f1

Browse files
committed
Make ValidationResponse package private and final (it's not jpms exported)
Plus formating changes
1 parent 6445ac5 commit 9df68f1

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

http-inject-plugin/src/main/java/io/avaje/http/inject/HelidonHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ final class HelidonHandler implements HttpFeature {
1515

1616
@Override
1717
public void setup(Builder routing) {
18-
1918
routing.error(ValidationException.class, this::handle);
2019
}
2120

2221
private void handle(ServerRequest req, ServerResponse res, ValidationException ex) {
2322
try (var os =
24-
res.status(ex.getStatus())
25-
.header("Content-Type", "application/problem+json")
26-
.outputStream()) {
23+
res.status(ex.getStatus())
24+
.header("Content-Type", "application/problem+json")
25+
.outputStream()) {
2726
new ValidationResponse(ex.getStatus(), ex.getErrors(), req.path().rawPath()).toJson(os);
2827
} catch (IOException e) {
2928
throw new UncheckedIOException(e);

http-inject-plugin/src/main/java/io/avaje/http/inject/HttpValidatorErrorPlugin.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,49 @@
77
import io.avaje.jex.Routing.HttpService;
88
import io.helidon.webserver.http.HttpFeature;
99

10-
/** Plugin for avaje inject that provides a default Validator Handler */
10+
/**
11+
* Plugin for avaje inject that provides a default Validator Handler
12+
*/
1113
@PluginProvides(
12-
providesStrings = {
13-
"io.helidon.webserver.http.HttpFeature",
14-
"io.avaje.http.api.AvajeJavalinPlugin",
15-
"io.avaje.jex.Routing.HttpService",
16-
})
14+
providesStrings = {
15+
"io.helidon.webserver.http.HttpFeature",
16+
"io.avaje.http.api.AvajeJavalinPlugin",
17+
"io.avaje.jex.Routing.HttpService",
18+
})
1719
public final class HttpValidatorErrorPlugin implements InjectPlugin {
1820

1921
@Override
2022
public void apply(BeanScopeBuilder builder) {
21-
2223
ModuleLayer bootLayer = ModuleLayer.boot();
2324

24-
bootLayer
25-
.findModule("io.avaje.http.plugin")
26-
.ifPresentOrElse(
27-
m -> {
28-
if (bootLayer.findModule("io.avaje.jex").isPresent()) {
29-
builder.provideDefault(HttpService.class, JexHandler::new);
30-
} else if (bootLayer.findModule("io.helidon.webserver").isPresent()) {
31-
builder.provideDefault(HttpFeature.class, HelidonHandler::new);
32-
} else if (bootLayer.findModule("io.javalin").isPresent()) {
33-
builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new);
34-
}
35-
},
36-
() -> {
37-
try {
38-
builder.provideDefault(HttpService.class, JexHandler::new);
39-
return;
40-
} catch (NoClassDefFoundError e) {
41-
// not present
42-
}
43-
try {
44-
builder.provideDefault(HttpFeature.class, HelidonHandler::new);
45-
return;
46-
} catch (NoClassDefFoundError e) {
47-
// not present
48-
}
49-
try {
50-
builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new);
51-
} catch (NoClassDefFoundError e) {
52-
// not present
53-
}
54-
});
25+
bootLayer.findModule("io.avaje.http.plugin")
26+
.ifPresentOrElse(m -> {
27+
if (bootLayer.findModule("io.avaje.jex").isPresent()) {
28+
builder.provideDefault(HttpService.class, JexHandler::new);
29+
} else if (bootLayer.findModule("io.helidon.webserver").isPresent()) {
30+
builder.provideDefault(HttpFeature.class, HelidonHandler::new);
31+
} else if (bootLayer.findModule("io.javalin").isPresent()) {
32+
builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new);
33+
}
34+
},
35+
() -> {
36+
try {
37+
builder.provideDefault(HttpService.class, JexHandler::new);
38+
return;
39+
} catch (NoClassDefFoundError e) {
40+
// not present
41+
}
42+
try {
43+
builder.provideDefault(HttpFeature.class, HelidonHandler::new);
44+
return;
45+
} catch (NoClassDefFoundError e) {
46+
// not present
47+
}
48+
try {
49+
builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new);
50+
} catch (NoClassDefFoundError e) {
51+
// not present
52+
}
53+
});
5554
}
5655
}

http-inject-plugin/src/main/java/io/avaje/http/inject/JavalinHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.javalin.http.Context;
1010

1111
final class JavalinHandler extends AvajeJavalinPlugin {
12+
1213
@Override
1314
public void onStart(JavalinConfig config) {
1415
config.router.mount(r -> r.exception(ValidationException.class, this::handler));

http-inject-plugin/src/main/java/io/avaje/http/inject/JexHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public void add(Routing arg0) {
1616
}
1717

1818
private void handler(Context ctx, ValidationException ex) {
19-
2019
try (var os =
2120
ctx.contentType("application/problem+json").status(ex.getStatus()).outputStream()) {
2221
new ValidationResponse(ex.getStatus(), ex.getErrors(), ctx.path()).toJson(os);

http-inject-plugin/src/main/java/io/avaje/http/inject/ValidationResponse.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
import java.io.OutputStream;
55
import java.io.OutputStreamWriter;
66
import java.io.Writer;
7+
import java.nio.charset.StandardCharsets;
78
import java.util.List;
89

910
import io.avaje.http.api.ValidationException.Violation;
1011

11-
public class ValidationResponse {
12-
13-
private static String title = "Request Failed Validation";
14-
private static String detail = "You tried to call this endpoint, but a io.avaje.http.api.ValidationException was thrown";
12+
final class ValidationResponse {
13+
14+
private static final String title = "Request Failed Validation";
15+
private static final String detail = "You tried to call this endpoint, but a io.avaje.http.api.ValidationException was thrown";
1516
private final int status;
1617
private final List<Violation> errors;
1718
private final String instance;
1819

19-
public ValidationResponse(int status, List<Violation> errors, String instance) {
20+
ValidationResponse(int status, List<Violation> errors, String instance) {
2021
this.status = status;
2122
this.errors = errors;
2223
this.instance = instance;
2324
}
24-
25+
2526
// custom serialize as this is a simple class
26-
public void toJson(OutputStream os) throws IOException {
27-
try (Writer writer = new OutputStreamWriter(os, "UTF-8")) {
27+
void toJson(OutputStream os) throws IOException {
28+
try (Writer writer = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
2829
writeJsonInternal(writer);
2930
}
3031
}

0 commit comments

Comments
 (0)