Class RpcGreeterController

java.lang.Object
info.ejava.examples.svc.rpc.greeter.controllers.RpcGreeterController

@RestController @RequestMapping("rpc/greeter") public class RpcGreeterController extends Object
The following is an example of using the HTTP constructs that are a part of a RESTful interface, but using them in an RPC way. The following is not even close to being RESTful and not what I will be referring to as REST-like.
  • Constructor Details

    • RpcGreeterController

      public RpcGreeterController()
  • Method Details

    • sayHi

      @RequestMapping(path="sayHi", method=GET) public String sayHi()
      This is an example of a method as simple as it gets
      Returns:
      hi
    • sayGreeting

      @RequestMapping(path="say/{greeting}", method=GET) public String sayGreeting(@PathVariable("greeting") String greeting, @RequestParam(value="name",defaultValue="you") String name)
    • boom

      @RequestMapping(path="boom", method=GET) public String boom(@RequestParam(value="value",required=true) String value)
      This method is an example of the container returning an error when the client does not supply a required query parameter.
      Parameters:
      value -
    • createBoy

      @RequestMapping(path="boys", method=GET) public org.springframework.http.ResponseEntity<String> createBoy(@RequestParam("name") String name)
      This method is an example of how the controller method can have full control over the response issued back to the caller.
      Parameters:
      name -
    • someMethodThatMayThrowException

      private void someMethodThatMayThrowException(String name)
    • createBoyThrows

      @RequestMapping(path="boys/throws", method=GET) public org.springframework.http.ResponseEntity<String> createBoyThrows(@RequestParam("name") String name)
      This method is an example of offloading detailed ResponseEntity handling to an @ExceptionHandler to keep the controller method clean.
      Parameters:
      name -
    • handle

      @ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<String> handle(IllegalArgumentException ex)
      This is an example handler that will convert an exception to a ResponseEntity to return to the caller. It is supplied within the controller here as a 1st step example. Later examples try to generalize the solution and create a service-wide advice.
      Parameters:
      ex -
      Returns:
      ResponseEntity