Java 类org.eclipse.jetty.server.Dispatcher 实例源码

项目:marathon-auth-plugin    文件:ServletContextHandler.java   
@Override
public RequestDispatcher getNamedDispatcher(String name)
{
    ContextHandler context=org.eclipse.jetty.servlet.ServletContextHandler.this;
    if (_servletHandler==null)
        return null;
    ServletHolder holder = _servletHandler.getServlet(name);
    if (holder==null || !holder.isEnabled())
        return null;
    return new Dispatcher(context, name);
}
项目:elasticsearch-jetty-cat    文件:JettyHttpServerErrorHandler.java   
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
    connection.getRequest().setHandled(true);
    response.setContentType(MimeTypes.TEXT_PLAIN_8859_1);
    ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
    writer.write(request.getAttribute(Dispatcher.ERROR_STATUS_CODE) + " " +
                 request.getAttribute(Dispatcher.ERROR_MESSAGE) + " " +
                 request.getAttribute(Dispatcher.ERROR_REQUEST_URI));
    writer.flush();
    response.setContentLength(writer.size());
    writer.writeTo(response.getOutputStream());
    writer.destroy();
}
项目:heroic    文件:JettyJSONErrorHandler.java   
@Override
public void handle(
    String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response
) throws IOException {
    baseRequest.setHandled(true);
    response.setContentType(CONTENT_TYPE);

    final String message;
    final javax.ws.rs.core.Response.Status status;

    if (response instanceof Response) {
        final Response r = (Response) response;
        status = javax.ws.rs.core.Response.Status.fromStatusCode(r.getStatus());
    } else {
        status = javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
    }

    final Throwable cause = (Throwable) request.getAttribute(Dispatcher.ERROR_EXCEPTION);

    if (cause != null && cause.getMessage() != null) {
        message = cause.getMessage();
    } else if (cause instanceof NullPointerException) {
        message = "NPE";
    } else {
        message = status.getReasonPhrase();
    }

    final InternalErrorMessage info = new InternalErrorMessage(message, status);

    response.setStatus(status.getStatusCode());

    try (final ByteArrayOutputStream output = new ByteArrayOutputStream(4096)) {
        final OutputStreamWriter writer = new OutputStreamWriter(output, Charsets.UTF_8);
        mapper.writeValue(writer, info);
        response.setContentLength(output.size());
        output.writeTo(response.getOutputStream());
    }
}