Search in sources :

Example 1 with BasicTestingServlet

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

the class TestOSGiService method testCanRegisterServlet.

/**
 * Can register a servlet with the HTTPService
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCanRegisterServlet() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    httpService.registerServlet("/", new BasicTestingServlet(), null, null);
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService)

Example 2 with BasicTestingServlet

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

the class TestOSGiService method testCannotRegisterInvalidAlias.

/**
 * Test invalid aliases throw NamespaceException.
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCannotRegisterInvalidAlias() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    String[] badAliases = { "noslash" };
    for (int i = 0; i < badAliases.length; ++i) {
        boolean namespaceExceptionThrown = false;
        try {
            httpService.registerServlet(badAliases[i], new BasicTestingServlet(), null, null);
        } catch (NamespaceException e) {
            namespaceExceptionThrown = true;
        }
    }
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService) NamespaceException(org.osgi.service.http.NamespaceException)

Example 3 with BasicTestingServlet

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

the class TestOSGiService method testCanReregisterAlias.

/**
 * Test that an alias can be registered after it's been previously registered and then unregistered.
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCanReregisterAlias() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
    httpService.unregister("/alias");
    httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService)

Example 4 with BasicTestingServlet

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

the class TestOSGiService method testCannotRegisterSameAliasTwice.

/**
 * Test that HTTP Service does not allow same alias to be registered twice.
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCannotRegisterSameAliasTwice() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    boolean namespaceExceptionThrown = false;
    httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
    try {
        httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
    } catch (NamespaceException e) {
        namespaceExceptionThrown = true;
    }
    assertTrue(namespaceExceptionThrown);
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService) NamespaceException(org.osgi.service.http.NamespaceException)

Example 5 with BasicTestingServlet

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

the class TestParameters method testCorrectParameterCount.

// TODO: test unicode parameters
// TODO: test parameters with empty values
// TODO: test parameter name collision
/**
 * @throws ServletException
 * @throws NamespaceException
 * @throws IOException
 */
public void testCorrectParameterCount() 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", "GET");
    int parameterCount = 16;
    for (int i = 0; i < parameterCount; ++i) {
        client.addRequestProperty("k" + i, "v" + i);
    }
    client.connect();
    assertTrue(client.getResponseCode() == 200);
    int headerCount = 0;
    Enumeration e = testServlet.getHeaderNames();
    while (e.hasMoreElements()) {
        headerCount++;
        System.out.println("header: " + e.nextElement().toString());
    }
    assertTrue(headerCount >= parameterCount);
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpURLConnection(java.net.HttpURLConnection) Enumeration(java.util.Enumeration) 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