|
5 | 5 | import io.avaje.inject.spi.InjectPlugin; |
6 | 6 | import io.avaje.inject.spi.PluginProvides; |
7 | 7 | import io.avaje.jex.Routing.HttpService; |
8 | | -import io.avaje.spi.ServiceProvider; |
9 | 8 | import io.helidon.webserver.http.HttpFeature; |
10 | 9 |
|
11 | 10 | /** Plugin for avaje inject that provides a default Validator Handler */ |
12 | | -@ServiceProvider |
13 | 11 | @PluginProvides( |
14 | 12 | providesStrings = { |
15 | 13 | "io.helidon.webserver.http.HttpFeature", |
|
18 | 16 | }) |
19 | 17 | public final class HttpValidatorHandler implements InjectPlugin { |
20 | 18 |
|
21 | | - enum Server { |
22 | | - HELIDON("io.helidon.webserver.http.HttpFeature"), |
23 | | - JAVALIN("io.javalin.plugin.Plugin"), |
24 | | - JEX("io.avaje.jex.Routing.HttpService"); |
25 | | - String register; |
26 | | - Server(String register) { |
27 | | - this.register = register; |
28 | | - } |
29 | | - } |
30 | | - |
31 | | - private static final Server type = server(); |
32 | | - |
33 | | - private static Server server() { |
34 | | - for (var register : Server.values()) { |
35 | | - try { |
36 | | - Class.forName(register.register); |
37 | | - return register; |
38 | | - } catch (ClassNotFoundException e) { |
39 | | - // nothing |
40 | | - } |
41 | | - } |
42 | | - return null; |
43 | | - } |
44 | | - |
45 | 19 | @Override |
46 | 20 | public void apply(BeanScopeBuilder builder) { |
47 | | - if (type == null) { |
48 | | - return; |
| 21 | + try { |
| 22 | + builder.provideDefault(HttpFeature.class, HelidonHandler::new); |
| 23 | + } catch (NoClassDefFoundError e) { |
| 24 | + } |
| 25 | + try { |
| 26 | + builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new); |
| 27 | + } catch (NoClassDefFoundError e) { |
49 | 28 | } |
50 | | - switch (type) { |
51 | | - case HELIDON: |
52 | | - builder.provideDefault(HttpFeature.class, HelidonHandler::new); |
53 | | - break; |
54 | | - case JAVALIN: |
55 | | - builder.provideDefault(AvajeJavalinPlugin.class, JavalinHandler::new); |
56 | | - break; |
57 | | - case JEX: |
58 | | - builder.provideDefault(HttpService.class, JexHandler::new); |
59 | | - break; |
| 29 | + try { |
| 30 | + builder.provideDefault(HttpService.class, JexHandler::new); |
| 31 | + } catch (NoClassDefFoundError e) { |
60 | 32 | } |
61 | 33 | } |
62 | 34 | } |
0 commit comments