@Test public void testQueryQueueTrailingSlash() { when(mockTextCommandService.poll(TEST_QUEUE)).thenReturn(TEST_VALUE); HttpGetCommand command = new HttpGetCommand(uri_queue_correct_slash); componentUnderTest.handle(command); verify(mockTextCommandService).poll(TEST_QUEUE); assertEquals("Result array not matches expectation", expected_result.response, command.response); }
public void handle(HttpGetCommand command) { String uri = command.getURI(); if (uri.startsWith(URI_MAPS)) { int indexEnd = uri.indexOf('/', URI_MAPS.length()); String mapName = uri.substring(URI_MAPS.length(), indexEnd); String key = uri.substring(indexEnd + 1); Object value = textCommandService.get(mapName, key); prepareResponse(command, value); } else if (uri.startsWith(URI_QUEUES)) { String queueName; if (uri.endsWith("/")) { queueName = uri.substring(URI_QUEUES.length(), uri.length() - 1); } else { queueName = uri.substring(URI_QUEUES.length()); } Object value = textCommandService.poll(queueName); prepareResponse(command, value); } else if (uri.startsWith(URI_CLUSTER)) { Node node = textCommandService.getNode(); StringBuilder res = new StringBuilder(node.getClusterImpl().toString()); res.append("\n"); ConnectionManager connectionManager = node.getConnectionManager(); res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections()); res.append("\n"); res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections()); res.append("\n"); command.setResponse(null, res.toString().getBytes()); } else if (uri.startsWith(URI_STATE_DUMP)) { final String stateDump = textCommandService.getNode().getSystemLogService().dump(); command.setResponse(HttpCommand.CONTENT_TYPE_PLAIN_TEXT, stateDump.getBytes()); } else { command.send400(); } textCommandService.sendResponse(command); }
HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> { public void handle(HttpGetCommand command) { String uri = command.getURI(); if (uri.startsWith(URI_MAPS)) { int indexEnd = uri.indexOf('/', URI_MAPS.length()); String mapName = uri.substring(URI_MAPS.length(), indexEnd); String key = uri.substring(indexEnd + 1); Object value = textCommandService.get(mapName, key); prepareResponse(command, value); } else if (uri.startsWith(URI_QUEUES)) { String queueName; if (uri.endsWith("/")) { queueName = uri.substring(URI_QUEUES.length(), uri.length() - 1); } else { queueName = uri.substring(URI_QUEUES.length()); } Object value = textCommandService.poll(queueName); prepareResponse(command, value); } else if (uri.startsWith(URI_CLUSTER)) { Node node = textCommandService.getNode(); StringBuilder res = new StringBuilder(node.getClusterImpl().toString()); res.append("\n"); ConnectionManager connectionManager = node.getConnectionManager(); res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections()); res.append("\n"); res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections()); res.append("\n"); command.setResponse(null, res.toString().getBytes()); } else if (uri.startsWith(URI_STATE_DUMP)) { final String stateDump = textCommandService.getNode().getSystemLogService().dump(); command.setResponse(HttpCommand.CONTENT_TYPE_PLAIN_TEXT, stateDump.getBytes()); } else { command.send400(); } textCommandService.sendResponse(command); } }
HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> { public void handle(HttpGetCommand command) { String uri = command.getURI(); if (uri.startsWith(URI_MAPS)) { int indexEnd = uri.indexOf('/', URI_MAPS.length()); String mapName = uri.substring(URI_MAPS.length(), indexEnd); String key = uri.substring(indexEnd + 1); Object value = textCommandService.get(mapName, key); prepareResponse(command, value); } else if (uri.startsWith(URI_QUEUES)) { String queueName; if (uri.endsWith("/")) { queueName = uri.substring(URI_QUEUES.length(), uri.length() - 1); } else { queueName = uri.substring(URI_QUEUES.length()); } Object value = textCommandService.poll(queueName); prepareResponse(command, value); } else if (uri.startsWith(URI_CLUSTER)) { Node node = textCommandService.getNode(); StringBuilder res = new StringBuilder(node.getClusterImpl().toString()); res.append("\n"); ConnectionManager connectionManager = node.getConnectionManager(); res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections()); res.append("\n"); res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections()); res.append("\n"); command.setResponse(null, res.toString().getBytes()); } else if (uri.startsWith(URI_STATE_DUMP)) { final String stateDump = textCommandService.getNode().getSystemLogService().dump(); command.setResponse(HttpCommand.CONTENT_TYPE_PLAIN_TEXT, stateDump.getBytes()); } else { command.send400(); } textCommandService.sendResponse(command); } HttpGetCommandProcessor(TextCommandService textCommandService); }
HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> { public void handle(HttpGetCommand command) { String uri = command.getURI(); if (uri.startsWith(URI_MAPS)) { int indexEnd = uri.indexOf('/', URI_MAPS.length()); String mapName = uri.substring(URI_MAPS.length(), indexEnd); String key = uri.substring(indexEnd + 1); Object value = textCommandService.get(mapName, key); prepareResponse(command, value); } else if (uri.startsWith(URI_QUEUES)) { String queueName; if (uri.endsWith("/")) { queueName = uri.substring(URI_QUEUES.length(), uri.length() - 1); } else { queueName = uri.substring(URI_QUEUES.length()); } Object value = textCommandService.poll(queueName); prepareResponse(command, value); } else if (uri.startsWith(URI_CLUSTER)) { Node node = textCommandService.getNode(); StringBuilder res = new StringBuilder(node.getClusterImpl().toString()); res.append("\n"); ConnectionManager connectionManager = node.getConnectionManager(); res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections()); res.append("\n"); res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections()); res.append("\n"); command.setResponse(null, res.toString().getBytes()); } else if (uri.startsWith(URI_STATE_DUMP)) { final String stateDump = textCommandService.getNode().getSystemLogService().dump(); command.setResponse(HttpCommand.CONTENT_TYPE_PLAIN_TEXT, stateDump.getBytes()); } else { command.send400(); } textCommandService.sendResponse(command); } HttpGetCommandProcessor(TextCommandService textCommandService); void handle(HttpGetCommand command); void handleRejection(HttpGetCommand command); }
HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> { public void handle(HttpGetCommand command) { String uri = command.getURI(); if (uri.startsWith(URI_MAPS)) { int indexEnd = uri.indexOf('/', URI_MAPS.length()); String mapName = uri.substring(URI_MAPS.length(), indexEnd); String key = uri.substring(indexEnd + 1); Object value = textCommandService.get(mapName, key); prepareResponse(command, value); } else if (uri.startsWith(URI_QUEUES)) { String queueName; if (uri.endsWith("/")) { queueName = uri.substring(URI_QUEUES.length(), uri.length() - 1); } else { queueName = uri.substring(URI_QUEUES.length()); } Object value = textCommandService.poll(queueName); prepareResponse(command, value); } else if (uri.startsWith(URI_CLUSTER)) { Node node = textCommandService.getNode(); StringBuilder res = new StringBuilder(node.getClusterImpl().toString()); res.append("\n"); ConnectionManager connectionManager = node.getConnectionManager(); res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections()); res.append("\n"); res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections()); res.append("\n"); command.setResponse(null, res.toString().getBytes()); } else if (uri.startsWith(URI_STATE_DUMP)) { final String stateDump = textCommandService.getNode().getSystemLogService().dump(); command.setResponse(HttpCommand.CONTENT_TYPE_PLAIN_TEXT, stateDump.getBytes()); } else { command.send400(); } textCommandService.sendResponse(command); } HttpGetCommandProcessor(TextCommandService textCommandService); void handle(HttpGetCommand command); void handleRejection(HttpGetCommand command);  }