use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class ProxyTest method startProxy.
private void startProxy(HttpServlet proxyServlet, Map<String, String> initParams) throws Exception {
QueuedThreadPool proxyPool = new QueuedThreadPool();
proxyPool.setName("proxy");
proxy = new Server(proxyPool);
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendDateHeader(false);
configuration.setSendServerVersion(false);
String value = initParams.get("outputBufferSize");
if (value != null)
configuration.setOutputBufferSize(Integer.valueOf(value));
proxyConnector = new ServerConnector(proxy, new HTTP2ServerConnectionFactory(configuration));
proxy.addConnector(proxyConnector);
ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
proxyServletHolder.setInitParameters(initParams);
proxyContext.addServlet(proxyServletHolder, "/*");
proxy.start();
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class AsyncServletTest method testStartAsyncThenServerIdleTimeout.
private void testStartAsyncThenServerIdleTimeout(long sessionTimeout, long streamTimeout) throws Exception {
prepareServer(new HTTP2ServerConnectionFactory(new HttpConfiguration()) {
@Override
protected ServerSessionListener newSessionListener(Connector connector, EndPoint endPoint) {
return new HTTPServerSessionListener(connector, endPoint) {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
stream.setIdleTimeout(streamTimeout);
return super.onNewStream(stream, frame);
}
};
}
});
connector.setIdleTimeout(sessionTimeout);
ServletContextHandler context = new ServletContextHandler(server, "/");
long timeout = Math.min(sessionTimeout, streamTimeout);
CountDownLatch errorLatch = new CountDownLatch(1);
context.addServlet(new ServletHolder(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AsyncContext asyncContext = (AsyncContext) request.getAttribute(AsyncContext.class.getName());
if (asyncContext == null) {
AsyncContext context = request.startAsync();
context.setTimeout(2 * timeout);
request.setAttribute(AsyncContext.class.getName(), context);
context.addListener(new AsyncListener() {
@Override
public void onComplete(AsyncEvent event) throws IOException {
}
@Override
public void onTimeout(AsyncEvent event) throws IOException {
event.getAsyncContext().complete();
}
@Override
public void onError(AsyncEvent event) throws IOException {
errorLatch.countDown();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
}
});
} else {
throw new ServletException();
}
}
}), servletPath + "/*");
server.start();
prepareClient();
client.start();
Session session = newClient(new Session.Listener.Adapter());
HttpFields fields = new HttpFields();
MetaData.Request metaData = newRequest("GET", fields);
HeadersFrame frame = new HeadersFrame(metaData, null, true);
CountDownLatch clientLatch = new CountDownLatch(1);
session.newStream(frame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
MetaData.Response response = (MetaData.Response) frame.getMetaData();
if (response.getStatus() == HttpStatus.OK_200 && frame.isEndStream())
clientLatch.countDown();
}
});
// When the server idle times out, but the request has been dispatched
// then the server must ignore the idle timeout as per Servlet semantic.
Assert.assertFalse(errorLatch.await(2 * timeout, TimeUnit.MILLISECONDS));
Assert.assertTrue(clientLatch.await(2 * timeout, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class AbstractTest method start.
protected void start(ServerSessionListener listener) throws Exception {
prepareServer(new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), listener));
server.start();
prepareClient();
client.start();
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class JsrBrowserDebugTool method setupServer.
private void setupServer(int port) throws DeploymentException, ServletException, URISyntaxException, MalformedURLException, IOException {
server = new Server();
HttpConfiguration httpConf = new HttpConfiguration();
httpConf.setSendServerVersion(true);
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConf));
connector.setPort(port);
server.addConnector(connector);
String resourcePath = "/jsr-browser-debug-tool/index.html";
URL urlStatics = JsrBrowserDebugTool.class.getResource(resourcePath);
Objects.requireNonNull(urlStatics, "Unable to find " + resourcePath + " in classpath");
String urlBase = urlStatics.toURI().toASCIIString().replaceFirst("/[^/]*$", "/");
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setBaseResource(Resource.newResource(urlBase));
ServletHolder holder = context.addServlet(DefaultServlet.class, "/");
holder.setInitParameter("dirAllowed", "true");
server.setHandler(context);
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
container.addEndpoint(JsrBrowserSocket.class);
LOG.info("{} setup on port {}", this.getClass().getName(), port);
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class AbstractRuleTestCase method start.
protected void start(final boolean isSecure) throws Exception {
_connector = new LocalConnector(_server);
_connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().addCustomizer(new HttpConfiguration.Customizer() {
@Override
public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
request.setSecure(isSecure);
}
});
_server.setConnectors(new Connector[] { _connector });
_server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
_request = baseRequest;
_response = _request.getResponse();
try {
_latch.await();
} catch (InterruptedException e) {
throw new ServletException(e);
}
}
});
_server.start();
_latch = new CountDownLatch(1);
_connector.executeRequest("GET / HTTP/1.0\nCookie: set=already\n\n");
while (_response == null) Thread.sleep(1);
}
Aggregations