我有一个下载文件的网址。 url的签名是http://services.local/api/v1/downloadFile?messageId=11090.I想要使用伪客户端进行代理。每次我收到一个异常通知我输出流已关闭。
星期五十一月02 16:18:47 IST 2018
发生意外错误(类型=内部服务器错误,状态= 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);
:
:
}
它将在
byte[]
中返回下载的文件。注意:作为示例,您的查询参数将为
messageId
。关于java - 如何使用伪装客户端实现下载文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53117281/