Package org.deftserver.web.handler

Examples of org.deftserver.web.handler.RequestHandler


          clientChannel,
          Timeout.newKeepAliveTimeout(clientChannel, KEEP_ALIVE_TIMEOUT)
      );
    }
    HttpResponse response = new HttpResponse(this, key, request.isKeepAlive());
    RequestHandler rh = application.getHandler(request);
    HttpRequestDispatcher.dispatch(rh, request, response);
   
    //Only close if not async. In that case its up to RH to close it (+ don't close if it's a partial request).
    if (!rh.isMethodAsynchronous(request.getMethod()) && ! (request instanceof PartialHttpRequest)) {
      response.finish();
    }
  }
View Full Code Here


public class ApplicationTest {
 
  @Test
  public void simpleApplicationTest() {
    Map<String, RequestHandler> handlers = new HashMap<String, RequestHandler>();
    final RequestHandler handler1 = new RequestHandler() {
      @Override public void get(HttpRequest request, HttpResponse response) { }
    };
    final RequestHandler handler2 = new RequestHandler() {
      @Override public void get(HttpRequest request, HttpResponse response) { }
    };
    final RequestHandler handler3 = new RequestHandler() {
      @Override public void get(HttpRequest request, HttpResponse response) { }
    };
    final RequestHandler handler4 = new RequestHandler() {
      @Override public void get(HttpRequest request, HttpResponse response) { }
    };
   
    handlers.put("/", handler1);
    handlers.put("/persons/([0-9]+)", handler2);
View Full Code Here

  }
 
  @Test(expected=PatternSyntaxException.class)
  public void malFormedRegularExpressionTest() {
    Map<String, RequestHandler> handlers = new HashMap<String, RequestHandler>();
    final RequestHandler handler1 = new RequestHandler() {
      @Override public void get(HttpRequest request, HttpResponse response) { }
    };
   
    handlers.put("/persons/([[0-9]{0,3})", handler1)// path contains malformed (a '[' too much) regex
    Application app = new Application(handlers);
View Full Code Here

   
  }

  @Test
  public void testAsynchronousAnnotations() {
    RequestHandler rh1 = new RequestHandler1();
    RequestHandler rh2 = new RequestHandler2();

    assertTrue(rh1.isMethodAsynchronous(HttpVerb.GET));
   
    assertFalse(rh2.isMethodAsynchronous(HttpVerb.GET));
    assertTrue(rh2.isMethodAsynchronous(HttpVerb.POST));
  }
View Full Code Here

    assertTrue(rh2.isMethodAsynchronous(HttpVerb.POST));
  }
 
  @Test
  public void testAuthenticatedAnnotations() {
    RequestHandler rh1 = new RequestHandler1();
    RequestHandler rh2 = new RequestHandler2();

    assertTrue(rh1.isMethodAuthenticated(HttpVerb.GET));
    assertFalse(rh1.isMethodAuthenticated(HttpVerb.POST));
    assertFalse(rh1.isMethodAuthenticated(HttpVerb.DELETE));
   
    assertFalse(rh2.isMethodAuthenticated(HttpVerb.GET));
    assertFalse(rh2.isMethodAuthenticated(HttpVerb.PUT));
    assertTrue(rh2.isMethodAuthenticated(HttpVerb.POST));
  }
View Full Code Here

   * @param path Requested path
   * @return Returns the {@link RequestHandler} associated with the given path. If no mapping exists a
   * {@link NotFoundRequestHandler} is returned.
   */
  private RequestHandler getHandler(String path) {
    RequestHandler rh = absoluteHandlers.get(path);
    if (rh == null) {
      // path could contain capturing groups which we could have a handler associated with.
      rh = getCapturingHandler(path);
      if (rh == null) {
        // path could be prefixed with the 'static content directory'
View Full Code Here

    if (!HttpUtil.verifyRequest(request)) {
      return BadRequestRequestHandler.getInstance();
    }
    // if @Authenticated annotation is present, make sure that the request/user is authenticated
    // (i.e RequestHandler.getCurrentUser() != null).
    RequestHandler rh = getHandler(request.getRequestedPath());;
    if (rh.isMethodAuthenticated(request.getMethod()) && rh.getCurrentUser(request) == null) {
      return ForbiddenRequestHandler.getInstance();
    }
    return rh;
  }
View Full Code Here

  private RequestHandler getCapturingHandler(String path) {
    int index = path.lastIndexOf("/");
    if (index != -1) {
      String init = path.substring(0, index+1)// path without its last segment
      String group = path.substring(index+1, path.length());
      RequestHandler handler = capturingHandlers.get(init);
      if (handler != null) {
        Pattern regex = patterns.get(handler);
        if (regex.matcher(group).matches()) {
          return handler;
        }
View Full Code Here

          clientChannel,
          Timeout.newKeepAliveTimeout(ioLoop, clientChannel, KEEP_ALIVE_TIMEOUT)
      );
    }
    HttpResponse response = new HttpResponse(this, key, request.isKeepAlive());
    RequestHandler rh = application.getHandler(request);
    HttpRequestDispatcher.dispatch(rh, request, response);
   
    //Only close if not async. In that case its up to RH to close it (+ don't close if it's a partial request).
    if (!rh.isMethodAsynchronous(request.getMethod()) && ! (request instanceof PartialHttpRequest)) {
      response.finish();
    }
  }
View Full Code Here

TOP

Related Classes of org.deftserver.web.handler.RequestHandler

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.