File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
src/test/java/com/devcycle/sdk/server/helpers Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .devcycle .sdk .server .helpers ;
2+
3+ import com .sun .net .httpserver .HttpExchange ;
4+ import com .sun .net .httpserver .HttpServer ;
5+
6+ import java .io .*;
7+ import java .net .InetSocketAddress ;
8+
9+ public class LocalConfigServer {
10+ private HttpServer server ;
11+ private String configData = "" ;
12+ public LocalConfigServer (String configData ) throws IOException {
13+ this .configData = configData ;
14+ InetSocketAddress address = new InetSocketAddress (8000 );
15+ server = HttpServer .create (address , 0 );
16+ server .createContext ("/" , this ::handleConfigRequest );
17+ server .setExecutor (null ); // use the default executor
18+ System .out .println ("Starting config server on " + address );
19+ }
20+
21+ public void handleConfigRequest (HttpExchange exchange ) throws IOException {
22+ exchange .sendResponseHeaders (200 , configData .length ());
23+ OutputStream outputStream = exchange .getResponseBody ();
24+ outputStream .write (configData .getBytes ());
25+ outputStream .flush ();
26+ outputStream .close ();
27+ }
28+
29+ public void setConfigData (String configData ) {
30+ this .configData = configData ;
31+ }
32+
33+ public void start () {
34+ this .server .start ();
35+ }
36+
37+ public void stop () {
38+ this .server .stop (0 );
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments