@@ -34,32 +34,34 @@ public class TestService {
34
34
"tags" ,
35
35
"filtering" ,
36
36
"migrations" ,
37
- "event-sampling"
37
+ "event-sampling" ,
38
+ "inline-context" ,
39
+ "anonymous-redaction"
38
40
};
39
-
41
+
40
42
static final Gson gson = new GsonBuilder ().serializeNulls ().create ();
41
43
42
44
static final OkHttpClient client = new OkHttpClient ();
43
-
45
+
44
46
private final Map <String , SdkClientEntity > clients = new ConcurrentHashMap <String , SdkClientEntity >();
45
47
private final AtomicInteger clientCounter = new AtomicInteger (0 );
46
48
private final String clientVersion ;
47
-
49
+
48
50
private TestService () {
49
51
LDClient dummyClient = new LDClient ("" , new LDConfig .Builder ().offline (true ).build ());
50
52
clientVersion = dummyClient .version ();
51
53
try {
52
54
dummyClient .close ();
53
55
} catch (Exception e ) {}
54
56
}
55
-
57
+
56
58
@ SuppressWarnings ("serial" )
57
59
public static class BadRequestException extends Exception {
58
60
public BadRequestException (String message ) {
59
61
super (message );
60
62
}
61
63
}
62
-
64
+
63
65
public static void main (String [] args ) throws Exception {
64
66
TestService service = new TestService ();
65
67
@@ -70,7 +72,7 @@ public static void main(String[] args) throws Exception {
70
72
.addRegex ("POST" , Pattern .compile ("/clients/(.*)" ), ctx -> service .postClientCommand (diableKeepAlive (ctx )))
71
73
.addRegex ("DELETE" , Pattern .compile ("/clients/(.*)" ), ctx -> service .deleteClient (diableKeepAlive (ctx )));
72
74
73
- HttpServer server = HttpServer .start (PORT , router );
75
+ HttpServer server = HttpServer .start (PORT , router );
74
76
server .getRecorder ().setEnabled (false ); // don't accumulate a request log
75
77
76
78
System .out .println ("Listening on port " + PORT );
@@ -97,21 +99,21 @@ private void forceQuit() {
97
99
System .out .println ("Test harness has told us to quit" );
98
100
System .exit (0 );
99
101
}
100
-
102
+
101
103
private void postCreateClient (RequestContext ctx ) {
102
104
CreateInstanceParams params = readJson (ctx , CreateInstanceParams .class );
103
105
104
106
String clientId = String .valueOf (clientCounter .incrementAndGet ());
105
107
SdkClientEntity client = new SdkClientEntity (this , params );
106
108
107
109
clients .put (clientId , client );
108
-
110
+
109
111
ctx .addHeader ("Location" , "/clients/" + clientId );
110
112
}
111
113
112
114
private void postClientCommand (RequestContext ctx ) {
113
115
CommandParams params = readJson (ctx , CommandParams .class );
114
-
116
+
115
117
String clientId = ctx .getPathParam (0 );
116
118
SdkClientEntity client = clients .get (clientId );
117
119
if (client == null ) {
@@ -131,9 +133,9 @@ private void postClientCommand(RequestContext ctx) {
131
133
client .logger .error ("Unexpected exception: {}" , e );
132
134
ctx .setStatus (500 );
133
135
}
134
- }
136
+ }
135
137
}
136
-
138
+
137
139
private void deleteClient (RequestContext ctx ) {
138
140
String clientId = ctx .getPathParam (0 );
139
141
SdkClientEntity client = clients .get (clientId );
@@ -143,11 +145,11 @@ private void deleteClient(RequestContext ctx) {
143
145
client .close ();
144
146
}
145
147
}
146
-
148
+
147
149
private <T > T readJson (RequestContext ctx , Class <T > paramsClass ) {
148
150
return gson .fromJson (ctx .getRequest ().getBody (), paramsClass );
149
151
}
150
-
152
+
151
153
private void writeJson (RequestContext ctx , Object data ) {
152
154
String json = gson .toJson (data );
153
155
Handlers .bodyJson (json ).apply (ctx );
0 commit comments