Spring Cloud Feign接口返回流的实现
作者:java干货 时间:2021-06-07 07:21:54
服务提供者
@GetMapping("/{id}")
public void queryJobInfoLogDetail(@PathVariable("id") Long id, HttpServletResponse response) {
File file = new File("xxxxx");
InputStream fileInputStream = new FileInputStream(file);
OutputStream outStream;
try {
outStream = response.getOutputStream();
byte[] bytes = new byte[1024];
int len = 0;
while ((len = fileInputStream.read(bytes)) != -1) {
outStream.write(bytes, 0, len);
}
fileInputStream.close();
outStream.close();
outStream.flush();
} catch (IOException e) {
log.error("exception", e);
}
}
client 客户端
@GetMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
feign.Response queryJobInfoLogDetail(@PathVariable("id") Long id);
服务消费者
@GetMapping("/{id}")
public void queryJobInfoLogInfoList(@PathVariable("id") Long id, HttpServletResponse servletResponse) {
Response response = apiServices.queryJobInfoLogDetail(id);
Response.Body body = response.body();
InputStream fileInputStream = null;
OutputStream outStream;
try {
fileInputStream = body.asInputStream();
outStream = servletResponse.getOutputStream();
byte[] bytes = new byte[1024];
int len = 0;
while ((len = fileInputStream.read(bytes)) != -1) {
outStream.write(bytes, 0, len);
}
fileInputStream.close();
outStream.close();
outStream.flush();
} catch (Exception e) {
}
}
来源:https://segmentfault.com/a/1190000020665350
标签:Spring,Cloud,Feign,接口
0
投稿
猜你喜欢
C#版Tesseract库的使用技巧
2023-01-24 20:07:53
利用adt-bundle轻松搭建Android开发环境与Hello world(Windows)
2022-09-05 14:35:18
深入探讨JAVA中的异常与错误处理
2023-06-11 00:30:24
Flutter Android多窗口方案落地实战
2023-01-30 04:55:07
从Cocos2d-x2迁移到Cocos2d-x3的过程分享
2021-06-07 23:52:28
Android开发中的简单设置技巧集锦
2021-10-10 04:40:35
easyexcel读取excel合并单元格数据的操作代码
2022-08-26 16:26:21
AndroidStudio 3.6 中 R.layout 找不到对应的xml文件问题及解决方法
2023-05-19 08:22:02
Java并发编程之volatile与JMM多线程内存模型
2023-10-19 12:13:48
Spring jackson原理及基本使用方法详解
2021-10-03 08:28:18
替换so文件来动态替换Flutter代码实现详解
2023-06-23 16:24:06
Java枚举类型enum的详解及使用
2023-08-02 14:23:57
Java设计模式之享元模式实例详解
2021-12-19 17:54:00
Java 继承与多态的深入理解
2023-10-05 04:25:41
Echarts+SpringMvc显示后台实时数据
2021-06-08 03:38:42
Java 异步编程实践_动力节点Java学院整理
2023-06-18 17:04:12
Spring Boot启动过程完全解析(二)
2022-06-17 14:40:59
SpringCloud实战之Feign声明式服务调用
2022-07-02 08:25:30
Spring RabbitMQ死信机制原理实例详解
2022-04-29 18:52:18
Kotlin封装RecyclerView Adapter实例教程
2023-11-06 01:54:23