All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.yourinspiration.jexpresso.HttpJExpressoServerInitializer Maven / Gradle / Ivy

package de.yourinspiration.jexpresso;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

import java.util.List;
import java.util.Map;

import de.yourinspiration.jexpresso.exception.ExceptionHandlerEntry;

/**
 * Netty channel initializer.
 * 
 * @author Marcel Härle
 *
 */
public class HttpJExpressoServerInitializer extends ChannelInitializer {

    public static final int MAX_CONTENT_LENGTH = 1048576;

    private final List routes;
    private final List exceptionHandlerEntries;
    private final Map templateEngines;
    private final List middlewareHandlers;

    protected HttpJExpressoServerInitializer(final List routes,
            final List exceptionHandlerEntries,
            final List middlewareHandlers, final Map templateEngines) {
        this.routes = routes;
        this.exceptionHandlerEntries = exceptionHandlerEntries;
        this.middlewareHandlers = middlewareHandlers;
        this.templateEngines = templateEngines;
    }

    @Override
    protected void initChannel(final Channel ch) throws Exception {
        final ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpRequestDecoder());
        p.addLast(new HttpObjectAggregator(MAX_CONTENT_LENGTH));
        p.addLast(new HttpResponseEncoder());
        p.addLast(new HttpContentCompressor());
        p.addLast(new MiddlewareChannelHandler(middlewareHandlers), new HttpJExpressoServerHandler(routes,
                exceptionHandlerEntries, templateEngines));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy