|
30 | 30 |
|
31 | 31 | import org.springframework.cloud.dataflow.core.ApplicationType;
|
32 | 32 | import org.springframework.cloud.dataflow.core.StreamRuntimePropertyKeys;
|
| 33 | +import org.springframework.cloud.dataflow.rest.client.DataFlowClientException; |
33 | 34 | import org.springframework.cloud.dataflow.rest.client.DataFlowTemplate;
|
34 | 35 | import org.springframework.cloud.dataflow.rest.resource.AppInstanceStatusResource;
|
35 | 36 | import org.springframework.cloud.dataflow.rest.resource.AppStatusResource;
|
|
40 | 41 | import org.springframework.http.HttpHeaders;
|
41 | 42 | import org.springframework.http.HttpMethod;
|
42 | 43 | import org.springframework.http.MediaType;
|
| 44 | +import org.springframework.http.ResponseEntity; |
43 | 45 | import org.springframework.util.Assert;
|
44 | 46 | import org.springframework.util.CollectionUtils;
|
45 | 47 | import org.springframework.util.StringUtils;
|
@@ -278,7 +280,10 @@ public void httpPostJson(String streamName, String appName, Object obj) throws J
|
278 | 280 |
|
279 | 281 |
|
280 | 282 | public void httpPost(String url, String message) {
|
281 |
| - dataFlowTemplate.getRestTemplate().postForObject(url, message, String.class); |
| 283 | + ResponseEntity<String> response = dataFlowTemplate.getRestTemplate().postForEntity(url, message, String.class); |
| 284 | + if(!response.getStatusCode().is2xxSuccessful()) { |
| 285 | + throw new RuntimeException("Exception posting:" + response.getStatusCode()+":" + response.getBody()); |
| 286 | + } |
282 | 287 | }
|
283 | 288 |
|
284 | 289 | public void httpPost(String streamName, String appName, byte[] message, HttpHeaders headers) {
|
@@ -319,11 +324,22 @@ public void httpPost(String streamName, String appName, byte[] message, HttpHead
|
319 | 324 | String url = instance.getAttributes().get("url");
|
320 | 325 | if(StringUtils.hasText(url)) {
|
321 | 326 | HttpEntity<byte[]> httpEntity = new HttpEntity<>(message, headers);
|
322 |
| - this.dataFlowTemplate.getRestTemplate().exchange(url, HttpMethod.POST, httpEntity, String.class); |
| 327 | + ResponseEntity<String> response = this.dataFlowTemplate.getRestTemplate().exchange(url, HttpMethod.POST, httpEntity, String.class); |
| 328 | + if(!response.getStatusCode().is2xxSuccessful()) { |
| 329 | + throw new RuntimeException("POST:exception:" + response.getStatusCode() + ":" + response.getBody()); |
| 330 | + } |
323 | 331 | } else {
|
324 | 332 | throw new RuntimeException("Cannot find url for " + streamName + ":" + appName);
|
325 | 333 | }
|
326 |
| - } |
| 334 | + } else { |
| 335 | + if(x instanceof DataFlowClientException) { |
| 336 | + throw (DataFlowClientException) x; |
| 337 | + } else if(x instanceof RuntimeException) { |
| 338 | + throw (RuntimeException) x; |
| 339 | + } else { |
| 340 | + throw new RuntimeException(x.getMessage(), x); |
| 341 | + } |
| 342 | + } |
327 | 343 | }
|
328 | 344 | }
|
329 | 345 |
|
|
0 commit comments