Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC controller throwing 415 error media unsupported for JSON request

I have looked at all the other answers for this problem and tried most of the solutions but nothing seems to work. I am using Dojo.xhrPOST(xhrArgs) which obviously comes after the xhrArgs definition.

my xhrArgs:

 xhrArgs = 
 {
     headers: 
     { 
       'Accept': 'application/json',
       'Content-Type': 'application/json' 
     },
  'url': thisUrl,
  'postData':requestString,
  'dataType' : 'json',
  'userId': userId,
  'measurementSystem': measurementSystem,
  'systemId': openedSystemId,
  'handleAs': 'text',
  'load': function(data)
     {
         // Replace newlines with nice HTML tags.
         data = data.replace(/\n/g, "<br/>");
         dojo.byId(target).innerHTML = data;
     },
    'error': function(error)
    {
       dojo.byId(target).innerHTML = error;
    }
};

and my controller method signature and annotations are as follows

@RequestMapping(value="/saveSystemConditions", method= RequestMethod.POST,  headers =                                                                               {"content-type=application/json"})
 public String saveSystemConditions(HttpServletRequest request, HttpServletResponse response, @Valid @RequestBody Load load, BindingResult result)

and my requestString as shown in the xhrArgs is

"{'systemID':'76', 'system.systemType':'1', 'unitsOfMeasure':'english', 'loadID':'63', 'dispersionInstallationLocation':'Duct+or+AHU', 'humidificationSystemType':'1', 'totalAirVolume':'1200.0', 'desiredDryBulb':'70.0', 'desiredAirMoistureType':'2', 'desiredAirMoisture':'55.0', 'outsideAirConditionsType':'1', 'outsideAirIntakeRateMeasuredAs':'0', 'loadCountry':'United+States', 'outsideAirVolumeMeasuredIn':'0', 'loadState':'Minnesota', 'outsideAirIntakeRate':'25.0', 'loadCity':'Minneapolis', 'elevationFeet':'837.0', 'outsideDryBulb':'-6.8', 'outsideAirMoisture':'57.3', 'userEnteredLoad':'7.43'}"

I get 415 (Unsupported Media Type)

Any suggestions would be much appreciated. David

like image 301
David C Avatar asked Dec 15 '25 20:12

David C


1 Answers

It was a problem with the explicit declaration of spring mvc mapping handlers along with <mvc:annotation-conig />.

like image 130
Arun P Johny Avatar answered Dec 17 '25 22:12

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!