Search in sources :

Example 6 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ContextHandlerTest method testNamedConnector.

@Test
public void testNamedConnector() throws Exception {
    Server server = new Server();
    LocalConnector connector = new LocalConnector(server);
    LocalConnector connectorN = new LocalConnector(server);
    connectorN.setName("name");
    server.setConnectors(new Connector[] { connector, connectorN });
    ContextHandler contextA = new ContextHandler("/");
    contextA.setVirtualHosts(new String[] { "www.example.com" });
    IsHandledHandler handlerA = new IsHandledHandler();
    contextA.setHandler(handlerA);
    ContextHandler contextB = new ContextHandler("/");
    IsHandledHandler handlerB = new IsHandledHandler();
    contextB.setHandler(handlerB);
    contextB.setVirtualHosts(new String[] { "@name" });
    ContextHandler contextC = new ContextHandler("/");
    IsHandledHandler handlerC = new IsHandledHandler();
    contextC.setHandler(handlerC);
    HandlerCollection c = new HandlerCollection();
    c.addHandler(contextA);
    c.addHandler(contextB);
    c.addHandler(contextC);
    server.setHandler(c);
    server.start();
    try {
        connector.getResponses("GET / HTTP/1.0\n" + "Host: www.example.com.\n\n");
        Assert.assertTrue(handlerA.isHandled());
        Assert.assertFalse(handlerB.isHandled());
        Assert.assertFalse(handlerC.isHandled());
        handlerA.reset();
        handlerB.reset();
        handlerC.reset();
        connector.getResponses("GET / HTTP/1.0\n" + "Host: localhost\n\n");
        Assert.assertFalse(handlerA.isHandled());
        Assert.assertFalse(handlerB.isHandled());
        Assert.assertTrue(handlerC.isHandled());
        handlerA.reset();
        handlerB.reset();
        handlerC.reset();
        connectorN.getResponses("GET / HTTP/1.0\n" + "Host: www.example.com.\n\n");
        Assert.assertTrue(handlerA.isHandled());
        Assert.assertFalse(handlerB.isHandled());
        Assert.assertFalse(handlerC.isHandled());
        handlerA.reset();
        handlerB.reset();
        handlerC.reset();
        connectorN.getResponses("GET / HTTP/1.0\n" + "Host: localhost\n\n");
        Assert.assertFalse(handlerA.isHandled());
        Assert.assertTrue(handlerB.isHandled());
        Assert.assertFalse(handlerC.isHandled());
        handlerA.reset();
        handlerB.reset();
        handlerC.reset();
    } finally {
        server.stop();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Test(org.junit.Test)

Example 7 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ContextHandlerTest method testVirtualHostWildcard.

@Test
public void testVirtualHostWildcard() throws Exception {
    Server server = new Server();
    LocalConnector connector = new LocalConnector(server);
    server.setConnectors(new Connector[] { connector });
    ContextHandler context = new ContextHandler("/");
    IsHandledHandler handler = new IsHandledHandler();
    context.setHandler(handler);
    server.setHandler(context);
    try {
        server.start();
        checkWildcardHost(true, server, null, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { null }, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(true, server, new String[] { "example.com", "*.example.com" }, new String[] { "example.com", ".example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { "example.com", "*.example.com" }, new String[] { "badexample.com", ".badexample.com", "vhost.badexample.com" });
        checkWildcardHost(false, server, new String[] { "*." }, new String[] { "anything.anything" });
        checkWildcardHost(true, server, new String[] { "*.example.com" }, new String[] { "vhost.example.com", ".example.com" });
        checkWildcardHost(false, server, new String[] { "*.example.com" }, new String[] { "vhost.www.example.com", "example.com", "www.vhost.example.com" });
        checkWildcardHost(true, server, new String[] { "*.sub.example.com" }, new String[] { "vhost.sub.example.com", ".sub.example.com" });
        checkWildcardHost(false, server, new String[] { "*.sub.example.com" }, new String[] { ".example.com", "sub.example.com", "vhost.example.com" });
        checkWildcardHost(false, server, new String[] { "example.*.com", "example.com.*" }, new String[] { "example.vhost.com", "example.com.vhost", "example.com" });
    } finally {
        server.stop();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Test(org.junit.Test)

Example 8 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ContextHandlerTest method testContextGetContext.

@Test
public void testContextGetContext() throws Exception {
    Server server = new Server();
    LocalConnector connector = new LocalConnector(server);
    server.setConnectors(new Connector[] { connector });
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    server.setHandler(contexts);
    ContextHandler rootA = new ContextHandler(contexts, "/");
    ContextHandler fooA = new ContextHandler(contexts, "/foo");
    ContextHandler foobarA = new ContextHandler(contexts, "/foo/bar");
    server.start();
    // System.err.println(server.dump());
    Assert.assertEquals(rootA._scontext, rootA._scontext.getContext("/"));
    Assert.assertEquals(fooA._scontext, rootA._scontext.getContext("/foo"));
    Assert.assertEquals(foobarA._scontext, rootA._scontext.getContext("/foo/bar"));
    Assert.assertEquals(foobarA._scontext, rootA._scontext.getContext("/foo/bar/bob.jsp"));
    Assert.assertEquals(rootA._scontext, rootA._scontext.getContext("/other"));
    Assert.assertEquals(fooA._scontext, rootA._scontext.getContext("/foo/other"));
    Assert.assertEquals(rootA._scontext, foobarA._scontext.getContext("/"));
    Assert.assertEquals(fooA._scontext, foobarA._scontext.getContext("/foo"));
    Assert.assertEquals(foobarA._scontext, foobarA._scontext.getContext("/foo/bar"));
    Assert.assertEquals(foobarA._scontext, foobarA._scontext.getContext("/foo/bar/bob.jsp"));
    Assert.assertEquals(rootA._scontext, foobarA._scontext.getContext("/other"));
    Assert.assertEquals(fooA._scontext, foobarA._scontext.getContext("/foo/other"));
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Test(org.junit.Test)

Example 9 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ContextHandlerTest method testContextVirtualGetContext.

@Test
public void testContextVirtualGetContext() throws Exception {
    Server server = new Server();
    LocalConnector connector = new LocalConnector(server);
    server.setConnectors(new Connector[] { connector });
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    server.setHandler(contexts);
    ContextHandler rootA = new ContextHandler(contexts, "/");
    rootA.setVirtualHosts(new String[] { "a.com" });
    ContextHandler rootB = new ContextHandler(contexts, "/");
    rootB.setVirtualHosts(new String[] { "b.com" });
    ContextHandler rootC = new ContextHandler(contexts, "/");
    rootC.setVirtualHosts(new String[] { "c.com" });
    ContextHandler fooA = new ContextHandler(contexts, "/foo");
    fooA.setVirtualHosts(new String[] { "a.com" });
    ContextHandler fooB = new ContextHandler(contexts, "/foo");
    fooB.setVirtualHosts(new String[] { "b.com" });
    ContextHandler foobarA = new ContextHandler(contexts, "/foo/bar");
    foobarA.setVirtualHosts(new String[] { "a.com" });
    server.start();
    // System.err.println(server.dump());
    Assert.assertEquals(rootA._scontext, rootA._scontext.getContext("/"));
    Assert.assertEquals(fooA._scontext, rootA._scontext.getContext("/foo"));
    Assert.assertEquals(foobarA._scontext, rootA._scontext.getContext("/foo/bar"));
    Assert.assertEquals(foobarA._scontext, rootA._scontext.getContext("/foo/bar/bob"));
    Assert.assertEquals(rootA._scontext, rootA._scontext.getContext("/other"));
    Assert.assertEquals(rootB._scontext, rootB._scontext.getContext("/other"));
    Assert.assertEquals(rootC._scontext, rootC._scontext.getContext("/other"));
    Assert.assertEquals(fooB._scontext, rootB._scontext.getContext("/foo/other"));
    Assert.assertEquals(rootC._scontext, rootC._scontext.getContext("/foo/other"));
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Test(org.junit.Test)

Example 10 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class RequestLogTest method before.

@Before
public void before() throws Exception {
    _log = new Exchanger<String>();
    _server = new Server();
    _connector = new LocalConnector(_server);
    _server.addConnector(_connector);
    _server.setRequestLog(new Log());
    _server.setHandler(new TestHandler());
    _server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) AbstractNCSARequestLog(org.eclipse.jetty.server.AbstractNCSARequestLog) LocalConnector(org.eclipse.jetty.server.LocalConnector) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before)

Aggregations

LocalConnector (org.eclipse.jetty.server.LocalConnector)47 Server (org.eclipse.jetty.server.Server)43 Before (org.junit.Before)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)13 Test (org.junit.Test)12 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BeforeClass (org.junit.BeforeClass)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)6 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 Password (org.eclipse.jetty.util.security.Password)4 File (java.io.File)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 HandlerList (org.eclipse.jetty.server.handler.HandlerList)3 Path (java.nio.file.Path)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2