Search in sources :

Example 1 with WebServlet

use of org.h2.server.web.WebServlet in project h2database by h2database.

the class TestWeb method testServlet.

private void testServlet() throws Exception {
    WebServlet servlet = new WebServlet();
    final HashMap<String, String> configMap = new HashMap<>();
    configMap.put("ifExists", "");
    configMap.put("", "");
    configMap.put("", "");
    configMap.put("", "");
    ServletConfig config = new ServletConfig() {

        @Override
        public String getServletName() {
            return "H2Console";
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new Vector<>(configMap.keySet()).elements();
        }

        @Override
        public String getInitParameter(String name) {
            return configMap.get(name);
        }

        @Override
        public ServletContext getServletContext() {
            return null;
        }
    };
    servlet.init(config);
    TestHttpServletRequest request = new TestHttpServletRequest();
    request.setPathInfo("/");
    TestHttpServletResponse response = new TestHttpServletResponse();
    TestServletOutputStream out = new TestServletOutputStream();
    response.setServletOutputStream(out);
    servlet.doGet(request, response);
    assertContains(out.toString(), "location.href = 'login.jsp");
    servlet.destroy();
}
Also used : WebServlet(org.h2.server.web.WebServlet) HashMap(java.util.HashMap) ServletConfig(javax.servlet.ServletConfig)

Example 2 with WebServlet

use of org.h2.server.web.WebServlet in project spring-boot by spring-projects.

the class H2ConsoleAutoConfiguration method h2Console.

@Bean
public ServletRegistrationBean<WebServlet> h2Console() {
    String path = this.properties.getPath();
    String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
    ServletRegistrationBean<WebServlet> registration = new ServletRegistrationBean<>(new WebServlet(), urlMapping);
    H2ConsoleProperties.Settings settings = this.properties.getSettings();
    if (settings.isTrace()) {
        registration.addInitParameter("trace", "");
    }
    if (settings.isWebAllowOthers()) {
        registration.addInitParameter("webAllowOthers", "");
    }
    return registration;
}
Also used : WebServlet(org.h2.server.web.WebServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with WebServlet

use of org.h2.server.web.WebServlet in project felix by apache.

the class H2Activator method start.

@Override
public void start(BundleContext context) throws Exception {
    ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("dataSourceName", "test");
    context.registerService(DataSource.class.getName(), ds, props);
    loadData(ds);
    // Register the H2 console servlet
    Dictionary<String, String> servletProps = new Hashtable<String, String>();
    servletProps.put("alias", "/h2");
    servletProps.put("init.webAllowOthers", "true");
    context.registerService(Servlet.class.getName(), new WebServlet(), servletProps);
}
Also used : WebServlet(org.h2.server.web.WebServlet) Hashtable(java.util.Hashtable) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Servlet(javax.servlet.Servlet) WebServlet(org.h2.server.web.WebServlet) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 4 with WebServlet

use of org.h2.server.web.WebServlet in project gs-spring-security-3.2 by rwinch.

the class H2Initializer method onStartup.

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    ServletRegistration.Dynamic dynamic = servletContext.addServlet("h2", new WebServlet());
    dynamic.addMapping("/h2/*");
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) WebServlet(org.h2.server.web.WebServlet)

Aggregations

WebServlet (org.h2.server.web.WebServlet)4 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Servlet (javax.servlet.Servlet)1 ServletConfig (javax.servlet.ServletConfig)1 ServletRegistration (javax.servlet.ServletRegistration)1 DataSource (javax.sql.DataSource)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)1 Bean (org.springframework.context.annotation.Bean)1