I don't like using an Error here, but too late to introduce a checked exception.

I suppose the justification could be that this error is meant to really just abort the processing right there, so it's somewhat akin to ThreadDeath.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7316 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2008-03-04 21:30:14 +00:00
1 parent 90e6be745d
commit b076630e8d
1 file changed
+9 -6
@@ -5,7 +5,6 @@ import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import java.io.IOException;
@@ -16,16 +15,20 @@ import java.io.IOException;
* @author Kohsuke Kawaguchi
*/
public class StructuredForm {
public static JSONObject get(StaplerRequest req) throws IOException, ServletException {
public static JSONObject get(StaplerRequest req) {
JSONObject o = (JSONObject)req.getAttribute(StructuredForm.class.getName());
if(o==null) {
String p = req.getParameter("json");
if(p==null) {
// no data submitted
StaplerResponse rsp = Stapler.getCurrentResponse();
rsp.sendError(SC_BAD_REQUEST,"This page expects a form submission");
rsp.getWriter().close();
throw new ServletException("This page expects a form submission");
try {
StaplerResponse rsp = Stapler.getCurrentResponse();
rsp.sendError(SC_BAD_REQUEST,"This page expects a form submission");
rsp.getWriter().close();
throw new Error("This page expects a form submission");
} catch (IOException e) {
throw new Error(e);
}
}
o = JSONObject.fromObject(p);
req.setAttribute(StructuredForm.class.getName(),o);