Search in sources :

Example 31 with Request

use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.

the class FormAuthenticator method prepareRequest.

/* ------------------------------------------------------------ */
@Override
public void prepareRequest(ServletRequest request) {
    //if this is a request resulting from a redirect after auth is complete
    //(ie its from a redirect to the original request uri) then due to 
    //browser handling of 302 redirects, the method may not be the same as
    //that of the original request. Replace the method and original post
    //params (if it was a post).
    //
    //See Servlet Spec 3.1 sec 13.6.3
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpSession session = httpRequest.getSession(false);
    if (session == null || session.getAttribute(SessionAuthentication.__J_AUTHENTICATED) == null)
        //not authenticated yet
        return;
    String juri = (String) session.getAttribute(__J_URI);
    if (juri == null || juri.length() == 0)
        //no original uri saved
        return;
    String method = (String) session.getAttribute(__J_METHOD);
    if (method == null || method.length() == 0)
        //didn't save original request method
        return;
    StringBuffer buf = httpRequest.getRequestURL();
    if (httpRequest.getQueryString() != null)
        buf.append("?").append(httpRequest.getQueryString());
    if (!juri.equals(buf.toString()))
        //this request is not for the same url as the original
        return;
    //restore the original request's method on this request
    if (LOG.isDebugEnabled())
        LOG.debug("Restoring original method {} for {} with method {}", method, juri, httpRequest.getMethod());
    Request base_request = Request.getBaseRequest(request);
    base_request.setMethod(method);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest)

Example 32 with Request

use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.

the class PatternRuleTest method assertMatch.

private void assertMatch(boolean flag, String[] matchCase) throws IOException {
    _rule.setPattern(matchCase[0]);
    final String uri = matchCase[1];
    String result = _rule.matchAndApply(uri, new Request(null, null) {

        {
            setMetaData(new MetaData.Request("GET", new HttpURI(uri), HttpVersion.HTTP_1_0, new HttpFields()));
        }
    }, null);
    assertEquals("pattern: " + matchCase[0] + " uri: " + matchCase[1], flag, result != null);
}
Also used : HttpFields(org.eclipse.jetty.http.HttpFields) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 33 with Request

use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.

the class RegexRuleTest method assertMatch.

private void assertMatch(boolean flag, String[] matchCase) throws IOException {
    _rule.setRegex(matchCase[0]);
    final String uri = matchCase[1];
    String result = _rule.matchAndApply(uri, new Request(null, null) {

        @Override
        public String getRequestURI() {
            return uri;
        }
    }, null);
    assertEquals("regex: " + matchCase[0] + " uri: " + matchCase[1], flag, result != null);
}
Also used : Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 34 with Request

use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.

the class RewriteHandlerTest method init.

@Before
public void init() throws Exception {
    _handler = new RewriteHandler();
    _handler.setServer(_server);
    _handler.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            response.setStatus(201);
            request.setAttribute("target", target);
            request.setAttribute("URI", request.getRequestURI());
            request.setAttribute("info", request.getPathInfo());
        }
    });
    _handler.start();
    _rule1 = new RewritePatternRule();
    _rule1.setPattern("/aaa/*");
    _rule1.setReplacement("/bbb");
    _rule2 = new RewritePatternRule();
    _rule2.setPattern("/bbb/*");
    _rule2.setReplacement("/ccc");
    _rule3 = new RewritePatternRule();
    _rule3.setPattern("/ccc/*");
    _rule3.setReplacement("/ddd");
    _rule4 = new RewriteRegexRule();
    _rule4.setRegex("/xxx/(.*)");
    _rule4.setReplacement("/$1/zzz");
    _handler.setRules(new Rule[] { _rule1, _rule2, _rule3, _rule4 });
    start(false);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Before(org.junit.Before)

Example 35 with Request

use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.

the class ScopedHandlerTest method testDouble.

@Test
public void testDouble() throws Exception {
    Request request = new Request(null, null);
    Response response = new Response(null, null);
    TestHandler handler0 = new TestHandler("0");
    OtherHandler handlerA = new OtherHandler("A");
    TestHandler handler1 = new TestHandler("1");
    OtherHandler handlerB = new OtherHandler("B");
    handler0.setServer(new Server());
    handlerA.setServer(handler0.getServer());
    handler1.setServer(handler0.getServer());
    handlerB.setServer(handler0.getServer());
    handler0.setHandler(handlerA);
    handlerA.setHandler(handler1);
    handler1.setHandler(handlerB);
    handler0.start();
    handler0.handle("target", request, request, response);
    handler0.stop();
    String history = _history.toString();
    assertEquals(">S0>S1>W0>HA>W1>HB<HB<W1<HA<W0<S1<S0", history);
}
Also used : Response(org.eclipse.jetty.server.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Server(org.eclipse.jetty.server.Server) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Test(org.junit.Test)

Aggregations

Request (org.eclipse.jetty.server.Request)248 HttpServletRequest (javax.servlet.http.HttpServletRequest)223 HttpServletResponse (javax.servlet.http.HttpServletResponse)200 Test (org.junit.Test)182 IOException (java.io.IOException)151 ServletException (javax.servlet.ServletException)137 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)129 CountDownLatch (java.util.concurrent.CountDownLatch)65 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)64 InterruptedIOException (java.io.InterruptedIOException)45 InputStream (java.io.InputStream)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)34 Server (org.eclipse.jetty.server.Server)29 Response (org.eclipse.jetty.client.api.Response)27 Result (org.eclipse.jetty.client.api.Result)27 ByteArrayInputStream (java.io.ByteArrayInputStream)26 ServletInputStream (javax.servlet.ServletInputStream)23 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)23 ServletOutputStream (javax.servlet.ServletOutputStream)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21