H2ConsoleServlet.java 1.18 KB
package org.legrog.util;

import org.apache.deltaspike.core.api.projectstage.ProjectStage;
import org.apache.deltaspike.core.util.ProjectStageProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

import static org.legrog.util.H2ConsoleServlet.CONSOLE_MAPPING;


@WebServlet(
        urlPatterns = CONSOLE_MAPPING,
        name = "H2Console",
        loadOnStartup = 1,
        initParams = {@WebInitParam(name = "webAllowOthers", value = ""), @WebInitParam(name = "trace", value = "")}
)
public class H2ConsoleServlet extends org.h2.server.web.WebServlet {
    static final String CONSOLE_MAPPING = "/console/*";

    static final Logger logger = LoggerFactory.getLogger(H2ConsoleServlet.class);

    @Override
    public void init() {
        ProjectStage projectStage = ProjectStageProducer.getInstance().getProjectStage();
        if (projectStage == ProjectStage.IntegrationTest) {
            logger.info("Create a H2 Console Servlet mapped to {}", CONSOLE_MAPPING);
            super.init();
        } else {
            logger.info("Skipping H2 Console Servlet creation");
        }

    }
}