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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations