From 5edf144d3ba31788c54ed2ead767a16acee5521e Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Tue, 7 Jul 2015 13:28:22 -0500 Subject: [PATCH] Added GroovyDirectoryServer: Simple file and Groovlet server.. --- build.gradle | 3 +- .../net/GroovyDirectoryServer.groovy | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy diff --git a/build.gradle b/build.gradle index bac8ae9..789dc06 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: "groovy" apply plugin: "maven" group = "com.jdbernard" -version = "3.8" +version = "3.9" repositories { mavenCentral() } @@ -12,6 +12,7 @@ dependencies { compile 'org.slf4j:slf4j-api:1.7.10' compile 'ch.qos.logback:logback-core:1.1.2' compile 'ch.qos.logback:logback-classic:1.1.2' + compile 'org.eclipse.jetty.aggregate:jetty-all:7.6.15.v20140411' testCompile 'junit:junit:4.12' } diff --git a/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy b/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy new file mode 100755 index 0000000..85bec11 --- /dev/null +++ b/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy @@ -0,0 +1,33 @@ +#!/usr/bin/env groovy + +package com.jdbernard.net + +import org.eclipse.jetty.server.Server +import org.eclipse.jetty.servlet.* +import groovy.servlet.* + + +def startJetty(int port) { + def server = new Server(port) + + def handler = new ServletContextHandler(ServletContextHandler.SESSIONS) + handler.contextPath = '/' + handler.resourceBase = '.' + + // Groovy Scripts + handler.addServlet(GroovyServlet, '*.groovy') + + // Files + def filesHolder = handler.addServlet(DefaultServlet, '/') + filesHolder.setInitParameter('resourceBase', '.') + + server.handler = handler + server.start() +} + + if (args.length < 1) { + println "Usage: webServer.groovy " + System.exit(1) } + +println "Starting Jetty, press Ctrl-C to stop." +startJetty(Integer.parseInt(args[0]))