diff options
author | 2016-11-12 01:34:07 +0700 | |
---|---|---|
committer | 2016-11-12 11:14:56 +0300 | |
commit | 194a9a763c6b11d207e682b2f93de94475c473b4 (patch) | |
tree | 196317662017b716066eadfa413ecbdc7532c52d /juick-ws/src/main/java/com/juick/ws/controllers | |
parent | 7d86347a351aa5263c19cd03aa0bda4650c8bfca (diff) |
extracted application configuration from Mvc configuration with application specific beans;
extracted bean initialization from constructor;
force using properties;
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/controllers')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java | 25 | ||||
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java | 32 |
2 files changed, 57 insertions, 0 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java b/juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java new file mode 100644 index 00000000..2f57b0b6 --- /dev/null +++ b/juick-ws/src/main/java/com/juick/ws/controllers/ApiController.java @@ -0,0 +1,25 @@ +package com.juick.ws.controllers; + +import com.juick.server.helpers.Status; +import com.juick.ws.WebsocketComponent; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.inject.Inject; + +/** + * Created by vitalyster on 25.07.2016. + */ +@RestController +public class ApiController { + @Inject + WebsocketComponent wsHandler; + + @RequestMapping(value = "/api/status", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public Status status() { + return new Status(String.valueOf(wsHandler.getClients().size())); + } +} diff --git a/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java b/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java new file mode 100644 index 00000000..2fe55eeb --- /dev/null +++ b/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java @@ -0,0 +1,32 @@ +package com.juick.ws.controllers; + +import com.juick.ws.WebsocketComponent; +import com.juick.ws.XMPPConnection; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import javax.inject.Inject; + +/** + * Created by vitalyster on 19.07.2016. + */ +@Controller +@ResponseBody +public class StatusController { + @Inject + WebsocketComponent wsHandler; + @Inject + XMPPConnection ws; + + @RequestMapping(method = RequestMethod.GET, headers = "Connection!=upgrade", value = "/") + public ModelAndView status() { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.addObject("clients", wsHandler.getClients().size()); + modelAndView.setViewName("index"); + return modelAndView; + } + +} |