which way for RESTful webservice, Spring-WS payloads or Spring 3 MVC REST Controllers?

StackOverflow https://stackoverflow.com/questions/14827895

سؤال

Im beginner for Spring Webservices. Im trying to create contract-first web services using spring-ws 2.0. I have done web.xml (MessageDispatcherServlet) configurations, my contract-design (XSD), generated JAXB classes and service implementations. Im confused in Endpoints. Which one of the following, mvc rest controllers or enpoints, is correct to use in which scenario and why? Thanks in advance.

@Endpoint
public class PersonEndpoint {

    @Autowired
    private PersonServiceImpl personService;

    @PayloadRoot(localPart = "PersonRequest", namespace = Constants.PERSON_NAMESPACE)
    public @ResponsePayload
    PersonResponseType personReadMethod(@RequestPayload PersonReadRequestType requestElement) {
        return personService.isBiometricNeeded(requestElement);
    }
}

or

@Controller
public class PersonController {

    @Autowired
    private PersonServiceImpl personService;

    @RequestMapping(value = "/person", method = RequestMethod.GET)
    public @ResponseBody
    PersonResponseType personReadMethod(@RequestBody PersonReadRequestType requestElement) {
        return personService.isBiometricNeeded(requestElement);
    }
}
هل كانت مفيدة؟

المحلول

The former is used for Soap calls, the latter for rest (I assume you have also included Jackson)

What you're doing in the former is declaring an endpoint which will be called upon an incoming soap call with the appropriate namespace and localPart. In your case PersonRequest.

I would recommend taking a look at chapter 3 of the reference guide which explains a simple example: http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

The latter is just for a rest call to the url and will transform the incoming parameters to an PersonReadRequestType instance.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top