Revision 61063
Added by Konstantinos Triantafyllou almost 3 years ago
HttpUtils.java | ||
---|---|---|
10 | 10 |
import org.springframework.stereotype.Component; |
11 | 11 |
import org.springframework.web.client.RestTemplate; |
12 | 12 |
|
13 |
import java.io.UnsupportedEncodingException; |
|
14 |
import java.net.URLEncoder; |
|
13 | 15 |
import java.nio.charset.Charset; |
16 |
import java.nio.charset.StandardCharsets; |
|
14 | 17 |
import java.util.Map; |
15 | 18 |
|
16 | 19 |
@Component |
... | ... | |
33 | 36 |
headers.setContentType(MediaType.APPLICATION_JSON); |
34 | 37 |
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers); |
35 | 38 |
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.POST, request, String.class); |
36 |
if(responseEntity.getBody() != null) { |
|
39 |
if (responseEntity.getBody() != null) {
|
|
37 | 40 |
return new JsonParser().parse(responseEntity.getBody()); |
38 | 41 |
} else { |
39 | 42 |
return null; |
... | ... | |
46 | 49 |
headers.setContentType(MediaType.APPLICATION_JSON); |
47 | 50 |
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers); |
48 | 51 |
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.PUT, request, String.class); |
49 |
if(responseEntity.getBody() != null) { |
|
52 |
if (responseEntity.getBody() != null) {
|
|
50 | 53 |
return new JsonParser().parse(responseEntity.getBody()); |
51 | 54 |
} else { |
52 | 55 |
return null; |
... | ... | |
58 | 61 |
String url = issuer + path + ((params != null) ? createParams(params) : null); |
59 | 62 |
ResponseEntity<String> responseEntity = restTemplate.exchange |
60 | 63 |
(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class); |
61 |
if(responseEntity.getBody() != null) { |
|
64 |
if (responseEntity.getBody() != null) {
|
|
62 | 65 |
return new JsonParser().parse(responseEntity.getBody()); |
63 | 66 |
} else { |
64 | 67 |
return null; |
... | ... | |
70 | 73 |
String url = issuer + path; |
71 | 74 |
ResponseEntity<String> responseEntity = restTemplate.exchange |
72 | 75 |
(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class); |
73 |
if(responseEntity.getBody() != null) { |
|
76 |
if (responseEntity.getBody() != null) {
|
|
74 | 77 |
return new JsonParser().parse(responseEntity.getBody()); |
75 | 78 |
} else { |
76 | 79 |
return null; |
... | ... | |
82 | 85 |
StringBuilder ret = new StringBuilder("?"); |
83 | 86 |
int count = 0; |
84 | 87 |
for (Map.Entry<String, String> param : params.entrySet()) { |
85 |
ret.append(param.getKey()).append("=").append(param.getValue()); |
|
88 |
ret.append(param.getKey()).append("="); |
|
89 |
try { |
|
90 |
ret.append(URLEncoder.encode(param.getValue(), StandardCharsets.UTF_8.toString())); |
|
91 |
} catch (UnsupportedEncodingException e) { |
|
92 |
logger.error("UnsupportedEncodingException on param " + param); |
|
93 |
return null; |
|
94 |
} |
|
86 | 95 |
count++; |
87 | 96 |
if (count != params.entrySet().size()) { |
88 | 97 |
ret.append("&"); |
Also available in: Unified diff
[Users | Trunk]: 1. Http utils: Encode params. 2. Registry calls: Add name parameter for getting cous base on a name. 3. Return coudId on role creation