use of io.undertow.server.protocol.http.HttpOpenListener in project undertow by undertow-io.
the class AutobahnExtensionsServer method run.
public void run() {
xnio = Xnio.getInstance();
try {
worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
openListener = new HttpOpenListener(new DefaultByteBufferPool(false, 8192));
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
WebSocketProtocolHandshakeHandler handler = webSocketDebugHandler().addExtension(new PerMessageDeflateHandshake());
DebugExtensionsHeaderHandler debug = new DebugExtensionsHeaderHandler(handler);
setRootHandler(debug);
server.resumeAccepts();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.protocol.http.HttpOpenListener in project undertow by undertow-io.
the class AutobahnExtensionCustomReceiverServer method run.
public void run() {
xnio = Xnio.getInstance();
try {
worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.WORKER_ACCEPT_THREADS, 4).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
openListener = new HttpOpenListener(new DefaultByteBufferPool(false, 8192));
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
setRootHandler(getRootHandler().addExtension(new PerMessageDeflateHandshake()));
server.resumeAccepts();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.protocol.http.HttpOpenListener in project undertow by undertow-io.
the class HttpClientConnection method sendRequest.
@Override
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
try {
Integer readTimeout = connection.getOption(Options.READ_TIMEOUT);
if (readTimeout != null && readTimeout > 0) {
connection.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(connection.getSourceChannel().getConduit(), connection, new HttpOpenListener(bufferPool)));
}
Integer writeTimeout = connection.getOption(Options.WRITE_TIMEOUT);
if (writeTimeout != null && writeTimeout > 0) {
connection.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(connection.getSinkChannel().getConduit(), connection, new HttpOpenListener(bufferPool)));
}
} catch (IOException e) {
IoUtils.safeClose(connection);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
}
if (http2Delegate != null) {
http2Delegate.sendRequest(request, clientCallback);
return;
}
if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
return;
}
final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
boolean ssl = this.connection instanceof SslConnection;
if (!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {
// this is the first request, as we want to try a HTTP2 upgrade
request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool));
request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING);
request.getRequestHeaders().put(Headers.CONNECTION, "Upgrade, HTTP2-Settings");
http2Tried = true;
}
if (currentRequest == null) {
initiateRequest(httpClientExchange);
} else {
pendingQueue.add(httpClientExchange);
}
}
use of io.undertow.server.protocol.http.HttpOpenListener in project undertow by undertow-io.
the class ProgramaticAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.protocol.http.HttpOpenListener in project undertow by undertow-io.
the class AnnotatedAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
DeploymentManager deploymentManager = null;
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8024);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).addEndpoint(AutobahnAnnotatedEndpoint.class).setDispatchToWorkerThread(true).addExtension(new PerMessageDeflateHandshake())).addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
log.error("failed to start server", e);
} finally {
if (deploymentManager != null) {
deploymentManager.undeploy();
try {
deploymentManager.stop();
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations