io.undertow.server.DefaultByteBufferPool Java Examples

The following examples show how to use io.undertow.server.DefaultByteBufferPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UndertowXhrTransport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public UndertowXhrTransport(OptionMap optionMap) throws IOException {
	Assert.notNull(optionMap, "OptionMap is required");
	this.optionMap = optionMap;
	this.httpClient = UndertowClient.getInstance();
	this.worker = Xnio.getInstance().createWorker(optionMap);
	this.bufferPool = new DefaultByteBufferPool(false, 1024, -1, 2);
}
 
Example #2
Source File: CustomizationBean.java    From momo-cloud-permission with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(UndertowServletWebServerFactory factory) {
    factory.addDeploymentInfoCustomizers(deploymentInfo -> {
        WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
        webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 1024));
        deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
    });
}
 
Example #3
Source File: UndertowXhrTransport.java    From java-technology-stack with MIT License 5 votes vote down vote up
public UndertowXhrTransport(OptionMap optionMap) throws IOException {
	Assert.notNull(optionMap, "OptionMap is required");
	this.optionMap = optionMap;
	this.httpClient = UndertowClient.getInstance();
	this.worker = Xnio.getInstance().createWorker(optionMap);
	this.bufferPool = new DefaultByteBufferPool(false, 1024, -1, 2);
}
 
Example #4
Source File: UndertowXhrTransport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public Undertow13BufferSupport() {
	this.undertowBufferPool = new DefaultByteBufferPool(false, 1024, -1, 2);
	this.httpClientConnectCallbackMethod = ReflectionUtils.findMethod(UndertowClient.class, "connect",
			ClientCallback.class, URI.class, XnioWorker.class, ByteBufferPool.class, OptionMap.class);
	this.httpClientConnectMethod = ReflectionUtils.findMethod(UndertowClient.class, "connect",
			URI.class, XnioWorker.class, ByteBufferPool.class, OptionMap.class);
}
 
Example #5
Source File: SNICombinedWithALPNTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSimpleViaHostname() throws Exception {
    Assume.assumeFalse("There is no ALPN implementation in IBM JDK 8 and less; also ALPN-hack that serves" +
                    " as a workaround for other JDKs does not work with IBM JDK.", isIbmJdk() && jdkLessThan9());

    XnioSsl ssl = createClientSSL(hostNameKeystore);
    UndertowClient client = UndertowClient.getInstance();
    DefaultByteBufferPool pool = new DefaultByteBufferPool(false, 1024);
    ClientConnection connection = client.connect(new URI("https", null, "localhost", TestSuiteEnvironment.getHttpPort(), "", null, null), XnioWorker.getContextManager().get(), ssl, pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    performSimpleTest(pool, connection);
}
 
Example #6
Source File: SNICombinedWithALPNTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testHttpsViaIp() throws Exception {
    Assume.assumeFalse("There is no ALPN implementation in IBM JDK 8 and less; also ALPN-hack that serves" +
            " as a workaround for other JDKs does not work with IBM JDK.", isIbmJdk() && jdkLessThan9());

    XnioSsl ssl = createClientSSL(ipKeystore);
    UndertowClient client = UndertowClient.getInstance();
    DefaultByteBufferPool pool = new DefaultByteBufferPool(false, 1024);
    ClientConnection connection = client.connect(new URI("https", null, "127.0.0.1", TestSuiteEnvironment.getHttpPort(), "", null, null), XnioWorker.getContextManager().get(), ssl, pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    performSimpleTest(pool, connection);
}
 
Example #7
Source File: ServletInitialHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {

    final DefaultByteBufferPool bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
    MockServerConnection connection = new MockServerConnection(bufferPool);
    HttpServerExchange exchange = new HttpServerExchange(connection);
    exchange.setRequestScheme(request.getScheme());
    exchange.setRequestMethod(new HttpString(request.getMethod()));
    exchange.setProtocol(Protocols.HTTP_1_0);
    exchange.setResolvedPath(request.getContextPath());
    String relative;
    if (request.getPathInfo() == null) {
        relative = request.getServletPath();
    } else {
        relative = request.getServletPath() + request.getPathInfo();
    }
    exchange.setRelativePath(relative);
    final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
    final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
    final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
    final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
    servletRequestContext.setServletRequest(request);
    servletRequestContext.setServletResponse(response);
    //set the max request size if applicable
    if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
        exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
    }
    exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);

    exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
    servletRequestContext.setServletPathMatch(info);

    try {
        dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new ServletException(e);
    }
}
 
