An open API service indexing awesome lists of open source software.

https://github.com/sniffertine/groovy-web-console

A web-based Groovy console written as a pure Java Servlet
https://github.com/sniffertine/groovy-web-console

devtools diagnostics filter groovy java servlet

Last synced: 2 months ago
JSON representation

A web-based Groovy console written as a pure Java Servlet

Awesome Lists containing this project

README

          

# groovy-web-console
A web-based Groovy console written as a pure Java Servlet or Filter

## General
As a developer, it would be very convenient if you could access your
running Java application and write some debug code for runtime analysis.
This is especially useful for debugging purposes.

Using this project enables you to open a web (HTML) based console view
that lets you immediately access your runtime environment using
the groovy langauge.

## Table of Contents
* **[Demo](#demo)**
* **[Setup](#setup)**
* **[Usage](#usage)**
* **[Configuration](#configuration)**

## Demo
1. Checkout the code to your local machine
```console
git clone https://github.com/sniffertine/groovy-web-console.git
cd groovy-web-console
```
2. Build the project and run the demo webapp
```console
./mvnw clean install org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run
```
3. Open your webbrowser here: http://localhost:8080

## Setup
The setup is very simple, as the code is availabe via the
maven central repository.
Just add the dependency to your project pom.xml
```xml

ch.baurs
groovy-web-console
1.0.0

```

## Usage
There are three possible usage scenarios.

### 1. Java Servlet

Configure the GroovyConsoleServlet in your web.xml

```xml

groovyConsoleServlet
ch.baurs.groovyconsole.GroovyConsoleServlet

mappingPath
/groovyConsoleServlet


theme
twilight


prompt
console via servlet $>

groovyConsoleServlet
/groovyConsoleServlet/*

```

### 2. Java Servlet Filter

Configure the GroovyConsoleServlet in your web.xml

```xml

groovyConsoleFilter
ch.baurs.groovyconsole.GroovyConsoleFilter

mappingPath
/groovyConsoleFilter


theme
twilight


prompt
console via filter $>

groovyConsoleFilter
/groovyConsoleFilter/*
REQUEST

```

### 3. Your own code

Configure the Application directly in your onw Java code. Here, I use an empty Servlet to demonstrate.

```xml

myServlet
ch.baurs.groovyconsole.testwebapp.MyServlet

myServlet
/myServlet/*

```

```java
package my.web.project.servlet;

public class MyServlet extends HttpServlet {

private Application application;

@Override
public void init(ServletConfig config) throws ServletException {

Configuration configuration = Configuration.builder()
.mappingPath("/myServlet")
.prompt("console directly configured $>")
.theme("mdn-like")
.build();

application = new Application(configuration);
}

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
application.handle(req, resp);
}
}

```

## Configuration

The Groovy Console Application has a number of configuration parameters available for customization.
You can configure most of the parameters in two ways:

A) Through direct configuration using the ```Configuration.builder()``` before initializing the ```ch.baurs.groovyconsole.Application```

B) As ```init-param``` when using the built-in ```GroovyConsoleFilter``` or ```GroovyConsoleServlet```.

| config param | available as init-param (web.xml) | description
| --- | --- | ---
| contextPath | no _(taken from ```ServletContext```)_ | The contextPath of the web application the groovy-web-console is part of.
:bulb: see ServletContext#getContextPath

**default value:** <empty string>
| mappingPath | yes | The path below _contextPath_ were the groovy-web-console is mapped to.
This value should correspond to the `````` in your `````` section of the _web.xml_ file.
:bulb: see http://tutorials.jenkov.com/java-servlets/web-xml.html#configuration

**default value:** /groovyWebConsole
| theme | yes | The codemirror theme to be used for console text formatting.
:bulb: see https://codemirror.net/demo/theme.html#vibrant-ink

**default value:** vibrant-ink
| prompt | yes | The prompt text of the console.

**default value:** gc$
| sessionInactiveInterval | yes | The number of seconds of inactivity before the session times out.
:bulb: see https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/HttpSession.html#setMaxInactiveInterval-int-.

**default value:** 86400 ( = 24 hours)
| characterEncoding | yes | The charset to be used.

**default value:** UTF-8
| inlineAssets | yes | Defines if assets (js, css) should be inlined in the html.

**default value:** ```false```
| ipAuth | yes | Enables access restriction by remote IP address. The value can be a regular expression.
:bulb: see https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletRequest.html#getRemoteAddr--.

**default value:** ```null```
| envAuth | yes | Enables access restriction by environment variable. The value must be in the form ```key=value```
This requires ```System.getProperty("key")``` to be equal to ```value```.

**default value:** ```null```