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 |
|
package info.magnolia.rest.client.call; |
35 |
|
|
36 |
|
import java.util.HashMap; |
37 |
|
import java.util.Map; |
38 |
|
|
39 |
|
import javax.ws.rs.client.Invocation; |
40 |
|
import javax.ws.rs.client.WebTarget; |
41 |
|
|
42 |
|
import org.apache.commons.lang3.StringUtils; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.1 |
|
49 |
|
public abstract class AbstractRestCall<T> { |
50 |
|
|
51 |
|
private String path; |
52 |
|
private Class<T> entityClass; |
53 |
|
private Map<String, String> queryParams = new HashMap<String, String>(); |
54 |
|
private Map<String, String> cookies = new HashMap<String, String>(); |
55 |
|
private Map<String, Object> headers = new HashMap<String, Object>(); |
56 |
|
private Map<String, Object> templateValues = new HashMap<String, Object>(); |
57 |
|
|
58 |
|
public abstract <T> T doCall(WebTarget target); |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
60 |
0 |
protected Invocation.Builder buildCall(WebTarget target) {... |
61 |
0 |
WebTarget webTarget = target.path(getPath()); |
62 |
0 |
for (Map.Entry<String, String> entry: getQueryParams().entrySet()) { |
63 |
0 |
webTarget = webTarget.queryParam(entry.getKey(), StringUtils.split(entry.getValue(), ", ")); |
64 |
|
} |
65 |
0 |
webTarget = webTarget.resolveTemplates(getTemplateValues()); |
66 |
0 |
Invocation.Builder builder = webTarget.request(); |
67 |
0 |
for (Map.Entry<String, Object> entry : getHeaders().entrySet()) { |
68 |
0 |
builder.header(entry.getKey(), entry.getValue()); |
69 |
|
} |
70 |
0 |
for (Map.Entry<String, String> entry : getQueryParams().entrySet()) { |
71 |
0 |
builder.cookie(entry.getKey(), entry.getValue()); |
72 |
|
} |
73 |
0 |
return builder; |
74 |
|
} |
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
76 |
|
public void setPath(String path) {... |
77 |
|
this.path = path; |
78 |
|
} |
79 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
80 |
|
public String getPath() {... |
81 |
|
return path; |
82 |
|
} |
83 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
84 |
|
public void setEntityClass(Class<T> entityClass) {... |
85 |
|
this.entityClass = entityClass; |
86 |
|
} |
87 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
88 |
|
public Class<T> getEntityClass() {... |
89 |
|
return entityClass; |
90 |
|
} |
91 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
92 |
|
public Map<String, String> getQueryParams() {... |
93 |
|
return queryParams; |
94 |
|
} |
95 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
96 |
|
public void setQueryParams(Map<String, String> queryParams) {... |
97 |
|
this.queryParams = queryParams; |
98 |
|
} |
99 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
100 |
|
public Map<String, Object> getHeaders() {... |
101 |
|
return headers; |
102 |
|
} |
103 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
104 |
|
public void setHeaders(Map<String, Object> headers) {... |
105 |
|
this.headers = headers; |
106 |
|
} |
107 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
108 |
|
public Map<String, Object> getTemplateValues() {... |
109 |
|
return templateValues; |
110 |
|
} |
111 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
112 |
|
public void setTemplateValues(Map<String, Object> templateValues) {... |
113 |
|
this.templateValues = templateValues; |
114 |
|
} |
115 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
116 |
|
public Map<String, String> getCookies() {... |
117 |
|
return cookies; |
118 |
|
} |
119 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
120 |
|
public void setCookies(Map<String, String> cookies) {... |
121 |
|
this.cookies = cookies; |
122 |
|
} |
123 |
|
} |