001package org.javasimon.console.action;
002
003import org.javasimon.console.Action;
004import org.javasimon.console.ActionContext;
005import org.javasimon.console.ActionException;
006
007import java.io.IOException;
008import java.io.PrintWriter;
009
010import javax.servlet.ServletException;
011
012/**
013 * Action used when an exception occurs: exception stack trace is dumped into the response.
014 *
015 * @author gquintana
016 */
017public class ErrorAction extends Action {
018
019        /** Exception to render. */
020        private ActionException error;
021
022        public ErrorAction(ActionContext context) {
023                super(context);
024        }
025
026        public ActionException getError() {
027                return error;
028        }
029
030        public void setError(ActionException error) {
031                this.error = error;
032        }
033
034        @Override
035        public void execute() throws ServletException, IOException, ActionException {
036                PrintWriter writer = null;
037                try {
038                        getContext().setContentType("text/plain");
039                        writer = getContext().getWriter();
040                        error.printStackTrace(getContext().getWriter());
041                } finally {
042                        if (writer != null) {
043                                writer.flush();
044                        }
045                }
046        }
047}