Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.jetty;
 
An org.eclipse.jetty.server.handler.ErrorHandler subclass which returns concise, text/plain error messages.
public class QuietErrorHandler extends ErrorHandler {
    private static final Log LOG = Log.forClass(QuietErrorHandler.class);
    private static final int RESPONSE_BUFFER_SIZE = 4096;
    /*
     * Sadly, this class is basically untestable.
     */
    private static final ImmutableSet<StringALLOWED_METHODS = ImmutableSet.of(
    );
    @Override
    public void handle(String target,
                       Request baseRequest,
                       HttpServletRequest request,
                       HttpServletResponse responsethrows IOException {
        final AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
        if (connection != null) {
            connection.getRequest().setHandled(true);
            final Response jettyResponse = connection.getResponse();
            jettyResponse.setStatus(jettyResponse.getStatus());
            connection.getRequest().setHandled(true);
            final String method = request.getMethod();
            if (!.contains(method)) {
                return;
            }
            response.setContentType(.);
            if (getCacheControl() != null) {
                response.setHeader(.getCacheControl());
            }
            final StringBuilder builder = new StringBuilder();
            builder.append(errorMessage(requestjettyResponse.getStatus()))
                   .append('\n')
                   .append('\n');
            final byte[] bytes = builder.toString().getBytes(.);
            response.setContentLength(bytes.length);
            final ServletOutputStream output = response.getOutputStream();
            try {
                output.write(bytes);
            } finally {
                output.close();
            }
        }
    }
    private static String errorMessage(HttpServletRequest requestint status) {
        try {
            final ResourceBundle bundle = ResourceBundle.getBundle("HttpErrorMessages",
                                                                   request.getLocale());
            final String message = bundle.getString(Integer.toString(status));
            if (message != null) {
                final MessageFormat format = new MessageFormat(messagerequest.getLocale());
                return format.format(new Object[]{request.getMethod()});
            }
        } catch (MissingResourceException e) {
            .error(e"Unable to load HttpErrorMessages.properties");
        }
        return "Your request could not be processed: " + HttpGenerator.getReasonBuffer(status);
    }
New to GrepCode? Check out our FAQ X