Search in sources :

Example 1 with Request

use of org.mortbay.jetty.Request in project commons by twitter.

the class RequestLoggerTest method setUp.

@Before
public void setUp() throws Exception {
    clock = new FakeClock();
    sink = createMock(LogSink.class);
    request = createMock(Request.class);
    response = createMock(Response.class);
    log = new RequestLogger(clock, sink);
}
Also used : Response(org.mortbay.jetty.Response) LogSink(com.twitter.common.net.http.RequestLogger.LogSink) FakeClock(com.twitter.common.util.testing.FakeClock) Request(org.mortbay.jetty.Request) Before(org.junit.Before)

Example 2 with Request

use of org.mortbay.jetty.Request in project ambrose by twitter.

the class APIHandler method setHandled.

private static void setHandled(HttpServletRequest request) {
    Request base_request = (request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
    base_request.setHandled(true);
}
Also used : Request(org.mortbay.jetty.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 3 with Request

use of org.mortbay.jetty.Request in project tomee by apache.

the class JettyHttpServer method init.

@Override
public void init(final Properties props) throws Exception {
    final Options options = new Options(props);
    port = options.get("port", 8080);
    // Create all the Jetty objects but dont' start them
    server = new Server();
    final Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.setConnectors(new Connector[] { connector });
    final ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    final ServletContext servletContext = context.getServletContext();
    server.setHandler(context);
    final Handler handler = new AbstractHandler() {

        @Override
        public void handle(final String target, final HttpServletRequest req, final HttpServletResponse res, final int dispatch) throws IOException, ServletException {
            try {
                ((Request) req).setHandled(true);
                final HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
                final HttpResponse httpResponse = new ServletResponseAdapter(res);
                JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
            } catch (IOException | ServletException e) {
                throw e;
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
    };
    final SessionHandler sessionHandler = new SessionHandler();
    final SessionManager sessionManager = new HashSessionManager();
    sessionManager.setIdManager(new HashSessionIdManager());
    sessionHandler.setSessionManager(sessionManager);
    sessionHandler.setHandler(handler);
    context.setHandler(sessionHandler);
}
Also used : SessionHandler(org.mortbay.jetty.servlet.SessionHandler) Options(org.apache.openejb.loader.Options) Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) SessionManager(org.mortbay.jetty.SessionManager) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) Request(org.mortbay.jetty.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.mortbay.jetty.Handler) SessionHandler(org.mortbay.jetty.servlet.SessionHandler) ContextHandler(org.mortbay.jetty.handler.ContextHandler) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HashSessionIdManager(org.mortbay.jetty.servlet.HashSessionIdManager) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ServiceException(org.apache.openejb.server.ServiceException) ContextHandler(org.mortbay.jetty.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletContext(javax.servlet.ServletContext)

Example 4 with Request

use of org.mortbay.jetty.Request in project sonatype-aether by sonatype.

the class HttpServer method newSslRedirectHandler.

protected Handler newSslRedirectHandler() {
    return new AbstractHandler() {

        public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) {
            int httpsPort = getHttpsPort();
            if (!((Request) request).isHandled() && request.getServerPort() != httpsPort) {
                String url = "https://" + request.getServerName() + ":" + httpsPort + request.getRequestURI();
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                response.setHeader("Location", url);
                ((Request) request).setHandled(true);
            }
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.mortbay.jetty.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) Constraint(org.mortbay.jetty.security.Constraint)

Aggregations

Request (org.mortbay.jetty.Request)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AbstractHandler (org.mortbay.jetty.handler.AbstractHandler)2 LogSink (com.twitter.common.net.http.RequestLogger.LogSink)1 FakeClock (com.twitter.common.util.testing.FakeClock)1 IOException (java.io.IOException)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 Options (org.apache.openejb.loader.Options)1 ServiceException (org.apache.openejb.server.ServiceException)1 Before (org.junit.Before)1 Connector (org.mortbay.jetty.Connector)1 Handler (org.mortbay.jetty.Handler)1 Response (org.mortbay.jetty.Response)1 Server (org.mortbay.jetty.Server)1 SessionManager (org.mortbay.jetty.SessionManager)1 ContextHandler (org.mortbay.jetty.handler.ContextHandler)1 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)1 Constraint (org.mortbay.jetty.security.Constraint)1