解决——》feign文件下载时报错feign.codec.EncodeException: not in non blocking mode

74 篇文章 6 订阅
19 篇文章 1 订阅

推荐链接:
    总结——》【Java】
    总结——》【Mysql】
    总结——》【Spring】
    总结——》【SpringBoot】
    总结——》【MyBatis、MyBatis-Plus】

解决——》feign文件下载时报错feign.codec.EncodeException: not in non blocking mode

1、操作

feign文件下载

2、现象

报异常feign.codec.EncodeException: not in non blocking mode

2022-11-10 09:30:05.200 ERROR [10.122.143.9] [http-nio-8882-exec-2] [house-platform-api-0a7a8f09-463345-253] com.eju.houseparent.config.starter.BaseControllerHandler.handleException [line=143 ] : handleException ex uri:/tmall/cityopen/syncEsfCommunity/logList/downloadError/1667895255597,param:{}
2022-11-10 09:30:05.200 ERROR [10.122.143.9] [http-nio-8882-exec-2] [house-platform-api-0a7a8f09-463345-253] com.eju.houseparent.config.starter.BaseControllerHandler.handleException [line=144 ] : handleException ex class:class feign.codec.EncodeException,ex:not in non blocking mode.
2022-11-10 09:30:05.201 ERROR [10.122.143.9] [http-nio-8882-exec-2] [house-platform-api-0a7a8f09-463345-253] com.eju.houseparent.config.starter.BaseControllerHandler.handleException [line=145 ] : 系统正在维护中,请稍候再试
feign.codec.EncodeException: not in non blocking mode.
        at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:384)
        at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232)
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:84)
        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100)
        at com.sun.proxy.$Proxy305.downloadErrorLogListByBatchNo(Unknown Source)
        at com.ejudata.platform.controller.TmallCityOpenController.downloadErrorLogListByBatchNo$original$DkyYi2Ll(TmallCityOpenController.java:70)
        at com.ejudata.platform.controller.TmallCityOpenController.downloadErrorLogListByBatchNo$original$DkyYi2Ll$accessor$nvaSjmiZ(TmallCityOpenController.java)
        at com.ejudata.platform.controller.TmallCityOpenController$auxiliary$m4Yk46Iz.call(Unknown Source)
        at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
        at com.ejudata.platform.controller.TmallCityOpenController.downloadErrorLogListByBatchNo(TmallCityOpenController.java)

3、原因

服务消费者,需要设置方法返回值为Response

4、解决

将服务提供者的文件下载响应的响应体(文件内容)复制到服务消费者对外的文件下载响应体中

@FeignClient(value = "${feign.client.config.good-house-push.name}", url = "${feign.client.config.good-house-push.url}", path = "${feign.client.inner.path}", configuration = CatFeignConfiguration.class)
public interface ITmallSyncEsfCommunityApi{

    @ApiOperation("根据批次号,下载同步二手房小区的错误日志列表")
    @GetMapping({"/api/tmall/syncEsfCommunity/logList/downloadError/{batchNo}"})
    Response downloadErrorLogListByBatchNo(@PathVariable(name = "batchNo") String batchNo);
}

    @ApiOperation(value = "根据批次号,下载同步二手房小区的错误日志列表")
    @GetMapping("/cityopen/syncEsfCommunity/logList/downloadError/{batchNo}")
    void downloadErrorLogListByBatchNo(@PathVariable(name = "batchNo") String batchNo, HttpServletResponse response) {

        InputStream inputStream = null;
        try {
            Response serviceResponse = tmallSyncEsfCommunityApi.downloadErrorLogListByBatchNo(batchNo);
            Response.Body body = serviceResponse.body();
            inputStream = body.asInputStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + batchNo + ".xlsx");
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
            int length = 0;
            byte[] temp = new byte[1024 * 10];
            while ((length = bufferedInputStream.read(temp)) != -1) {
                bufferedOutputStream.write(temp, 0, length);
            }
            bufferedOutputStream.flush();
            bufferedOutputStream.close();
            bufferedInputStream.close();
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值