Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC Web Validation: Validate Request Model and Not Response Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC Web Validation: Validate Request Model and Not Response

    I have registered a validator by doing a @InitBinder. Here is my controller code snippet:

    Code:
    	@InitBinder
    	public void initBinder(WebDataBinder binder) {
    		binder.setValidator(new ArchiveReportRequestFormValidator());
    	}
    Code:
    	@RequestMapping(value = "/reports/preciseid/v2/archives", method = RequestMethod.GET, headers = "Accept=application/xml")
    	public FraudArchiveReport getArchiveReportsV2(
    			final HttpServletRequest request,
    			@Validated ArchiveReportRequestForm requestForm)
    			throws ApplicationException {
    		appLogHandler
    				.logInformational("RESTfulPreciseIDV1WebserviceController.getArchiveReportsV2() is invoked at "
    						+ new Date() + ".");
    		appLogHandler.logInformational("RequestForm: " + requestForm);
    		FraudArchiveReport report = createPIDArchiveReport();
    		request.setAttribute("Archive Report", report);
    		appLogHandler
    				.logInformational("RESTfulPreciseIDV1WebserviceController.getArchiveReportsV2() is invoked at "
    						+ new Date() + ".");
    		return report;
    	}
    Now Spring is validating my incoming request model, ArchiveReportRequestForm, just fine. However, it seems to attempt to validate my outgoing response model, FraudArchiveReport, as well, and that is not a desired behavior. Is there a way to validate only the incoming request and not the outgoing response when I bind my own custom validator?

  • #2
    Spring will only validate incoming requests. Actually it only validates model objects so I doubt that i validates your response object.

    Also why don't you let spring handle things for you? Why are you setting a request attribute?

    Comment

    Working...
    X