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
- Host: GitHub
- URL: https://github.com/sniffertine/groovy-web-console
- Owner: sniffertine
- License: mit
- Created: 2018-07-08T20:16:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-01T22:03:50.000Z (over 7 years ago)
- Last Synced: 2023-07-28T00:14:48.502Z (over 2 years ago)
- Topics: devtools, diagnostics, filter, groovy, java, servlet
- Language: JavaScript
- Size: 428 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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```