-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerLauncher.java
More file actions
56 lines (48 loc) · 1.98 KB
/
Copy pathServerLauncher.java
File metadata and controls
56 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.retailsvc.http.start;
import com.retailsvc.http.Handlers;
import com.retailsvc.http.OpenApiServer;
import com.retailsvc.http.RequestHandler;
import com.retailsvc.http.Response;
import com.retailsvc.http.spec.Spec;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
public class ServerLauncher {
private static final Logger LOG = LoggerFactory.getLogger(ServerLauncher.class);
static void main() throws Exception {
new ServerLauncher();
}
public ServerLauncher() throws IOException {
long t0 = System.currentTimeMillis();
Map<String, Object> raw;
try (InputStream in = ServerLauncher.class.getResourceAsStream("/openapi.yaml")) {
raw = new Yaml().load(in);
}
Spec spec = Spec.from(raw);
Map<String, RequestHandler> handlers = new HashMap<>();
handlers.put("get-data", new GetDataHandler());
handlers.put("post-data", new PostDataHandler());
handlers.put("post-list-objects", new PostListObjectsHandler());
handlers.put("query-params", new ParamHandler());
handlers.put("path-params", new ParamHandler());
handlers.put("path-params-multi", new ParamHandler());
handlers.put("secureApiKey", req -> Response.status(200));
handlers.put("secureBearer", req -> Response.status(200));
handlers.put("secureBasic", req -> Response.status(200));
handlers.put("secureOpen", req -> Response.status(200));
OpenApiServer.builder()
.spec(spec)
.handlers(handlers)
.responseDecorator(Handlers.securityHeadersDecorator())
.securityValidator("apiKeyAuth", (req, cred) -> Optional.empty())
.securityValidator("bearerAuth", (req, cred) -> Optional.empty())
.securityValidator("basicAuth", (req, cred) -> Optional.empty())
.build();
LOG.info("Application started in {}ms", System.currentTimeMillis() - t0);
}
}