2

I have the following property that I need mapped to a post parameter in Spring. Is there an attribute I can use? It accepts application/x-www-form-urlencoded for string-based payloads, multipart/form-data for binary payloads. Other properties are mapping fine without underscores.

String deliveryAttemptId;

mapped to the post parameter

DELIVERY-ATTEMPT-ID

Controller

@Controller
@RequestMapping("/notifications")
public class NotificationController {

    @RequestMapping(method = RequestMethod.POST)
        @ResponseBody
        public void grade(EventNotificationRequest request, HttpServletResponse response) throws Exception {        

    }

Model

public class EventNotificationRequest {

    String deliveryAttemptId;
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • Please clarify whether this endpoint is a web service endpoint or a form-processing endpoint. The approach is different depending on the answer. –  Dec 18 '13 at 23:33
  • MVC Controller for spring – Mike Flynn Dec 18 '13 at 23:40
  • That part I got (i.e., that there's a Spring Web MVC controller processing the request). My question is whether you have an HTML form submitting the data, or whether it's a web service client. –  Dec 18 '13 at 23:42
  • Either one can make a POST, application/x-www-form-urlencoded for string-based payloads, multipart/form-data for binary payloads – Mike Flynn Dec 18 '13 at 23:43
  • Isnt there a way to map it like I posted here, http://stackoverflow.com/questions/20646634/map-json-property-with-period-to-class-property-in-spring-controller – Mike Flynn Dec 18 '13 at 23:44
  • So we understand eachother: you want to make a post request like `host.com/context/notifications?DELIVERY_ATTEMPT_ID=someValue` and have it mapped to a property of a class (`EventNotificationRequest`)? – Sotirios Delimanolis Dec 19 '13 at 05:14
  • Yep exactly how do I do that – Mike Flynn Dec 19 '13 at 15:48
  • There may not be a way http://stackoverflow.com/questions/1943878/how-to-map-a-b-query-to-a-command-object-in-spring-mvc – Mike Flynn Dec 19 '13 at 15:51
  • In my case I just needed https://stackoverflow.com/q/23892179/733092. – Noumenon Mar 04 '18 at 23:08

1 Answers1

0

I just made a work around for this Spring limitation. This also fixes case sensitivity issues with parameters. Sorry I am used to .NET and how easy binding is so it's frustrating to run into these Spring issues.

HttpServletRequest parameter lowecase

 @RequestMapping(method = RequestMethod.POST, value = "/grade")
        @ResponseBody
        public void grade(HttpServletRequest request, HttpServletResponse response) throws Exception {  

            EventNotificationRequest notificationRequest = new LearningStudioEventNotificationRequest();
            notificationRequest.setDeliveryAttemptId(getCaseInsensitiveParameter(request, "DELIVERY-ATTEMPT-ID"));
Community
  • 1
  • 1
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341