2

Code is

@RestController
@Component
@Slf4j
public class ServicesController {
 @CrossOrigin
    @PutMapping(
            consumes = "multipart/form-data",
            path = "/{id}/{route}/structure_article/{filename:.+}")
    public ResponseEntity<ServiceResponse> updateStructureXMLFile(
            @PathVariable("id") final String id,
            @PathVariable("route") final String route,
            @RequestParam("file") final MultipartFile uploadfile,
            @PathVariable("filename") final String fileName) throws IOException {
(Some processing)
return new ResponseEntity<>(response, httpHeaders, HttpStatus.CREATED);
}
}

Here response is a POJO with public getters and setters. enter image description here

When I am putting a file getting this error:

{
    "timestamp": 1596783608973,
    "status": 406,
    "error": "Not Acceptable",
    "exception": "org.springframework.web.HttpMediaTypeNotAcceptableException",
    "message": "Could not find acceptable representation",
    "path": "/7f3033d7-3979-45e0-9f0a-172b60568edb/articles/structure_article/manuscript.xml"
}

What can be solution for this? Thank you

Tanvi Shah
  • 21
  • 2
  • 1
    Are you sure that this is the correct Controller? Because this path "/{id}/{route}/structure_article/{filename:.+}" don't look like the one on the image – Mafick Aug 07 '20 at 07:30
  • And what is the request ?? Aspecially `Accept` header. And yeah, request is made to different endpoint than specified here (missing structure_rticle) – Antoniossss Aug 07 '20 at 07:30
  • I have edited the image – Tanvi Shah Aug 07 '20 at 09:07

1 Answers1

0

In my case, the Content Negotiation was configured like:

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer
        .favorPathExtension(true)
        .defaultContentType(MediaType.APPLICATION_JSON)
        .mediaType("xml", MediaType.APPLICATION_XML) 
        .mediaType("json", MediaType.APPLICATION_JSON); 
}

and just like you, I have a controller method with

@PutMapping("/user/{userId:.+}")

So, Spring tries to treat a request /user/email@domain.com for example with the Content-Type of .com file extension which does not exist in the Common MIME types, hence the 406 error.

I resolved it by turning off favorPathExtension.

Attacktive
  • 604
  • 1
  • 11
  • 25