Announcement Announcement Module
Collapse
No announcement yet.
how can a Contoller be made aware of the xsd validation events Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how can a Contoller be made aware of the xsd validation events

    Jaxb2Marshaller is wired to my custom ValidationEventHandler and the schema for my request.
    And I am able to view and log the Validation errors but I would like to be able to access this this ValidationEvent in my Controller so that I can construct my own meaningful Fault response to an RESTful xml service.

    Could any of the following be accomplished?:

    Have the controller's request mapping method explicitly validate the object in the request body against the schema so that unmarshall validation errors are available to the controller. Can this be implemented?

    (or)

    Is there a better way to handle controller's @RequestBody validation through a different error handling mechanism?

    Currently all i get is:


    HTTP Status 400 -

    message

    description The request sent by the client was syntactically incorrect ().


    When the actual event message is something like this:

    Invalid content was found starting with element 'lastName'. One of '{"http://request":dateOfBirth}' is expected.

    I want to expose this error to my users in my fault xml message and not via an HTTP error.

    Can someone please help me with this issue.

    -Pavi

  • #2
    Example from http://www.ibm.com/developerworks/we...x.html?ca=drs- helped resolve the issue.

    Using the following configurations the request body string content was then unmarshalled and the controller could logs the errors if required.

    <!--To enable @RequestMapping process on type level and method level-->
    <bean class="org.springframework.web.servlet.mvc.annotat ion
    .DefaultAnnotationHandlerMapping" />
    <bean class="org.springframework.web.servlet.mvc.annotat ion
    .AnnotationMethodHandlerAdapter" />


    @RequestMapping(method=RequestMethod.POST, value="/employee")
    public ModelAndView addEmployee(@RequestBody String body) {
    Source source = new StreamSource(new StringReader(body));
    Employee e = (Employee) jaxb2Mashaller.unmarshal(source);
    employeeDS.add(e);
    return new ModelAndView(XML_VIEW_NAME, "object", e);
    }
    Last edited by pavithra; Dec 27th, 2010, 09:31 AM.

    Comment

    Working...
    X