Created
January 7, 2011 01:28
-
-
Save kimukou/768959 to your computer and use it in GitHub Desktop.
jetty_runnigng test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//refarence Groovy Goodness: Groovlets as Lightweight Servlets | |
// http://mrhaki.blogspot.com/2009/10/groovy-goodness-groovlets-as.html | |
// | |
//@Grab(group='org.apache.tomcat', module='jsp-api', version='6.0.29') | |
//@Grab('javax.servlet:servlet-api:2.4') //not good working | |
@Grab(group='org.mortbay.jetty', module='jetty-embedded', version='6.1.14') | |
import org.mortbay.jetty.Server | |
import org.mortbay.jetty.servlet.* | |
import groovy.servlet.* | |
def startJetty() { | |
def jetty = new Server(9090) | |
def context = new Context(jetty, '/', Context.SESSIONS) // Allow sessions. | |
context.resourceBase = '.' // Look in current dir for Groovy scripts. | |
context.addServlet(GroovyServlet, '*.groovy') // All files ending with .groovy will be served. | |
context.setAttribute('version', '1.0') // Set an context attribute. | |
jetty.start() | |
} | |
println "Starting Jetty, press Ctrl+C to stop." | |
println "=> http://localhost:9090/serverinfo.groovy browsing" | |
startJetty() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set JAVA_HOME=C:\opt\jdk | |
set GROOVY_HOME=C:\opt\groovy-1.7.6 | |
::set JAVA_OPTS=-Dgroovy.source.encoding=UTF-8 -Dfile.encoding=UTF-8 | |
::%GROOVY_HOME%/bin/groovy jetty_start.groovy | |
::require lib | |
:: groovy-all-1.7.6.jar | |
:: ivy-2.2.0.jar | |
:: servlet-api-2.4.jar | |
:: jsp-api-2.0.jar | |
%JAVA_HOME%/bin/java %JAVA_OPTS% -cp ".;./lib/*" groovy.ui.GroovyMain jetty_start.groovy | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method = request.method | |
if (!session) { | |
session = request.getSession(true) | |
} | |
if (!session.groovlet) { | |
session.groovlet = 'Groovlets rock!' | |
} | |
html.html { | |
head { | |
title 'Groovlet info' | |
} | |
body { | |
h1 'General info' | |
ul { | |
li "Method: ${method}" | |
li "RequestURI: ${request.requestURI}" | |
li "session.groovlet: ${session.groovlet}" | |
li "application.version: ${context.version}" | |
} | |
h1 'Headers' | |
ul { | |
headers.each { | |
li "${it.key} = ${it.value}" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment