H2 Console

The H2ManagerMenu provides a single menu item to redirect to the H2 web console. This is only enabled for prototyping, and only if H2 is detected in the underlying JDBC URL.

The menu appears under the "Prototyping" menu.

Maven Configuration

Dependency Management

If your application inherits from the Apache Isis starter app (org.apache.isis.app:isis-app-starter-parent) then that will define the version automatically:

pom.xml
<parent>
    <groupId>org.apache.isis.app</groupId>
    <artifactId>isis-app-starter-parent</artifactId>
    <version>2.0.0-M6</version>
    <relativePath/>
</parent>

Alternatively, import the core BOM. This is usually done in the top-level parent pom of your application:

pom.xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.isis.core</groupId>
            <artifactId>isis-core</artifactId>
            <version>2.0.0-M6</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

In addition, add a section for the BOM of all the testing support libraries:

pom.xml
<dependencyManagement>
    <dependencies>
        <dependency>
        	<groupId>org.apache.isis.testing</groupId>
	        <artifactId>isis-testing</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>2.0.0-M6</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Dependencies

In the domain module(s) of your application, add the following dependency:

pom.xml
<dependencies>
    <dependency>
        <groupId>org.apache.isis.testing</groupId>
        <artifactId>isis-testing-h2console-ui</artifactId>
    </dependency>
</dependencies>

Update AppManifest

In your application’s AppManifest (top-level Spring @Configuration used to bootstrap the app), import the IsisModuleTestingH2ConsoleUi module:

AppManifest.java
@Configuration
@Import({
        ...
        IsisModuleTestingH2ConsoleUi.class,
        ...
})
public class AppManifest {
}

API & Implementation

The API of the service is:

public class H2ManagerMenu {
    public void openH2Console() { /* ... */ }
}

Note that this launches the manager on the same host that the webapp runs, and so is only appropriate to use when running on localhost.

Additional Configuration

The following additional configuration is also required (all of this is present in the helloworld and simpleapp starter apps):

  • the h2 jdbc driver is required on the classpath of the webapp:

    pom.xml
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
  • the jdbc:h2 URL configuration properties must be defined, eg in application.properties:

    application.properties
    spring.sql.init.platform=h2
    spring.datasource.url=jdbc:h2:mem
  • finally, and most importantly, the h2 console servlet must be configured in web.xml, and must be mapped to /db:

    web.xml
    <servlet>
        <servlet-name>H2Console</servlet-name>
        <servlet-class>org.h2.server.web.WebServlet</servlet-class>
        <init-param>
            <param-name>webAllowOthers</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>H2Console</servlet-name>
        <url-pattern>/db/*</url-pattern>
    </servlet-mapping>

Disabling/hiding the menu

The menu can be hidden or disabled by subscribing to its domain event, eg:

import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

@Service
public class HideH2ManagerMenu {

    @EventListener(H2ManagerMenu.ActionDomainEvent.class)
    public void on(H2ManagerMenu.ActionDomainEvent ev) {
        ev.hide();
    }
}

Using with Secman

TODO - describe the necessary role to grant if using secman.