-
Notifications
You must be signed in to change notification settings - Fork 37
/
PingsResource.java
75 lines (67 loc) · 2.27 KB
/
PingsResource.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
*/
package com.airhacks.ping.boundary;
import java.util.Map;
import java.util.Properties;
import static java.util.stream.Collectors.toMap;
import javax.json.Json;
import static javax.json.Json.createValue;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
import javax.json.stream.JsonCollectors;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
*
* @author adam-bien.com
*/
@Path("pings")
@Produces(MediaType.APPLICATION_JSON)
public class PingsResource {
@GET
@Path("/echo/{echo}")
public String echo(@PathParam("echo") String param) {
return param;
}
@GET
@Path("/system-properties")
public JsonObject systemProperties() {
Properties properties = System.getProperties();
Map<String, JsonValue> map = properties.entrySet().
stream().
collect(toMap(k -> k.toString(), v -> createValue(v.getValue().toString())));
return map.entrySet().stream().collect(JsonCollectors.toJsonObject());
}
@GET
@Path("/environment-variables")
public JsonObject environmentVariables() {
Map<String, JsonValue> environment
= System.getenv().
entrySet().
stream().
collect(toMap(Map.Entry::getKey, v -> createValue(v.getValue())));
return environment.entrySet().stream().collect(JsonCollectors.toJsonObject());
}
@GET
@Path("/jndi/{namespace}")
public JsonObject jndi(@PathParam("namespace") String namespace) throws NamingException {
JsonObjectBuilder builder = Json.createObjectBuilder();
InitialContext c = new InitialContext();
NamingEnumeration<NameClassPair> list = c.list(namespace);
while (list.hasMoreElements()) {
NameClassPair nameClassPair = list.nextElement();
String name = nameClassPair.getName();
String type = nameClassPair.getClassName();
builder.add(name, type);
}
return builder.build();
}
}