use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class JspIncludeTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
// Setup Server
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
// Setup WebAppContext
File testWebAppDir = MavenTestingUtils.getProjectDir("src/test/webapp");
// Prepare WebApp libs
File libDir = new File(testWebAppDir, "WEB-INF/lib");
FS.ensureDirExists(libDir);
File testTagLibDir = MavenTestingUtils.getProjectDir("src/test/taglibjar");
JAR.create(testTagLibDir, new File(libDir, "testtaglib.jar"));
// Configure WebAppContext
Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
WebAppContext context = new WebAppContext();
context.setContextPath("/");
File scratchDir = MavenTestingUtils.getTargetFile("tests/" + JspIncludeTest.class.getSimpleName() + "-scratch");
FS.ensureEmpty(scratchDir);
JspConfig.init(context, testWebAppDir.toURI(), scratchDir);
server.setHandler(context);
// Start Server
server.start();
// Figure out Base URI
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
baseUri = new URI(String.format("http://%s:%d/", host, port));
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class OneConnector method main.
public static void main(String[] args) throws Exception {
// The Server
Server server = new Server();
// HTTP connector
ServerConnector http = new ServerConnector(server);
http.setHost("localhost");
http.setPort(8080);
http.setIdleTimeout(30000);
// Set the connector
server.addConnector(http);
// Set a handler
server.setHandler(new HelloHandler());
// Start the server
server.start();
server.join();
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class ProxyServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxy = new ConnectHandler();
server.setHandler(proxy);
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
context.addServlet(proxyServlet, "/*");
server.start();
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class AbstractHttpClientServerTest method start.
public void start(Handler handler) throws Exception {
server = new Server();
ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration());
serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
connector = new ServerConnector(server, null, null, serverBufferPool, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory);
// connector.setPort(9000);
server.addConnector(connector);
server.setHandler(handler);
server.start();
QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client");
client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") {
@Override
public HttpDestination newHttpDestination(Origin origin) {
return new HttpDestinationOverFCGI(client, origin) {
@Override
protected DuplexConnectionPool newConnectionPool(HttpClient client) {
return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) {
@Override
protected void leaked(LeakDetector.LeakInfo leakInfo) {
connectionLeaks.incrementAndGet();
}
};
}
};
}
}, null);
client.setExecutor(executor);
clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
client.setByteBufferPool(clientBufferPool);
client.start();
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class FastCGIProxyServletTest method prepare.
public void prepare(HttpServlet servlet) throws Exception {
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
httpConnector = new ServerConnector(server);
server.addConnector(httpConnector);
fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration(), sendStatus200));
server.addConnector(fcgiConnector);
final String contextPath = "/";
context = new ServletContextHandler(server, contextPath);
final String servletPath = "/script";
FastCGIProxyServlet fcgiServlet = new FastCGIProxyServlet() {
@Override
protected String rewriteTarget(HttpServletRequest request) {
return "http://localhost:" + fcgiConnector.getLocalPort() + servletPath + request.getServletPath();
}
};
ServletHolder fcgiServletHolder = new ServletHolder(fcgiServlet);
fcgiServletHolder.setName("fcgi");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, "/scriptRoot");
fcgiServletHolder.setInitParameter("proxyTo", "http://localhost");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
context.addServlet(fcgiServletHolder, "*.php");
context.addServlet(new ServletHolder(servlet), servletPath + "/*");
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
client = new HttpClient();
client.setExecutor(clientThreads);
server.addBean(client);
server.start();
}
Aggregations