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();
}
}
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();
}
}
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"));
}
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"));
}
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();
}
Aggregations