Class RpcGreeterController
java.lang.Object
info.ejava.examples.svc.rpc.greeter.controllers.RpcGreeterController
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis method is an example of the container returning an error when the client does not supply a required query parameter.org.springframework.http.ResponseEntity<String>
This method is an example of how the controller method can have full control over the response issued back to the caller.org.springframework.http.ResponseEntity<String>
createBoyThrows
(String name) This method is an example of offloading detailed ResponseEntity handling to an @ExceptionHandler to keep the controller method clean.org.springframework.http.ResponseEntity<String>
This is an example handler that will convert an exception to a ResponseEntity to return to the caller.sayGreeting
(String greeting, String name) sayHi()
This is an example of a method as simple as it getsprivate void
-
Constructor Details
-
RpcGreeterController
public RpcGreeterController()
-
-
Method Details
-
sayHi
This is an example of a method as simple as it gets- Returns:
- hi
-
sayGreeting
-
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
-
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
-