spring-cloud - DataFlowTemplate 响应不返回正文
问题描述
考虑到 test07 流已经创建,下面的代码片段不会在异常堆栈跟踪中获得响应体。
try {
URI dataFlowUri = URI.create("http://localhost:9393");
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri);
StreamDefinition streamDefinition = Stream.builder(dataFlowOperations)
.name("test07")
.definition("time|log")
.create();
}
catch (Exception ex){
ex.printStackTrace();
}
org.springframework.web.client.HttpClientErrorException$Conflict: 409 : [no body] at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:125) at org.springframework.web.client.DefaultResponseErrorHandler.handleError( DefaultResponseErrorHandler.java:184) at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:125) at org.springframework.cloud.dataflow.rest.client.VndErrorResponseErrorHandler.handleError(VndErrorResponseErrorHandler.java:62) at org org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate .java:740) 在 org.springframework.web.client.RestTemplate。在 org.springframework.cloud.dataflow.rest.client.StreamTemplate.createStream(StreamTemplate.java:121) 的 org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:418) 执行(RestTemplate.java:674)在 org.springframework.cloud.dataflow.rest.client.dsl.StreamDefinition.(StreamDefinition.java:60) 在 org.springframework.cloud.dataflow.rest.client.dsl.Stream$StreamDefinitionBuilder.create(Stream.java:400 )
另一方面,当 Post 直接请求时
http://localhost:9393/streams/definitions?name=test07&definition=time%20%7C%20log&description=test07
响应如下,状态码为 409
[ { "logref": "DuplicateStreamDefinitionException", "message": "无法创建流 test07,因为已经创建了另一个同名流" } ]
我想在发生异常时获得响应正文,
这样如果我在这里遗漏了什么,任何人都可以提供帮助?
解决方案
我必须覆盖默认的休息模板才能根据需要获取响应正文。
ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
RestTemplate restTemplate = new RestTemplate(factory);
URI dataFlowUri = URI.create("http://localhost:9393");
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri, restTemplate);
StreamDefinition streamDefinition = Stream.builder(dataFlowOperations)
.name("test07")
.definition("time|log")
.create();
谢谢
推荐阅读
- html - Css 网格,对齐内容:结束,在我的代码中不起作用
- qt - QTimer:定时器回调可以重叠执行吗?
- netflix-zuul - 如果请求正文小于 Content-Length 标头中指定的大小并使用 tomcat APR 连接器,则可能会发生这种情况
- javascript - Bean 名称“广告”的 BindingResult 和普通目标对象都不能用作请求属性
- java - Sphere-Sphere Intersection,选择正确的 theta
- python - 跳过列表中的空值
- linux - 为什么 for 循环数组在 bash 语言中不起作用?
- javascript - 如何让 Discord 机器人对 Discord 频道中的每条消息做出反应
- arrays - 如果满足条件visual basic,我将如何更改数组元素的颜色
- python - 身份验证失败在 /oauth/complete/github/ Django 中的社交登录错误