javarestswaggereureka-formsfeign

no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data]


I an trying to integrate a file upload service, which is registered with a Eureka discovery infrastructure.

My Service, say /myfile/upload is having below 6 parameters, below is the YML:

/myfile/upload:
      put:
         operationId: "uploadUsingPUT"
         consumes:
         - "multipart/form-data"
         produces:
         - "*/*"
         parameters:
         - name: "file"
           in: "formData"
           required: true
           type: "file"
         - name: "filename"
           in: "formData"
           required: true
           type: "string"
         - name: "path"
           in: "formData"
           required: true
           type: "string"
         - name: "header1"
           in: "header"
           required: true
           type: "string"
         - name: "header2"
           in: "header"
           required: false
           type: "string"
           allowEmptyValue: true
         responses:
            200:
               description: "OK"
            400:
               description: "Bad Request"

I have created a client interface for this service, below is the API that I created:

import java.io.File;
import java.util.Map;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;

@org.springframework.cloud.netflix.feign.FeignClient(value = "SERVICE-NAME", configuration = {
  com.MyConfiguration.class})
public interface UploadControllerAPINew extends ApiClient.Api {

  @RequestMapping(value = "/myfile/upload",
    method = RequestMethod.PUT,
    produces = "*/*",
    consumes = "multipart/form-data"
  )
  FileUploadResponse uploadUsingPUT(@RequestPart("file") File file,
    @RequestParam("filename") String filename, @RequestParam("path") String path,
    @RequestHeader("header1") String header1,
    @RequestHeader("header2") String header2);


  @RequestMapping(value = "/myfile/upload",
    method = RequestMethod.PUT,
    produces = "*/*",
    consumes = "multipart/form-data"
  )
  FileUploadResponse uploadUsingPUT1(@RequestBody Map<String, ?> formParams,
    @RequestHeader("header1") String header1,
    @RequestHeader("header2") String header2);

  @RequestMapping(value = "/myfile/upload",
    method = RequestMethod.PUT,
    produces = "*/*",
    consumes = "multipart/form-data"
  )
  FileUploadResponse uploadUsingPUT2(@RequestPart("file") byte[] file,
    @RequestParam("filename") String filename, @RequestParam("path") String path,
    @RequestHeader("header1") String header1,
    @RequestHeader("header2") String header2);

}

to provide it with an encoder, I have added below encoder:

@Bean
  public Encoder feignEncoder() {
    ObjectFactory<HttpMessageConverters> objectFactory = () ->
      new HttpMessageConverters(new FormHttpMessageConverter());
    // return new SpringEncoder(objectFactory);
    return new FormEncoder(new SpringEncoder(objectFactory));
  }

still I am getting exceptions with all the three approaches:

uploadUsingPUT:

Could not write request: no suitable HttpMessageConverter found for request type [java.io.File] and content type [multipart/form-data]

uploadUsingPUT1:

Could not write request: no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data]

uploadUsingPUT2:

Required request part 'file' is not present

PLEASE SUGGEST


Solution

  • This issue seems to be resolved now, I was on 2.0.x version for feign-form, when I upgraded to 3.4.1 it started working.