My spring boot application was running fine. Suddenly I am facing an strange issue.
Below is the StackTrace:
Inside Global Exception Handler. Exception caught is {}
org.springframework.http.InvalidMediaTypeException: Invalid mime type "text/xml; charset=UTF-8,application/xml": UTF-8,application/xml
at org.springframework.http.MediaType.parseMediaType(MediaType.java:452) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:760) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:115) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:85) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:662) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:620) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:387) ~[spring-web-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
at com.airtelbank.insurance.utils.RestUtils.postXmlRequest(RestUtils.java:100) ~[classes!/:1.0.5]
at com.airtelbank.insurance.utils.RestUtils.postXmlRequest(RestUtils.java:122) ~[classes!/:1.0.5]
at com.airtelbank.insurance.service.impl.vehicle.IDVServiceImpl.getIDVValue(IDVServiceImpl.java:116) ~[classes!/:1.0.5]
at com.airtelbank.insurance.controller.vehicle.GIController.checkIDV(GIController.java:198) ~[classes!/:1.0.5]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
Request Mapping in controller:
@RequestMapping(value = "v1/test", method = RequestMethod.GET, consumer ="application/json",produces = {"application/JSON"})
Any Help is appreciated.
as you post code you need to post your request as content-type = application/xml or text/xml
change like this
@RequestMapping(value = "/test",consumer ="application/xml or text/xml", produces = {"application/json"})
after that change your request header side content-type as application/xml or text/xml then it will be fixed.And also provide method (GET ,POST)
@RequestMapping(value = "v1/test", method = RequestMethod.POST,consume="text/xml",produces="application/json")
@ResponseBody
public ResponseEntity<CustomObject> test(@RequestBody CustomXMLObject) {
// do some logical things for example change to json
return new ResponseEntity<CustomObject>(convertedJsonObject,HttpStatus.OK);
}
request this method as post and set header content-type as text/xml