Search in sources :

Example 11 with BasicTestingServlet

use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.

the class TestRequestPath method testMultipleSeperatorsRequestPath.

public void testMultipleSeperatorsRequestPath() throws ServletException, NamespaceException, IOException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    BasicTestingServlet testServlet = new BasicTestingServlet();
    httpService.registerServlet("/test", testServlet, null, null);
    HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test/a/b//c", "GET");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    assertTrue(testServlet.getPathInfo().equals("/a/b/c"));
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) HttpService(org.osgi.service.http.HttpService)

Example 12 with BasicTestingServlet

use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.

the class TestRequestPath method testSimpleRequestPath.

public void testSimpleRequestPath() throws ServletException, NamespaceException, IOException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    BasicTestingServlet testServlet = new BasicTestingServlet();
    httpService.registerServlet("/test", testServlet, null, null);
    HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test/a/b/c", "GET");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    assertTrue(testServlet.getPathInfo().equals("/a/b/c"));
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) HttpService(org.osgi.service.http.HttpService)

Example 13 with BasicTestingServlet

use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.

the class TestServletContainer method testExecutePUT.

/**
 * Test can execute PUT method.
 *
 * @throws ServletException
 * @throws NamespaceException
 * @throws IOException
 */
public void testExecutePUT() throws ServletException, NamespaceException, IOException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    BasicTestingServlet testServlet = new BasicTestingServlet();
    httpService.registerServlet("/test", testServlet, null, null);
    HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "PUT");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    assertFalse(testServlet.isGetCalled());
    assertFalse(testServlet.isDeleteCalled());
    assertFalse(testServlet.isPostCalled());
    assertTrue(testServlet.isPutCalled());
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) HttpService(org.osgi.service.http.HttpService)

Example 14 with BasicTestingServlet

use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.

the class TestServletContainer method testGETResponseStringContent.

/**
 * Test that container returns exact content as specified in servlet.
 *
 * @throws ServletException
 * @throws NamespaceException
 * @throws IOException
 */
public void testGETResponseStringContent() throws ServletException, NamespaceException, IOException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    String content = "test content";
    BasicTestingServlet testServlet = new BasicTestingServlet(content, false);
    httpService.registerServlet("/test", testServlet, null, null);
    HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    String response = readInputAsString(client.getInputStream());
    printBytes(content.getBytes());
    printBytes(response.getBytes());
    assertTrue(content.equals(response));
    httpService.unregister("/test");
    content = "test content";
    testServlet = new BasicTestingServlet(content, true);
    httpService.registerServlet("/test", testServlet, null, null);
    client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    response = readInputAsString(client.getInputStream());
    printBytes(content.getBytes());
    printBytes(response.getBytes());
    assertTrue(content.length() == response.length());
    assertTrue(content.equals(response));
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) HttpService(org.osgi.service.http.HttpService)

Example 15 with BasicTestingServlet

use of org.apache.felix.httplite.osgi.test.BasicTestingServlet in project felix by apache.

the class TestServletContainer method testGETResponseBinaryContent.

/**
 * Test that container returns exact content as specified in servlet.
 *
 * @throws ServletException
 * @throws NamespaceException
 * @throws IOException
 */
public void testGETResponseBinaryContent() throws ServletException, NamespaceException, IOException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    byte[] content = generateRandomBinaryContent();
    BasicTestingServlet testServlet = new BasicTestingServlet(content, false);
    httpService.registerServlet("/test", testServlet, null, null);
    HttpURLConnection client = getConnection(DEFAULT_BASE_URL + "/test", "GET");
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    byte[] response = readInputAsByteArray(client.getInputStream());
    printBytes(content);
    printBytes(response);
    assertTrue(content.length == response.length);
    for (int i = 0; i < content.length; ++i) {
        assertTrue(content[i] == response[i]);
    }
    httpService.unregister("/test");
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) HttpService(org.osgi.service.http.HttpService)

Aggregations

BasicTestingServlet (org.apache.felix.httplite.osgi.test.BasicTestingServlet)15 HttpService (org.osgi.service.http.HttpService)15 HttpURLConnection (java.net.HttpURLConnection)11 Enumeration (java.util.Enumeration)2 Map (java.util.Map)2 NamespaceException (org.osgi.service.http.NamespaceException)2 HashMap (java.util.HashMap)1