forked from GJWT/javaOIDCMsg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponse.java
More file actions
109 lines (92 loc) · 3.52 KB
/
Response.java
File metadata and controls
109 lines (92 loc) · 3.52 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package oiccli.HTTP;
import com.auth0.jwt.creators.Message;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class Response {
private static final List<Integer> successfulCodes =
Arrays.asList(200, 201, 202, 203, 204, 205, 206);
private static Map<String, String> corsHeaders = new
HashMap<String, String>() {{
put("Access-Control-Allow-Origin", "*");
put("Access-Control-Allow-Methods", "GET");
put("Access-Control-Allow-Headers", "Authorization");
}};
private String status = "200 OK";
private String contentType = "text/html";
private Object template;
private Object makoTemplate;
private Object makoLookup;
private Message message;
private List<Map<String, String>> headers;
public Response(Message message, Map<String, Object> args) {
this.status = args.get("status");
this.response = args.get("response");
this.template = args.get("template");
this.makoTemplate = args.get("makoTemplate");
this.makoLookup = args.get("templateLookup");
this.message = message;
this.headers = new ArrayList<>();
this.headers.add(args.get("headers"), new List<>());
this.contentType = args.get("content");
}
private List<String> getResponse(String message, Map<String, String> args) {
if (!Strings.isNullOrEmpty(message)) {
if (message.contains("<script>")) {
message = message.replace("<script>", "<script>").replace(
"</script>", "</script>");
}
}
if (this.template != null) {
for (Map<String, String> hMap : headers) {
if ("application/json".equals(hMap.get("Content-type"))) {
return Arrays.asList(message);
} else {
//return [str(self.template % message).encode("utf-8")]
}
}
} else if (this.makoLookup != null && this.makoTemplate != null) {
args.put("message", message);
Object mte = this.makoLookup.getTemplate(this.makoTemplate);
return Arrays.asList(mte.render(args));
} else {
for (String type : this._c_types()) {
if (type.startsWith("image/") || type.equals("application/x-gzip")) {
return Arrays.asList(message);
}
}
}
}
public Map<String, Object> info() {
Map<String, Object> hMap = new HashMap<String, Object>() {{
put("status", this.status);
put("headers", this.headers);
put("message", this.message);
}};
return hMap;
}
public void addHeader(Map<String, String> value) {
this.headers.add(value);
}
public Response reply(Map<String, String> args) {
return this.response(message, args);
}
public List<String> cTypes() {
List<String> cTypes = new ArrayList<>();
Iterator it;
Map.Entry pair;
for (Map<String, String> index : this.headers) {
it = index.entrySet().iterator();
while (it.hasNext()) {
pair = (Map.Entry) it.next();
if (((String) pair.getKey()).equals("Content-type")) {
cTypes.add((String) pair.getValue());
}
}
}
}
}