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; |
35 |
|
|
36 |
|
import info.magnolia.rest.client.call.AbstractRestCall; |
37 |
|
|
38 |
|
import javax.ws.rs.WebApplicationException; |
39 |
|
import javax.ws.rs.client.WebTarget; |
40 |
|
|
41 |
|
import org.slf4j.Logger; |
42 |
|
import org.slf4j.LoggerFactory; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.5 |
|
49 |
|
public class DefaultRestClient<E extends Throwable> implements RestClient<E> { |
50 |
|
|
51 |
|
private static final Logger log = LoggerFactory.getLogger(DefaultRestClient.class); |
52 |
|
|
53 |
|
private RestClientDefinition restClientDefinition; |
54 |
|
private WebTarget target; |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
0 |
public DefaultRestClient(WebTarget target, RestClientDefinition restClientDefinition) {... |
57 |
0 |
this.target = target; |
58 |
0 |
this.restClientDefinition = restClientDefinition; |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
61 |
0 |
@Override... |
62 |
|
public <T> T invoke(AbstractRestCall<T> restCall) throws E { |
63 |
0 |
try { |
64 |
0 |
return restCall.doCall(target); |
65 |
|
} catch (WebApplicationException e) { |
66 |
0 |
return handleRestException(restCall, e); |
67 |
|
} |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
70 |
0 |
@Override... |
71 |
|
public <T> T invoke(String restCallName) throws E { |
72 |
0 |
if (getRestClientDefinition().getRestCalls().containsKey(restCallName)) { |
73 |
0 |
AbstractRestCall<?> restCall = getRestClientDefinition().getRestCalls().get(restCallName); |
74 |
0 |
return (T) invoke(restCall); |
75 |
|
} |
76 |
0 |
log.warn("Unknown rest call with name " + restCallName + "."); |
77 |
0 |
return null; |
78 |
|
} |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
80 |
0 |
@Override... |
81 |
|
public <T> T handleRestException(AbstractRestCall<T> restCall, WebApplicationException e) throws E { |
82 |
0 |
log.error("Error while issuing a rest call: Status code: " + e.getResponse().getStatus() + ", Response: " + e.getResponse().readEntity(String.class)); |
83 |
0 |
return null; |
84 |
|
} |
85 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
86 |
|
@Override... |
87 |
|
public RestClientDefinition getRestClientDefinition() { |
88 |
|
return restClientDefinition; |
89 |
|
} |
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
91 |
|
public void setRestClientDefinition(RestClientDefinition restClientDefinition) {... |
92 |
|
this.restClientDefinition = restClientDefinition; |
93 |
|
} |
94 |
|
} |