Class SampleController

java.lang.Object
ywebservicespackage.controllers.SampleController

@Controller @RequestMapping("/sample") public class SampleController extends Object
Sample Controller
  • Field Details

  • Constructor Details

    • SampleController

      public SampleController()
  • Method Details

    • getSample

      @GetMapping(value="/dto/{pathVariable}", produces={"application/json","application/xml"}) @ResponseBody public SampleWsDTO getSample(@PathVariable String pathVariable)
      Sample method returning Cache-Control header and using Path Variable
      Example :
      GET http://localhost:9001/ywebservices/sample/dto/sampleValue
      Parameters:
      pathVariable - Sample path variable parameter
      Returns:
      SampleWsDTO object filled with pathVariable value
    • createSample

      @PostMapping(value="/dto", consumes={"application/json","application/xml"}, produces={"application/json","application/xml"}) @ResponseStatus(CREATED) @ResponseBody public SampleWsDTO createSample(@RequestBody SampleWsDTO sampleWsDTO)
      Sample method showing how to validate object given in POST body parameter
      Example :
      URL : http://localhost:9001/ywebservices/sample/dto
      Method : POST
      Header : Content-Type=application/json
      POST body parameter :{ "value" : "sampleValue"}
      Parameters:
      sampleWsDTO - - Request body parameter (DTO in xml or json format)
      Returns:
      - The same object, which was send in POST body
    • validate

      protected void validate(Object object, String objectName, org.springframework.validation.Validator validator)
    • getUsersList

      @GetMapping(value="/users", produces={"application/json","application/xml"}) @ResponseBody public UsersListWsDTO getUsersList(@RequestParam(required=false,defaultValue="DEFAULT") String fields)
      Request handler for list response. Retrieves all user from userService and maps Collection of UserModel to UserListWsDTO Mapping is done according to configuration in WEB-INF/config/field-mapping.xml Sample url's:
      • http://localhost:9001/ywebservices/sample/users
      • http://localhost:9001/ywebservices/sample/users?fields=users(info)
      • http://localhost:9001/ywebservices/sample/users?fields=users(BASIC)
      • http://localhost:9001/ywebservices/sample/users?fields=users(DEFAULT)
      • http://localhost:9001/ywebservices/sample/users?fields=users(FULL)
      • http://localhost:9001/ywebservices/sample/users?fields=users(firstName,addresses(street))
    • getUsers

      @GetMapping(value="/usersPaged", produces={"application/json","application/xml"}) @ResponseBody public UsersPageWsDTO getUsers(@RequestParam(required=false,defaultValue="DEFAULT") String fields, @RequestParam Map<String,String> params)
      Request handler for paginated response. Retrieves user from userService and maps result to UsersPageWsDTO Mapping is done according to configuration in WEB-INF/config/field-mapping.xml Sample url's:
      • http://localhost:9001/ywebservices/sample/usersPaged
      • http://localhost:9001/ywebservices/sample/usersPaged?currentPage=1
      • http://localhost:9001/ywebservices/sample/usersPaged?currentPage=0?pageSize=1
    • getUser

      @GetMapping(value="/users/{id}", produces={"application/json","application/xml"}) @ResponseBody public UserWsDTO getUser(@PathVariable String id, @RequestParam(required=false,defaultValue="DEFAULT") String fields)
      Request handler for particular user. Retrieves single user from userService and maps UserModel to UserWsDTO Mapping is done according to configuration in WEB-INF/config/field-mapping.xml Sample url's:
      • http://localhost:9001/ywebservices/sample/users/user1
      • http://localhost:9001/ywebservices/sample/users/user1?fields=info
      • http://localhost:9001/ywebservices/sample/users/user1?fields=BASIC
      • http://localhost:9001/ywebservices/sample/users/user1?fields=DEFAULT
      • http://localhost:9001/ywebservices/sample/users/user1?fields=FULL
      • http://localhost:9001/ywebservices/sample/users/user1?fields=firstName,addresses(street)
    • updateUser

      @PatchMapping(value="/users/{userId}", consumes={"application/json","application/xml"}) @ResponseStatus(OK) public void updateUser(@PathVariable String userId, @RequestBody UserWsDTO user)
      Sample method for updating data of particular user using PATCH request.
      Parameters:
      userId - User identifier
      user - Username and info as DTO in xml or json format
    • getTestMap

      @GetMapping(value="/map", produces={"application/json","application/xml"}) @ResponseBody public TestMapWsDTO getTestMap()
      Request handler for getting object with map. Created to test adapters for particular fields.

      Url: http://localhost:9001/ywebservices/sample/map

    • doProcessString

      @PostMapping("plain/string") @ResponseBody public String doProcessString(@RequestBody String val)
    • doProcessLong

      @PostMapping("plain/long") @ResponseBody public Long doProcessLong(@RequestBody Long value)
    • doProcessDouble

      @PostMapping("plain/double") @ResponseBody public double doProcessDouble(@RequestBody double value)
    • getList

      @GetMapping("plain/list") @ResponseBody public List<Object> getList()
    • getMap

      @GetMapping("plain/map") @ResponseBody public Map<String,Object> getMap()
    • getTestBeanText

      @GetMapping("/testBean") @ResponseBody public SampleWsDTO getTestBeanText()