Package org.eclipse.jetty.server

Examples of org.eclipse.jetty.server.Request


                            {
                              HttpChannel channel = HttpChannel.getCurrentHttpChannel();

                                if (channel == null)
                                    return;
                                Request request = channel.getRequest();

                                if (request != null)
                                {
                                    RequestParameterCallback rpc = (RequestParameterCallback)callback;
                                    rpc.setParameterValues(Arrays.asList(request.getParameterValues(rpc.getParameterName())));
                                }
                            }
                            else
                                throw new UnsupportedCallbackException(callback);
                        }
View Full Code Here


        /* ------------------------------------------------------------ */
        @Override
        public void doFilter(ServletRequest request, ServletResponse response)
            throws IOException, ServletException
        {
            final Request baseRequest=(request instanceof Request)?((Request)request):HttpChannel.getCurrentHttpChannel().getRequest();

            // pass to next filter
            if (_filterHolder!=null)
            {
                if (LOG.isDebugEnabled())
                    LOG.debug("call filter " + _filterHolder);
                Filter filter= _filterHolder.getFilter();
                if (_filterHolder.isAsyncSupported())
                    filter.doFilter(request, response, _next);
                else
                {
                    final boolean suspendable=baseRequest.isAsyncSupported();
                    if (suspendable)
                    {
                        try
                        {
                            baseRequest.setAsyncSupported(false);
                            filter.doFilter(request, response, _next);
                        }
                        finally
                        {
                            baseRequest.setAsyncSupported(true);
                        }
                    }
                    else
                        filter.doFilter(request, response, _next);
                }
View Full Code Here

            }
            else if (getHandler()==null)
                notFound(srequest, (HttpServletResponse)response);
            else
            {
                Request baseRequest=(request instanceof Request)?((Request)request):HttpChannel.getCurrentHttpChannel().getRequest();
                nextHandle(URIUtil.addPaths(srequest.getServletPath(),srequest.getPathInfo()),
                           baseRequest,srequest,(HttpServletResponse)response);
            }
        }
View Full Code Here

    @Test
    public void testWriteLog()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);
        final Principal principal = mock(Principal.class);

        final long timeToFirstByte = 456;
        final long timeToLastByte = 3453;
        final long now = System.currentTimeMillis();
        final long timestamp = now - timeToLastByte;
        final String user = "martin";
        final String agent = "HttpClient 4.0";
        final String referrer = "http://www.google.com";
        final String ip = "4.4.4.4";
        final String protocol = "protocol";
        final String method = "GET";
        final long requestSize = 5432;
        final String requestContentType = "request/type";
        final long responseSize = 32311;
        final int responseCode = 200;
        final String responseContentType = "response/type";
        final HttpURI uri = new HttpURI("http://www.example.com/aaa+bbb/ccc?param=hello%20there&other=true");


        final TraceTokenManager tokenManager = new TraceTokenManager();
        MockCurrentTimeMillisProvider currentTimeMillisProvider = new MockCurrentTimeMillisProvider(timestamp + timeToLastByte);
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 1_000_000_000, tokenManager, currentTimeMillisProvider);

        when(principal.getName()).thenReturn(user);
        when(request.getTimeStamp()).thenReturn(timestamp);
        when(request.getHeader("User-Agent")).thenReturn(agent);
        when(request.getHeader("Referer")).thenReturn(referrer);
        when(request.getRemoteAddr()).thenReturn("9.9.9.9");
        when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of("1.1.1.1, 2.2.2.2", "3.3.3.3, " + ip)));
        when(request.getProtocol()).thenReturn("unknown");
        when(request.getHeader("X-FORWARDED-PROTO")).thenReturn(protocol);
        when(request.getAttribute(TimingFilter.FIRST_BYTE_TIME)).thenReturn(timestamp + timeToFirstByte);
        when(request.getUri()).thenReturn(uri);
        when(request.getUserPrincipal()).thenReturn(principal);
        when(request.getMethod()).thenReturn(method);
        when(request.getContentRead()).thenReturn(requestSize);
        when(request.getHeader("Content-Type")).thenReturn(requestContentType);
        when(response.getStatus()).thenReturn(responseCode);
        when(response.getContentCount()).thenReturn(responseSize);
        when(response.getHeader("Content-Type")).thenReturn(responseContentType);

        tokenManager.createAndRegisterNewRequestToken();
        long currentTime = currentTimeMillisProvider.getCurrentTimeMillis();
        logger.log(request, response);
        logger.stop();

        String actual = Files.toString(file, Charsets.UTF_8);
        String expected = String.format("%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%s\n",
                isoFormatter.print(timestamp),
                ip,
                method,
                uri,
                user,
                agent,
                responseCode,
                requestSize,
                responseSize,
                currentTime - request.getTimeStamp(),
                tokenManager.getCurrentRequestToken());
        Assert.assertEquals(actual, expected);
    }
