Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用外国客户机实现下载文件_Java_Spring_Spring Cloud_Spring Cloud Feign - Fatal编程技术网

Java 如何使用外国客户机实现下载文件

Java 如何使用外国客户机实现下载文件,java,spring,spring-cloud,spring-cloud-feign,Java,Spring,Spring Cloud,Spring Cloud Feign,我有一个下载文件的url。url的签名是希望使用假客户端代理它。每次我收到一个异常,告诉我的输出流已关闭 2018年11月2日星期五16:18:47 出现意外错误(类型=内部服务器错误,状态=500)。 无法写入JSON:getOutputStream()已为此响应调用;嵌套异常为com.fasterxml.jackson.databind.JsonMappingException:getOutputStream()已为此响应调用(通过引用链:org.springframework.securi

我有一个下载文件的url。url的签名是希望使用假客户端代理它。每次我收到一个异常,告诉我的输出流已关闭

2018年11月2日星期五16:18:47 出现意外错误(类型=内部服务器错误,状态=500)。 无法写入JSON:getOutputStream()已为此响应调用;嵌套异常为com.fasterxml.jackson.databind.JsonMappingException:getOutputStream()已为此响应调用(通过引用链:org.springframework.security.web.firewall.FirewalledResponse[“response”]->org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterResponse[“response”]->org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper[“response”]->org.springframework.security.web.firewall.FirewalledResponse[“response”]->org.apache.catalina.connector.ResponseFacade[“writer”])

我的假客户很简单

 @FeignClient(name = "downloadAPI", url = "${service.ip}")
public interface DownloadApiProxy {

    @RequestMapping(method = RequestMethod.GET, value = "/downloadFile")
    public void downloadFile(HttpServletResponse response,
            @RequestParam(value = "downloadMessageId", required = false) String messageId);

我遇到了同样的问题,我想从一个微服务调用API到另一个微服务,所以我映射了返回
byte[]
的API

因此,您的代码应该如下所示:

@FeignClient(name = "downloadAPI", url = "${service.ip}")
public interface DownloadApiProxy {

    @RequestMapping(method = RequestMethod.GET, value = "/downloadFile")
    public byte[] downloadFile(HttpServletResponse response, @RequestParam(value = "messageId", required = false) String messageId);

     :
     :
}
它将以
字节[]
的形式返回下载的文件

注:您的查询参数将是“代码> MeasGeID 作为给定的示例。