Reputation: 1340
I have a url which downloads a file. The signature of the url is http://services.local/api/v1/downloadFile?messageId=11090.I want to proxy it using feign client.Every time I get a exception telling my output stream is closed.
Fri Nov 02 16:18:47 IST 2018 There was an unexpected error (type=Internal Server Error, status=500). Could not write JSON: getOutputStream() has already been called for this response; nested exception is com.fasterxml.jackson.databind.JsonMappingException: getOutputStream() has already been called for this response (through reference chain: 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"])
My feign client is very simple
@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);
Upvotes: 1
Views: 6916
Reputation: 1260
I got the same problem where I want to make API call from one Microservice to another Microservice so I mapped that API which returning byte[]
.
So your code should be like:
@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);
:
:
}
It will return downloaded file in byte[]
.
Note: Your query parameter will be messageId
as par given example.
Upvotes: 3