View Full Code Here

            }

            @Override
            public void onComplete(AsyncEvent event) throws IOException {
                final HttpChannelState state = (HttpChannelState) event.getAsyncContext();
                final Request request = state.getBaseRequest();
                activeRequests.dec();
                updateResponses(request);
                if (!state.isDispatched()) {
                    activeSuspended.dec();
                }
View Full Code Here

    @Test
    public void testWriteLog()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);
        final Principal principal = mock(Principal.class);

        final long timeToFirstByte = 456;
        final long timeToLastByte = 3453;
        final long now = System.currentTimeMillis();
        final long timestamp = now - timeToLastByte;
        final String user = "martin";
        final String agent = "HttpClient 4.0";
        final String referrer = "http://www.google.com";
        final String ip = "4.4.4.4";
        final String protocol = "protocol";
        final String method = "GET";
        final long requestSize = 5432;
        final String requestContentType = "request/type";
        final long responseSize = 32311;
        final int responseCode = 200;
        final String responseContentType = "response/type";
        final HttpURI uri = new HttpURI("http://www.example.com/aaa+bbb/ccc?param=hello%20there&other=true");


        final TraceTokenManager tokenManager = new TraceTokenManager();
        InMemoryEventClient eventClient = new InMemoryEventClient();
        MockCurrentTimeMillisProvider currentTimeMillisProvider = new MockCurrentTimeMillisProvider(timestamp + timeToLastByte);
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, tokenManager, eventClient, currentTimeMillisProvider);

        when(principal.getName()).thenReturn(user);
        when(request.getTimeStamp()).thenReturn(timestamp);
        when(request.getHeader("User-Agent")).thenReturn(agent);
        when(request.getHeader("Referer")).thenReturn(referrer);
        when(request.getRemoteAddr()).thenReturn("9.9.9.9");
        when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of("1.1.1.1, 2.2.2.2", "3.3.3.3, " + ip)));
        when(request.getProtocol()).thenReturn("unknown");
        when(request.getHeader("X-FORWARDED-PROTO")).thenReturn(protocol);
        when(request.getAttribute(TimingFilter.FIRST_BYTE_TIME)).thenReturn(timestamp + timeToFirstByte);
        when(request.getUri()).thenReturn(uri);
        when(request.getUserPrincipal()).thenReturn(principal);
        when(request.getMethod()).thenReturn(method);
        when(request.getContentRead()).thenReturn(requestSize);
        when(request.getHeader("Content-Type")).thenReturn(requestContentType);
        when(response.getStatus()).thenReturn(responseCode);
        when(response.getContentCount()).thenReturn(responseSize);
        when(response.getHeader("Content-Type")).thenReturn(responseContentType);

        tokenManager.createAndRegisterNewRequestToken();
View Full Code Here

    @Test
    public void testNoXForwardedProto()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);
        final String protocol = "protocol";

        when(request.getScheme()).thenReturn("protocol");

        InMemoryEventClient eventClient = new InMemoryEventClient();
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, null, eventClient);
        logger.log(request, response);
        logger.stop();
View Full Code Here

    @Test
    public void testNoTimeToFirstByte()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);

        InMemoryEventClient eventClient = new InMemoryEventClient();
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, null, eventClient);
        logger.log(request, response);
View Full Code Here

    @Test
    public void testNoXForwardedFor()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);
        final String clientIp = "1.1.1.1";

        when(request.getRemoteAddr()).thenReturn(clientIp);

        InMemoryEventClient eventClient = new InMemoryEventClient();
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, null, eventClient);
        logger.log(request, response);
        logger.stop();
View Full Code Here

    @Test
    public void testXForwardedForSkipPrivateAddresses()
            throws Exception
    {
        final Request request = mock(Request.class);
        final Response response = mock(Response.class);
        final String clientIp = "1.1.1.1";

        when(request.getRemoteAddr()).thenReturn("9.9.9.9");
        when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));

        InMemoryEventClient eventClient = new InMemoryEventClient();
        DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, null, eventClient);
        logger.log(request, response);
        logger.stop();
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.