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

杀马特。学长 韩版系。学妹 提交于 2019-12-23 15:10:26

问题


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);
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/14827895/which-way-for-restful-webservice-spring-ws-payloads-or-spring-3-mvc-rest-contro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!