Example #8
Source File: InVMConnection.java    From thorntail with Apache License 2.0 4 votes vote down vote up
InVMConnection(XnioWorker worker, int port) {
    this.bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
    this.worker = worker;
    this.address = new InetSocketAddress(port); // port carried forward from the initial
}
 
Example #9
Source File: InVMConnection.java    From thorntail with Apache License 2.0 4 votes vote down vote up
InVMConnection(XnioWorker worker, int port) {
    this.bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
    this.worker = worker;
    this.address = new InetSocketAddress(port); // port carried forward from the initial
}
 
Example #10
Source File: DeploymentManagerFactory.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "False positive")
private DeploymentInfo configureDeploymentInfo() {
    // Basic deployment attributes
    DeploymentInfo deploymentInfo = Servlets.deployment()
            .setEagerFilterInit(true)
            .setClassLoader(mostCompleteClassLoader)
            .setDeploymentName(applicationConfig.getId())
            .setDisplayName(applicationConfig.getName())
            .setDefaultSessionTimeout(serverConfig.getDefaultSessionTimeout())
            .setResourceManager(new ClassPathResourceManager(mostCompleteClassLoader, META_INF_RESOURCES))
            .addWelcomePages(serverConfig.getWelcomeFiles())
            .addErrorPages(buildUndertowErrorPages(serverConfig.getErrorPages()))
            .setContextPath(serverConfig.getContextPath());

    // Configure WebSockets if enabled
    if (serverConfig.webSocket().isEnabled()) {
        LOGGER.info("WebSocket support is enabled");
        deploymentInfo.addServletContextAttribute(
                WebSocketDeploymentInfo.ATTRIBUTE_NAME,
                new WebSocketDeploymentInfo()
                        .setBuffers(new DefaultByteBufferPool(
                                undertowConfig.isDirectBuffers(),
                                undertowConfig.getBufferSize()))
                        .setWorker(xnioWorker)
        );
    }

    // Redirect to HTTPS if configured
    if (serverConfig.isHttp() && serverConfig.isHttps() && serverConfig.isPreferHttps()) {
        LOGGER.info("Automatic redirection to HTTPS is enabled");
        deploymentInfo
                .addSecurityConstraint(new SecurityConstraint()
                        .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*"))
                        .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
                        .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
                .setConfidentialPortManager(ex -> serverConfig.getSecurePort());
    }

    // Add custom init parameters
    for (Map.Entry<String, String> initParameter : initParameters.entrySet()) {
        LOGGER.debug("Servlet init parameter {} = {}", initParameter.getKey(), initParameter.getValue());
        deploymentInfo.addInitParameter(initParameter.getKey(), initParameter.getValue());
    }

    // Register ServletContainerInitializers
    for (ServletContainerInitializer sci : loadServletContainerInitializers()) {
        LOGGER.debug("Registering ServletContainerInitializer {}", sci.getClass().getName());
        deploymentInfo.addServletContainerInitializer(createServletContainerInitializerInfo(sci));
    }

    return deploymentInfo;
}
 
Example #11
Source File: UndertowWebSocketClient.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Alternate constructor providing additional control over the
 * {@link ConnectionBuilder} for each WebSocket connection.
 * @param worker the Xnio worker to use to create {@code ConnectionBuilder}'s
 * @param builderConsumer a consumer to configure {@code ConnectionBuilder}'s
 */
public UndertowWebSocketClient(XnioWorker worker, Consumer<ConnectionBuilder> builderConsumer) {
	this(worker, new DefaultByteBufferPool(false, DEFAULT_POOL_BUFFER_SIZE), builderConsumer);
}
 
Example #12
Source File: UndertowWebSocketClient.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Alternate constructor providing additional control over the
 * {@link ConnectionBuilder} for each WebSocket connection.
 * @param worker the Xnio worker to use to create {@code ConnectionBuilder}'s
 * @param builderConsumer a consumer to configure {@code ConnectionBuilder}'s
 */
public UndertowWebSocketClient(XnioWorker worker, Consumer<ConnectionBuilder> builderConsumer) {
	this(worker, new DefaultByteBufferPool(false, DEFAULT_POOL_BUFFER_SIZE), builderConsumer);
}