16
16
17
17
package org .glassfish .jersey .server .internal ;
18
18
19
+ import java .net .URI ;
20
+ import java .util .HashMap ;
21
+ import java .util .Map ;
22
+ import java .util .concurrent .CompletableFuture ;
23
+ import java .util .concurrent .CompletionStage ;
24
+ import java .util .function .BiFunction ;
25
+ import java .util .function .Consumer ;
26
+
27
+ import javax .ws .rs .JAXRS ;
19
28
import javax .ws .rs .core .Application ;
29
+ import javax .ws .rs .core .UriBuilder ;
20
30
21
31
import org .glassfish .jersey .internal .AbstractRuntimeDelegate ;
22
32
import org .glassfish .jersey .message .internal .MessagingBinders ;
23
33
import org .glassfish .jersey .server .ContainerFactory ;
34
+ import org .glassfish .jersey .server .ResourceConfig ;
35
+ import org .glassfish .jersey .server .ServerProperties ;
24
36
25
37
/**
26
38
* Server-side implementation of JAX-RS {@link javax.ws.rs.ext.RuntimeDelegate}.
@@ -46,4 +58,61 @@ public <T> T createEndpoint(Application application, Class<T> endpointType)
46
58
}
47
59
return ContainerFactory .createContainer (endpointType , application );
48
60
}
61
+
62
+ @ Override
63
+ public JAXRS .Configuration .Builder createConfigurationBuilder () {
64
+ return new JAXRS .Configuration .Builder () {
65
+ private final Map <String , Object > properties = new HashMap <>();
66
+
67
+ {
68
+ this .properties .put (JAXRS .Configuration .PROTOCOL , "HTTP" );
69
+ this .properties .put (JAXRS .Configuration .HOST , "localhost" );
70
+ this .properties .put (JAXRS .Configuration .PORT , 80 );
71
+ this .properties .put (JAXRS .Configuration .ROOT_PATH , "/" );
72
+ }
73
+
74
+ @ Override
75
+ public final JAXRS .Configuration .Builder property (final String name , final Object value ) {
76
+ this .properties .put (name , value );
77
+ return this ;
78
+ }
79
+
80
+ @ Override
81
+ public final JAXRS .Configuration build () {
82
+ return new JAXRS .Configuration () {
83
+ @ Override
84
+ public final Object getProperty (final String name ) {
85
+ return properties .get (name );
86
+ }
87
+ };
88
+ }
89
+ };
90
+ }
91
+
92
+ @ SuppressWarnings ("unchecked" )
93
+ @ Override
94
+ public CompletionStage <JAXRS .Instance > bootstrap (final Application application , final JAXRS .Configuration configuration ) {
95
+ return CompletableFuture .supplyAsync (() -> {
96
+ final String protocol = (String ) configuration .getProperty (JAXRS .Configuration .PROTOCOL );
97
+ final String host = (String ) configuration .getProperty (JAXRS .Configuration .HOST );
98
+ final int port = (int ) configuration .getProperty (JAXRS .Configuration .PORT );
99
+ final String rootPath = (String ) configuration .getProperty (JAXRS .Configuration .ROOT_PATH );
100
+ final BiFunction <URI , ResourceConfig , ?> httpServerProvider = (BiFunction <URI , ResourceConfig , ?>) configuration
101
+ .getProperty (ServerProperties .HTTP_SERVER_PROVIDER );
102
+ final Consumer <Object > httpServerAnnihilator = (Consumer <Object >) configuration
103
+ .getProperty (ServerProperties .HTTP_SERVER_ANNIHILATOR );
104
+
105
+ final URI uri = UriBuilder .fromUri (protocol .toLowerCase () + "://" + host ).port (port ).path (rootPath ).build ();
106
+ final ResourceConfig rc = ResourceConfig .forApplication (application );
107
+ final Object httpServer = httpServerProvider .apply (uri , rc );
108
+
109
+ return new JAXRS .Instance () {
110
+ @ Override
111
+ public final CompletionStage <Void > stop () {
112
+ return CompletableFuture .runAsync (() -> httpServerAnnihilator .accept (httpServer ));
113
+ }
114
+ };
115
+ });
116
+ }
117
+
49
118
}
0 commit comments