Tried to upload a file via Rest request using MultiPartFile. Getting the request in the controller in App A, which calls service, which then calls FeignClient to invoke different REST endpoint in App B.
Controller class
@RestController("strategy")
@Validated
public class StrategyController {
private final StrategyService strategyService;
public StrategyController(StrategyService strategyService) {
this.strategyService = strategyService;
}
@RequestMapping(path = ASSORT_STRAT_UPLOAD_REQUEST, method = RequestMethod.POST)
public ResponseEntity<String> upload(MultipartFile file) {
return ResponseEntity.ok(strategyService.upload(file));
}
Service class
@Service
public class StrategyServiceImpl implements StrategyService {
private final strategyServiceRestClient strategyServiceRestClient;
public StrategyServiceImpl(strategyServiceRestClient strategyServiceRestClient) {
this.strategyServiceRestClient = strategyServiceRestClient;
}
@Override
public String upload(MultipartFile file) {
return strategyServiceRestClient.uploadRequest(file);
}
}
Feign Client
@FeignClient(value = "strategy", url = "${strategy-service-url}", configuration = StrategyServiceFeignConfig.class)
public interface StrategyServiceRestClient {
@RequestMapping(method = RequestMethod.POST, value = KimsBffConstants.ASSORT_STRAT_UPLOAD_REQUEST)
@HandleFeignException(HandleFeignClientException.class)
String uploadRequest(@RequestPart MultipartFile file);
}
Seeing the following exception when it calls strategyServiceRestClient.uploadRequest(file);
Caused by:
java.io.FileNotFoundException: MultipartFile resource [file] cannot be resolved to URL
at org.springframework.core.io.AbstractResource.getURL(AbstractResource.java:113)
at org.springframework.core.io.AbstractResource.getURI(AbstractResource.java:123)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:869)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:760)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1514)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1007)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:456)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104)
at org.springframework.cloud.openfeign.support.SpringEncoder.checkAndWrite(SpringEncoder.java:217)
at org.springframework.cloud.openfeign.support.SpringEncoder.encodeWithMessageConverter(SpringEncoder.java:146)
