Java 如何使用外国客户机实现下载文件
我有一个下载文件的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”]) 我的假客户很简单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
@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 作为给定的示例。