Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.tasks;
A servlet which provides access to administrative Tasks. It only responds to POST requests, since most Tasks aren't side-effect free, and passes along the query string parameters of the request to the task as a multimap.

See also:
public class TaskServlet extends HttpServlet {
    private static final long serialVersionUID = 7404713218661358124L;
    private static final Logger LOGGER = LoggerFactory.getLogger(TaskServlet.class);
    private final ImmutableMap<StringTasktasks;

Creates a new TaskServlet given the provided set of Task instances.

tasks a series of tasks which the servlet will provide access to
    public TaskServlet(Iterable<Tasktasks) {
        final ImmutableMap.Builder<StringTaskbuilder = ImmutableMap.builder();
        for (Task task : tasks) {
            builder.put('/' + task.getName(), task);
        this. =;
    protected void doPost(HttpServletRequest req,
                          HttpServletResponse respthrows ServletExceptionIOException {
        final Task task = .get(req.getPathInfo());
        if (task != null) {
            final PrintWriter output = resp.getWriter();
            try {
                task.execute(getParams(req), output);
            } catch (Exception e) {
                .error("Error running {}"task.getName(), e);
            } finally {
        } else {
    private static ImmutableMultimap<StringStringgetParams(HttpServletRequest req) {
        final ImmutableMultimap.Builder<StringStringresults = ImmutableMultimap.builder();
        final Enumeration<Stringnames = req.getParameterNames();
        while (names.hasMoreElements()) {
            final String name = names.nextElement();
            final String[] values = req.getParameterValues(name);
New to GrepCode? Check out our FAQ X