EzyFox Server Annotations
Updated at 1689065597000Supported Annotations
EzyFox Server provides a list of annotations:
| # | Annotation | Scopes | Description |
| 1 | EzyDoHandle | Method | Maps a request command to a controller's method |
| 2 | EzyEventHandler | Class | Maps an event to a controller |
| 3 | EzyExceptionHandler | Class | Indicates the annotated class will handle exceptions |
| 4 | EzyRequestController | Method | Indicates the annotated class is controller |
| 5 | EzyRequestData | Parameter | Maps a request data to a java parameter |
| 6 | EzyRequestInterceptor | Class | Indicate the annotated class will intercept requests |
| 7 | EzyRequestListener | Class | Map a request command to a handler class |
| 8 | EzyTryCatch | Method | Indicates the annotated method will handle the exception in TryCatch |
1. EzyDoHandle
below examplesecureChatsecureChat command:
@EzyRequestController public class ChatRequestController extends EzyLoggable { @EzyDoHandle("secureChat") public void secureChat(EzyUser user, ChatRequest request) { responseFactory.newObjectResponse() .encrypted() .command(Commands.SECURE_CHAT) .param("secure-message", greeting.greet(request.getWho())) .user(user) .execute(); } }
2. EzyEventHandler
example for SERVER_READY event:
@EzyEventHandler(SERVER_READY) // refer EzyEventType public class ServerReadyController extends EzyAbstractAppEventController<EzyServerReadyEvent> { @Override public void handle(EzyAppContext ctx, EzyServerReadyEvent event) { logger.info("hello-world app: fire custom app ready, node name: {}", appConfig.getNodeName()); } }
3. EzyExceptionHandler
GlobalExceptionHandler:
@EzyExceptionHandler public class GlobalExceptionHandler extends EzyLoggable { private final EzyResponseFactory responseFactory; @EzyTryCatch(InvalidChatRequestException.class) public void handle(InvalidChatRequestException e) {} }
4. EzyRequestController
ChatRequestController:
@EzyRequestController public class ChatRequestController extends EzyLoggable { @EzyDoHandle(Commands.SECURE_CHAT) public void secureChat(EzyUser user, ChatRequest request) {} }
5. EzyRequestData
EyRequestData like this:
@EzyDoHandle("hello") public void handleHelloRequest( EzyContext context, String cmd, @EzyRequestData Hello data ) { // handle the hello request }
6. EzyRequestInteceptor
You can use this annotation for a class that intercepts client requests, example:
@EzyRequestInterceptor public class AppRequestInterceptor extends EzyLoggable implements EzyUserRequestInterceptor<EzyAppContext> { @Override public void preHandle( EzyAppContext context, EzyUserSessionEvent event, String command, Object data ) { logger.info("user: {} request command: {}", event.getUser(), command); } }
7. EzyRequestListener
EzyRequestListenerGreetRequestHandler:
@Setter @EzyPrototype @EzyObjectBinding(write = false) @EzyRequestListener(GREET) public class GreetRequestHandler extends ClientRequestHandler implements EzyDataBinding { private String who; @EzyAutoBind private Greeting greeting; @Override protected void execute() throws EzyBadRequestException { responseFactory.newObjectResponse() .command(GREET) .param("message", greeting.greet(who)) .session(session) .execute(); } }
for many way to handle a request with EzyFox Server
8. EzyTryCatch
GlobalExceptionHandler.handle@EzyTryCatch(InvalidChatRequestException.class) public void handle( InvalidChatRequestException e, EzyUserSessionEvent event, String command, Object request ) { logger.info("invalid chat request, command: {}, data: {}", command, request, e); responseFactory.newObjectResponse() .command(EzyResponseCommands.ERROR) .data(EzyEntityObjects.newObject("request", "invalid")) .session(event.getSession()) .execute(); }
Next Step
.