Catch the exception in doPost and doGet method, make this two method do not throw exception.
This commit is contained in:
parent
a4891dd30f
commit
3438071374
|
|
@ -32,31 +32,43 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.server.ServerHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public abstract class JettyHandler extends HttpServlet implements ServerHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(JettyHandler.class);
|
||||
|
||||
public abstract String pathSpec();
|
||||
|
||||
@Override
|
||||
protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected final void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
reply(resp, doGet(req));
|
||||
} catch (ArgumentsParseException e) {
|
||||
replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
|
||||
} catch (ArgumentsParseException | IOException e) {
|
||||
try {
|
||||
replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
|
||||
} catch (IOException replyException) {
|
||||
logger.error(replyException.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException;
|
||||
|
||||
@Override
|
||||
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
reply(resp, doPost(req));
|
||||
} catch (ArgumentsParseException e) {
|
||||
replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
|
||||
} catch (ArgumentsParseException | IOException e) {
|
||||
try {
|
||||
replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
|
||||
} catch (IOException replyException) {
|
||||
logger.error(replyException.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue