New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement TaskServlet::doGet to list tasks lexically. #1939
Conversation
Implement doGet in TaskServlet in order to be able to query registered tasks. Returns the registered tasks ordered lexically by Task::getName. Since TaskServlet matches "/tasks/*" any GET request not matching root will yield 404 or 405. 404: Task name is unknown. 405: Task name is registered but must be invoked with POST.
if (Strings.isNullOrEmpty(req.getPathInfo())) { | ||
try (final PrintWriter output = resp.getWriter()) { | ||
resp.setContentType(MediaType.PLAIN_TEXT_UTF_8.toString()); | ||
final ArrayList<Task> tasks = new ArrayList<>(getTasks()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and the following lines) could be replaced by:
getTasks().stream()
.map(Task::getName)
.sorted()
.forEach(output::println);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks @joschi, nice and clean. (Grepping for stream()
made me think it was a bad idea to use it :D )
import com.google.common.collect.ImmutableMultimap; | ||
import com.google.common.io.CharStreams; | ||
import com.google.common.net.MediaType; | ||
import java.util.ArrayList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the unused imports. Then we're good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
* Use stream() when looping, sorting and printing task names.
Implement doGet in TaskServlet in order to be able to query registered tasks. Returns the registered tasks ordered lexically by Task::getName. Since TaskServlet matches "/tasks/*" any GET request not matching root will yield 404 or 405. 404: Task name is unknown. 405: Task name is registered but must be invoked with POST. Closes #1940 (cherry picked from commit e94deb2)
Thanks for reviewing @joschi |
Tasks are logged on startup but aren't easily accessible otherwise. Implement
TaskServlet::doGet
to print tasks lexically by name.Example:
TaskServlet is mapped on "/tasks/*" and any GET request not matching root
will yield 404 or 405.
404: Task name is unknown.
405: Task name is registered but must be invoked with POST.