OpenFeign下载流

OpenFeign下载文件流(调用OpenFeign接口不能携带HttpServeltRequest和HttpServeletContext参数)

   服务调用方:
       @GetMapping(value="download")
    public void download(HttpServletResponse httpServletResponse) throws IOException {
           Response response =  fileService.download();
           feignResp2ServletResp(response,httpServletResponse);
    }

    public static void feignResp2ServletResp(Response feignResponse, HttpServletResponse response) {
        Response.Body body = feignResponse.body();
        try (InputStream inputStream = body.asInputStream(); OutputStream outputStream = response.getOutputStream())
        {
            response.setHeader(HttpHeaders.CONTENT_DISPOSITION, feignResponse.headers().get(HttpHeaders.CONTENT_DISPOSITION).stream().findFirst().get());
            response.setContentType(feignResponse.headers().get(HttpHeaders.CONTENT_TYPE).stream().findFirst().get());
            IOUtils.copy(inputStream, outputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

2. OpenFeign接口
   @GetMapping(value="download")
    Response download() throws IOException;
3. 服务提供者:
     @GetMapping(value = "download")
    public void download(HttpServletResponse response) {    

你可能感兴趣的:(java,前端,javascript)