Package org.deftserver.web.http

Examples of org.deftserver.web.http.HttpRequest


   
   
    String requestLine = "GET / HTTP/1.1";
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("host", "localhost");
    HttpRequest request = new HttpRequest(requestLine, headers);
   
   
    assertNotNull(app.getHandler(request));
   
    requestLine = "GET /persons/1911 HTTP/1.1";
    request = new HttpRequest(requestLine, headers);
    assertNotNull(app.getHandler(request));
   
   
    requestLine = "GET /persons/phone_numbers HTTP/1.1";
    request = new HttpRequest(requestLine, headers);
    assertNotNull(app.getHandler(request));
   
    requestLine = "GET /pets/123 HTTP/1.1";
    request = new HttpRequest(requestLine, headers);
    assertNotNull(app.getHandler(request));
   
   
    request = new HttpRequest("GET /missing HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /persons HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /persons/roger HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /persons/123a HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /persons/a123 HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /pets/a123 HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /pets/123a HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET /pets/1234 HTTP/1.1", headers);
    assertEquals(NotFoundRequestHandler.getInstance(), app.getHandler(request));
   
    request = new HttpRequest("GET / HTTP/1.1", headers);
    assertEquals(handler1, app.getHandler(request));
   
    request = new HttpRequest("GET /persons/1911 HTTP/1.1", headers);
    assertEquals(handler2, app.getHandler(request));
   
    request = new HttpRequest("GET /persons/phone_numbers HTTP/1.1", headers);
    assertEquals(handler3, app.getHandler(request));
   
    request = new HttpRequest("GET /pets/123 HTTP/1.1", headers);
    assertEquals(handler4, app.getHandler(request));
   
    //Verify that BadRequestRequestHandler is returned if request does not include Host header
    headers = new HashMap<String, String>();
    request = new HttpRequest("GET /pets/123 HTTP/1.1", headers);
    assertEquals(BadRequestRequestHandler.getInstance(), app.getHandler(request));
   
  }
View Full Code Here


    helper.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    helper.addHeader("Keep-Alive", "115");
    helper.addHeader("Connection", "keep-alve");
    ByteBuffer bb2 = helper.getRequestAsByteBuffer();

    HttpRequest request1 = HttpRequest.of(bb1);
    HttpRequest request2 = HttpRequest.of(bb2);

    assertEquals("GET / HTTP/1.1", request1.getRequestLine());
    assertEquals("GET / HTTP/1.1", request2.getRequestLine());

    assertEquals(4, request1.getHeaders().size());
    assertEquals(9, request2.getHeaders().size());

    List<String> expectedHeaderNamesInRequest1 = Arrays.asList(new String[]{"User-Agent", "Host", "Accept", "From"});
    for (String expectedHeaderName : expectedHeaderNamesInRequest1) {
      assertTrue(request1.getHeaders().containsKey(expectedHeaderName.toLowerCase()));
    }

    List<String> expectedHeaderNamesInRequest2 = Arrays.asList(new String[]{"Host", "User-Agent", "Accept", "From",
        "Accept-Language", "Accept-Encoding", "Accept-Charset", "Keep-Alive", "Connection"});
    for (String expectedHeaderName : expectedHeaderNamesInRequest2) {
      assertTrue(request2.getHeaders().containsKey(expectedHeaderName.toLowerCase()));
    }

    // TODO RS 100920 verify that the headers exist
  }
View Full Code Here

  @Test
  public void testSingleGetParameter() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", "jim");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());

    assertEquals(1, request.getParameters().size());
    assertEquals("jim", request.getParameter("firstname"));
  }
View Full Code Here

    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", "jim");
    helper.addGetParameter("lastname", "petersson");
    helper.addGetParameter("city", "stockholm");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(3, getSize(params));
    assertEquals("jim", request.getParameter("firstname"));
    assertEquals("petersson", request.getParameter("lastname"));
    assertEquals("stockholm", request.getParameter("city"));
  }
View Full Code Here

  @Test
  public void testSingleParameterWithoutValue() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", null);

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();
    assertEquals(0, getSize(params));
    assertEquals(null, request.getParameter("firstname"));
  }
View Full Code Here

  public void testMultipleParametersWithoutValue() {
    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("firstname", null);
    helper.addGetParameter("lastName", "");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(0, getSize(params));
    assertEquals(null, request.getParameter("firstname"));
    assertEquals(null, request.getParameter("lastName"));
  }
View Full Code Here

    helper.addGetParameter("lastName", "petersson");
    helper.addGetParameter("city", "");
    helper.addGetParameter("phoneno", "12345");
    helper.addGetParameter("age", "30");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(3, getSize(params));
    assertEquals(null, request.getParameter("firstname"));
    assertEquals("petersson", request.getParameter("lastName"));
    assertEquals(null, request.getParameter("city"));
    assertEquals("12345", request.getParameter("phoneno"));
    assertEquals("30", request.getParameter("age"));
  }
View Full Code Here

    HttpRequestHelper helper = new HttpRequestHelper();
    helper.addGetParameter("letters", "x");
    helper.addGetParameter("letters", "y");
    helper.addGetParameter("letters", "z");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(3, getSize(params));
    Collection<String> values = params.get("letters");
    assertEquals(3, values.size());
    assertTrue(values.contains("x"));
View Full Code Here

    helper.addGetParameter("letters", "z");
    helper.addGetParameter("numbers", "23");
    helper.addGetParameter("numbers", "54");
    helper.addGetParameter("country", "swe");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(6, getSize(params));
    Collection<String> letters = params.get("letters");
    Collection<String> numbers = params.get("numbers");
    Collection<String> country = params.get("country");
View Full Code Here

    helper.addGetParameter("letters", "x");
    helper.addGetParameter("letters", "y");
    helper.addGetParameter("letters", null);
    helper.addGetParameter("letters", "z");

    HttpRequest request = HttpRequest.of(helper.getRequestAsByteBuffer());
    Map<String, Collection<String>> params = request.getParameters();

    assertEquals(3, getSize(params));
    Collection<String> values = params.get("letters");
    assertEquals(3, values.size());
    assertTrue(values.contains("x"));
View Full Code Here

TOP

Related Classes of org.deftserver.web.http.HttpRequest

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.