0

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.

5
  • i think this is about when you request on controller dispatcher servlet is mapping via consumer and producer type I think you need to change request mapping consumer type maybe controller wants as a json but you sending as text / xml . I think you using postman right ? Commented Aug 29, 2018 at 11:16
  • Actually it was working fine , since last one hour i am getting this exception. It is throwing exception inside the Spring boot application when i am trying to access them Commented Aug 29, 2018 at 11:17
  • please check i have updated Commented Aug 29, 2018 at 11:21
  • 1
    You are sending XML whereas the receiving side doesn't accept XML. Commented Aug 29, 2018 at 11:21
  • You should add your basic details about your issue in question instead of comments on answer. Commented Aug 29, 2018 at 12:00

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

I am consuming SOAP service of third party i.e. xml request and response. I am parsing xml response from third party and sending JSON response from my service
But it is running fine at my local machine
Could you provide exact syntax , consumer is not resolvable in my code
0

When you are reading the xml from 3rd party service, you should parse it correctly and have below annotation on your Rest endpoint to convert it into json.

@RequestMapping(value = "v1/test", method = RequestMethod.GET, consumes = {"application/json"} ,produces = {"application/json"})

The produces and consumes attributes specifies Type of data produced by that endpoint and type of data consumed (accepted) by that endpoint respectively.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.