use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.
the class ContextHandlerTest method checkWildcardHost.
private void checkWildcardHost(boolean succeed, Server server, String[] contextHosts, String[] requestHosts) throws Exception {
LocalConnector connector = (LocalConnector) server.getConnectors()[0];
ContextHandler context = (ContextHandler) server.getHandler();
context.setVirtualHosts(contextHosts);
IsHandledHandler handler = (IsHandledHandler) context.getHandler();
for (String host : requestHosts) {
connector.getResponse("GET / HTTP/1.1\n" + "Host: " + host + "\nConnection:close\n\n");
if (succeed)
Assert.assertTrue("'" + host + "' should have been handled.", handler.isHandled());
else
Assert.assertFalse("'" + host + "' should not have been handled.", handler.isHandled());
handler.reset();
}
}
use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.
the class ContextHandlerTest method testVirtualHostNormalization.
@Test
public void testVirtualHostNormalization() throws Exception {
Server server = new Server();
LocalConnector connector = new LocalConnector(server);
server.setConnectors(new Connector[] { connector });
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[] { "www.example2.com." });
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);
try {
server.start();
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: www.example2.com\n\n");
Assert.assertFalse(handlerA.isHandled());
Assert.assertTrue(handlerB.isHandled());
Assert.assertFalse(handlerC.isHandled());
} finally {
server.stop();
}
}
use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.
the class ContextHandlerCollectionTest method checkWildcardHost.
private void checkWildcardHost(boolean succeed, Server server, String[] contextHosts, String[] requestHosts) throws Exception {
LocalConnector connector = (LocalConnector) server.getConnectors()[0];
ContextHandlerCollection handlerCollection = (ContextHandlerCollection) server.getHandler();
ContextHandler context = (ContextHandler) handlerCollection.getHandlers()[0];
IsHandledHandler handler = (IsHandledHandler) context.getHandler();
context.setVirtualHosts(contextHosts);
// trigger this manually; it's supposed to be called when adding the handler
handlerCollection.mapContexts();
for (String host : requestHosts) {
// System.err.printf("host=%s in %s%n",host,contextHosts==null?Collections.emptyList():Arrays.asList(contextHosts));
String response = connector.getResponse("GET / HTTP/1.0\n" + "Host: " + host + "\nConnection:close\n\n");
// System.err.println(response);
if (succeed)
assertTrue("'" + host + "' should have been handled.", handler.isHandled());
else
assertFalse("'" + host + "' should not have been handled.", handler.isHandled());
handler.reset();
}
}
use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.
the class WebAppContextTest method testNullPath.
@Test
public void testNullPath() throws Exception {
Server server = new Server(0);
HandlerList handlers = new HandlerList();
ContextHandlerCollection contexts = new ContextHandlerCollection();
WebAppContext context = new WebAppContext();
context.setBaseResource(Resource.newResource("./src/test/webapp"));
context.setContextPath("/");
server.setHandler(handlers);
handlers.addHandler(contexts);
contexts.addHandler(context);
LocalConnector connector = new LocalConnector(server);
server.addConnector(connector);
server.start();
try {
String response = connector.getResponses("GET http://localhost:8080 HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n");
Assert.assertTrue(response.indexOf("200 OK") >= 0);
} finally {
server.stop();
}
}
use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.
the class ServletContextHandlerTest method createServer.
@Before
public void createServer() {
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
__testServlets.set(0);
}
Aggregations