Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
PostBodyTask
class to allow for tasks to get the post body.
- Loading branch information
Showing
14 changed files
with
155 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dropwizard-servlets/src/main/java/io/dropwizard/servlets/tasks/PostBodyTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.dropwizard.servlets.tasks; | ||
|
||
import com.google.common.collect.ImmutableMultimap; | ||
|
||
import java.io.PrintWriter; | ||
|
||
/** | ||
* A task which can be performed via the admin interface and provides the post body of the request. | ||
* | ||
* @see Task | ||
* @see TaskServlet | ||
*/ | ||
public abstract class PostBodyTask extends Task { | ||
/** | ||
* Create a new task with the given name. | ||
* | ||
* @param name the task's name | ||
*/ | ||
protected PostBodyTask(String name) { | ||
super(name); | ||
} | ||
|
||
/** | ||
* @param parameters the query string parameters | ||
* @param body the plain text request body | ||
* @param output a {@link PrintWriter} wrapping the output stream of the task | ||
* @throws Exception | ||
*/ | ||
public abstract void execute(ImmutableMultimap<String, String> parameters, | ||
String body, | ||
PrintWriter output) throws Exception; | ||
|
||
/** | ||
* Deprecated, use `execute(parameters, body, output)` or inherit from Task instead. | ||
* | ||
* @param parameters the query string parameters | ||
* @param output a {@link PrintWriter} wrapping the output stream of the task | ||
* @throws Exception | ||
*/ | ||
@Override | ||
@Deprecated | ||
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { | ||
throw new UnsupportedOperationException("Use `execute(parameters, body, output)`"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
dropwizard-servlets/src/test/java/io/dropwizard/servlets/tasks/PostBodyTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.dropwizard.servlets.tasks; | ||
|
||
import com.google.common.collect.ImmutableMultimap; | ||
import org.junit.Test; | ||
|
||
import java.io.PrintWriter; | ||
|
||
public class PostBodyTaskTest { | ||
private final PostBodyTask task = new PostBodyTask("test") { | ||
@Override | ||
public void execute(ImmutableMultimap<String, String> parameters, String body, PrintWriter output) throws Exception { | ||
|
||
} | ||
}; | ||
|
||
@Test(expected = UnsupportedOperationException.class) | ||
public void throwsExceptionWhenCallingExecuteWithoutThePostBody() throws Exception { | ||
task.execute(new ImmutableMultimap.Builder<String, String>().build(), new PrintWriter(System.out)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.