Last active
August 29, 2015 14:03
-
-
Save EECOLOR/14ba318a5e93e1eaf8f8 to your computer and use it in GitHub Desktop.
Experiment running railo from sbt
This file contains 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
import javax.servlet.http.HttpServletRequest | |
class FakeHttpServletRequest extends HttpServletRequest { | |
// Members declared in javax.servlet.http.HttpServletRequest | |
def authenticate(x$1: javax.servlet.http.HttpServletResponse): Boolean = ??? | |
def getAuthType(): String = ??? | |
def getContextPath(): String = "/" | |
def getCookies(): Array[javax.servlet.http.Cookie] = Array.empty | |
def getDateHeader(x$1: String): Long = ??? | |
def getHeader(x$1: String): String = ??? | |
def getHeaderNames(): java.util.Enumeration[String] = ??? | |
def getHeaders(x$1: String): java.util.Enumeration[String] = ??? | |
def getIntHeader(x$1: String): Int = ??? | |
def getMethod(): String = ??? | |
def getPart(x$1: String): javax.servlet.http.Part = ??? | |
def getParts(): java.util.Collection[javax.servlet.http.Part] = ??? | |
def getPathInfo(): String = "" | |
def getPathTranslated(): String = ??? | |
def getQueryString(): String = "" | |
def getRemoteUser(): String = ??? | |
def getRequestURI(): String = "/" | |
def getRequestURL(): StringBuffer = ??? | |
def getRequestedSessionId(): String = ??? | |
def getServletPath(): String = "/" | |
def getSession(): javax.servlet.http.HttpSession = ??? | |
def getSession(x$1: Boolean): javax.servlet.http.HttpSession = ??? | |
def getUserPrincipal(): java.security.Principal = ??? | |
def isRequestedSessionIdFromCookie(): Boolean = ??? | |
def isRequestedSessionIdFromURL(): Boolean = ??? | |
def isRequestedSessionIdFromUrl(): Boolean = ??? | |
def isRequestedSessionIdValid(): Boolean = ??? | |
def isUserInRole(x$1: String): Boolean = ??? | |
def login(x$1: String,x$2: String): Unit = ??? | |
def logout(): Unit = ??? | |
// Members declared in javax.servlet.ServletRequest | |
def getAsyncContext(): javax.servlet.AsyncContext = ??? | |
def getAttribute(name: String): Object = null | |
def getAttributeNames(): java.util.Enumeration[String] = ??? | |
def getCharacterEncoding(): String = ??? | |
def getContentLength(): Int = ??? | |
def getContentType(): String = null | |
def getDispatcherType(): javax.servlet.DispatcherType = ??? | |
def getInputStream(): javax.servlet.ServletInputStream = ??? | |
def getLocalAddr(): String = ??? | |
def getLocalName(): String = ??? | |
def getLocalPort(): Int = ??? | |
def getLocale(): java.util.Locale = ??? | |
def getLocales(): java.util.Enumeration[java.util.Locale] = ??? | |
def getParameter(x$1: String): String = ??? | |
def getParameterMap(): java.util.Map[String,Array[String]] = ??? | |
def getParameterNames(): java.util.Enumeration[String] = ??? | |
def getParameterValues(x$1: String): Array[String] = ??? | |
def getProtocol(): String = ??? | |
def getReader(): java.io.BufferedReader = ??? | |
def getRealPath(x$1: String): String = ??? | |
def getRemoteAddr(): String = ??? | |
def getRemoteHost(): String = ??? | |
def getRemotePort(): Int = ??? | |
def getRequestDispatcher(x$1: String): javax.servlet.RequestDispatcher = ??? | |
def getScheme(): String = "http" | |
def getServerName(): String = "sbt-not-a-server" | |
def getServerPort(): Int = 9999 | |
def getServletContext(): javax.servlet.ServletContext = ??? | |
def isAsyncStarted(): Boolean = ??? | |
def isAsyncSupported(): Boolean = ??? | |
def isSecure(): Boolean = ??? | |
def removeAttribute(x$1: String): Unit = ??? | |
def setAttribute(x$1: String,x$2: Any): Unit = ??? | |
def setCharacterEncoding(x$1: String): Unit = ??? | |
def startAsync(x$1: javax.servlet.ServletRequest,x$2: javax.servlet.ServletResponse): javax.servlet.AsyncContext = ??? | |
def startAsync(): javax.servlet.AsyncContext = ??? | |
} |
This file contains 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
import javax.servlet.http.HttpServletResponse | |
import scala.beans.BeanProperty | |
class FakeHttpServletResponse extends HttpServletResponse { | |
@BeanProperty | |
var contentType:String = _ | |
def addCookie(x$1: javax.servlet.http.Cookie): Unit = ??? | |
def addDateHeader(x$1: String, x$2: Long): Unit = ??? | |
def addHeader(x$1: String, x$2: String): Unit = ??? | |
def addIntHeader(x$1: String, x$2: Int): Unit = ??? | |
def containsHeader(x$1: String): Boolean = ??? | |
def encodeRedirectURL(x$1: String): String = ??? | |
def encodeRedirectUrl(x$1: String): String = ??? | |
def encodeURL(x$1: String): String = ??? | |
def encodeUrl(x$1: String): String = ??? | |
def getHeader(x$1: String): String = ??? | |
def getHeaderNames(): java.util.Collection[String] = ??? | |
def getHeaders(x$1: String): java.util.Collection[String] = ??? | |
def getStatus(): Int = ??? | |
def sendError(x$1: Int): Unit = ??? | |
def sendError(x$1: Int, x$2: String): Unit = ??? | |
def sendRedirect(x$1: String): Unit = ??? | |
def setDateHeader(x$1: String, x$2: Long): Unit = ??? | |
def setHeader(x$1: String, x$2: String): Unit = ??? | |
def setIntHeader(x$1: String, x$2: Int): Unit = ??? | |
def setStatus(x$1: Int, x$2: String): Unit = ??? | |
def setStatus(x$1: Int): Unit = ??? | |
// Members declared in javax.servlet.ServletResponse | |
def flushBuffer(): Unit = ??? | |
def getBufferSize(): Int = ??? | |
def getCharacterEncoding(): String = ??? | |
def getLocale(): java.util.Locale = ??? | |
def getOutputStream(): javax.servlet.ServletOutputStream = ??? | |
def getWriter(): java.io.PrintWriter = ??? | |
def isCommitted(): Boolean = ??? | |
def reset(): Unit = ??? | |
def resetBuffer(): Unit = ??? | |
def setBufferSize(x$1: Int): Unit = ??? | |
def setCharacterEncoding(x$1: String): Unit = ??? | |
def setContentLength(x$1: Int): Unit = ??? | |
def setLocale(x$1: java.util.Locale): Unit = ??? | |
} |
This file contains 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
resolvers += "http://cfmlprojects.org/artifacts/" at "http://cfmlprojects.org/artifacts/" | |
libraryDependencies ++= Seq( | |
"org.eclipse.jetty" % "jetty-servlet" % "9.0.3.v20130506", | |
"org.eclipse.jetty" % "jetty-webapp" % "9.0.3.v20130506", | |
"org.getrailo" % "railo" % "4.3.0.001", | |
"org.getrailo" % "railo-rc" % "4.3.0.001", | |
"org.mortbay.jetty" % "jsp-2.1-glassfish" % "2.1.v20100127", | |
"org.fusesource.jansi" % "jansi" % "1.11" | |
) |
This file contains 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
import org.eclipse.jetty.server.Server | |
import org.eclipse.jetty.webapp.WebAppContext | |
import org.fusesource.jansi.AnsiConsole | |
import jline.console.ConsoleReader | |
import scala.Console.{GREEN, RESET} | |
import railo.loader.engine.CFMLEngineFactory | |
import railo.runtime.CFMLFactory | |
import scala.collection.JavaConverters._ | |
import javax.servlet.http.HttpServlet | |
import xsbti.api.OutputSetting | |
import xsbti.api.Compilation | |
val Railo = config("railo") describedAs "Configuration for Railo utilities" | |
val port = settingKey[Int]("Port to start Railo server") | |
val withServer = taskKey[(WebAppContext => Unit) => Unit]("Code to be executed with Railo started") | |
val servletName = settingKey[String]("Name of the CMFL servlet") | |
val servletConfiguration = taskKey[File]("location of the web.xml") | |
val railoConfiguration = taskKey[File]("location of the railo config dir containing railo-web.xml.cfm") | |
val cfmlFactory = taskKey[CFMLFactory]("The cfml factory") | |
port in Railo := 8181 | |
servletName in Railo := "CFMLServlet" | |
sourceDirectory in Railo := (sourceDirectory in Compile).value / "webapp" | |
classDirectory in Railo := target.value / "webappClasses" | |
run in Railo := { | |
(withServer in Railo).value { context => | |
println(GREEN + "(Server started, use Ctrl+D to stop and go back to the console...)" + RESET) | |
waitForKey() | |
} | |
} | |
compile in Railo := { | |
val railoPort = (port in Railo).value | |
val webAppDirectory = (sourceDirectory in Railo).value.getAbsolutePath | |
val webXml = (servletConfiguration in Railo).value.getAbsolutePath | |
val railoServletName = (servletName in Railo).value | |
val sourceDir = (sourceDirectory in Railo).value | |
val result = | |
executeWithServer(railoPort, webAppDirectory, webXml) { | |
compileMapping(railoServletName, sourceDir) | |
} | |
IO.copyDirectory(result, (classDirectory in Railo).value, overwrite = true) | |
inc.Analysis.Empty | |
} | |
withServer in Railo := { | |
val railoPort = (port in Railo).value | |
val webAppDirectory = (sourceDirectory in Railo).value.getAbsolutePath | |
val webXml = (servletConfiguration in Railo).value.getAbsolutePath | |
executeWithServer(railoPort, webAppDirectory, webXml) | |
} | |
def executeWithServer[T](port:Int, webAppDirectory:String, webXml:String):(WebAppContext => T) => T = | |
code => { | |
val (context, server) = startRailoServer(port, webAppDirectory, webXml) | |
try code(context) | |
finally server.stop | |
} | |
def startRailoServer(webPort:Int, webappDirLocation:String, webXml:String) = { | |
import org.eclipse.jetty.server.Server | |
import org.eclipse.jetty.webapp.WebAppContext | |
import org.fusesource.jansi.AnsiConsole | |
// | |
val server = new Server(webPort) | |
val root = new WebAppContext() | |
root.setContextPath("/") | |
root.setDescriptor(webXml) | |
root.setResourceBase(webappDirLocation) | |
// | |
//Parent loader priority is a class loader setting that Jetty accepts. | |
//By default Jetty will behave like most web containers in that it will | |
//allow your application to replace non-server libraries that are part of the | |
//container. Setting parent loader priority to true changes this behavior. | |
//Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading | |
root.setParentLoaderPriority(true) | |
// | |
server.setHandler(root) | |
server.start() | |
AnsiConsole.systemInstall() | |
val ANSI_NORMAL = "\u001b[0m" | |
val ANSI_WHITEONBLUE = "\u001b[37;44m" | |
AnsiConsole.out.println(ANSI_WHITEONBLUE + "Railo running on port " + webPort + ANSI_NORMAL) | |
//server.join() | |
(root, server) | |
} | |
def compileMapping(railoServletName:String, sourceDir:File) = { context:WebAppContext => | |
val startTime = System.currentTimeMillis | |
val handler = context.getServletHandler | |
val servlet = handler.getServlet(railoServletName).getServlet | |
val servletConfig = servlet.getServletConfig | |
val servletContext = handler.getServletContext | |
val engine = CFMLEngineFactory.getInstance(servletConfig) | |
// yes... we need to cast to get at the factories... | |
//.asInstanceOf[CFMLEngineImpl] | |
println(engine) | |
val factory = engine | |
.getCFMLFactory(servletContext, servletConfig, new FakeHttpServletRequest) | |
val idCounter = 1 | |
val config = factory.getConfig | |
val pageContext = factory.getRailoPageContext( | |
servlet.asInstanceOf[HttpServlet], | |
new FakeHttpServletRequest, | |
new FakeHttpServletResponse, | |
"error-page-url", | |
false, | |
-1, | |
false) | |
val rootMapping = config.getMappings.toSeq.find(_.getVirtual == "/").getOrElse(error("Could not find root mapping")) | |
val classRootDirectory = rootMapping.getClassRootDirectory | |
val files = (sourceDir ** "*.cfc") | |
.get | |
.flatMap(IO.relativize(sourceDir, _:File)) | |
.map("/" + _) | |
files.foreach { path => | |
println("Compiling " + path) | |
val pageSource = rootMapping.getPageSource(path) | |
pageSource.loadPage(pageContext) | |
} | |
new File(classRootDirectory.getAbsolutePath) | |
} | |
val custom = taskKey[Unit]("custom task") | |
custom := (withServer in Railo).value { context => | |
println("context: " + context) | |
println((test in Test).value) | |
println("context: " + context) | |
} | |
def withConsoleReader[T](f: ConsoleReader => T): T = { | |
val consoleReader = new ConsoleReader | |
try f(consoleReader) finally consoleReader.shutdown() | |
} | |
def waitForKey(): Unit = { | |
withConsoleReader { consoleReader => | |
def waitEOF(): Unit = { | |
consoleReader.readCharacter() match { | |
case 4 | -1 => | |
// Note: we have to listen to -1 for jline2, for some reason... | |
// STOP on Ctrl-D or EOF. | |
case 11 => | |
consoleReader.clearScreen(); waitEOF() | |
case 10 => | |
println(); waitEOF() | |
case 13 => | |
println(); waitEOF() | |
case x => | |
print(String valueOf x.toChar) | |
waitEOF() | |
} | |
} | |
doWithoutEcho(waitEOF()) | |
} | |
} | |
def doWithoutEcho(f: => Unit): Unit = { | |
withConsoleReader { consoleReader => | |
val terminal = consoleReader.getTerminal | |
terminal.setEchoEnabled(false) | |
try f finally terminal.restore() | |
} | |
} | |
servletConfiguration in Railo := { | |
val railoConfigDir = (railoConfiguration in Railo).value.getAbsolutePath | |
val webXml = s"""|<?xml version="1.0" encoding="UTF-8"?> | |
|<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> | |
| <welcome-file-list> | |
| <welcome-file>index.cfm</welcome-file> | |
| <welcome-file>index.html</welcome-file> | |
| </welcome-file-list> | |
| <servlet> | |
| <servlet-name>CFMLServlet</servlet-name> | |
| <servlet-class>railo.loader.servlet.CFMLServlet</servlet-class> | |
| <init-param> | |
| <param-name>railo-web-directory</param-name> | |
| <param-value>$railoConfigDir</param-value> | |
| </init-param> | |
| <init-param> | |
| <param-name>railo-server-root</param-name> | |
| <param-value>lib/railo</param-value> | |
| </init-param> | |
| <load-on-startup>1</load-on-startup> | |
| </servlet> | |
| <servlet-mapping> | |
| <servlet-name>CFMLServlet</servlet-name> | |
| <url-pattern>*.cfm</url-pattern> | |
| <url-pattern>*.cfc</url-pattern> | |
| </servlet-mapping> | |
|</web-app>""".stripMargin | |
val webXmlFile = streams.value.cacheDirectory / "web.xml" | |
IO.write(webXmlFile, webXml) | |
webXmlFile | |
} | |
railoConfiguration in Railo := { | |
val railoConfigDir = streams.value.cacheDirectory | |
val sourceDir = (sourceDirectory in Railo).value.getAbsolutePath | |
val mappingName = name.value | |
val railoConfig = s"""|<?xml version="1.0" encoding="UTF-8"?><railo-configuration pw="" version="4.3"><cfabort/> | |
| <setting/> | |
| <data-sources> | |
| </data-sources> | |
| <resources> | |
| <resource-provider arguments="lock-timeout:10000;" class="railo.commons.io.res.type.s3.S3ResourceProvider" scheme="s3"/> | |
| </resources> | |
| <remote-clients directory="{railo-web}remote-client/"/> | |
| <file-system deploy-directory="{railo-web}/cfclasses/" fld-directory="{railo-web}/library/fld/" temp-directory="{railo-web}/temp/" tld-directory="{railo-web}/library/tld/"> | |
| </file-system> | |
| <scope client-directory="{railo-web}/client-scope/" client-directory-max-size="100mb"/> | |
| <mail> | |
| </mail> | |
| <search directory="{railo-web}/search/" engine-class="railo.runtime.search.lucene.LuceneSearchEngine"/> | |
| <scheduler directory="{railo-web}/scheduler/"/> | |
| <mappings> | |
| <mapping archive="{railo-web}/context/railo-context.ra" physical="{railo-web}/context/" primary="physical" readonly="yes" toplevel="yes" trusted="true" virtual="/railo-context/"/> | |
| </mappings> | |
| <custom-tag> | |
| <mapping physical="{railo-web}/customtags/" trusted="yes"/> | |
| </custom-tag> | |
| <ext-tags> | |
| <ext-tag class="railo.cfx.example.HelloWorld" name="HelloWorld" type="java"/> | |
| </ext-tags> | |
| <component base="/railo-context/Component.cfc" data-member-default-access="public" use-shadow="yes"> | |
| <mapping archive="{web-root-directory}/../archives/shared-1.1-SNAPSHOT.ra" inspect-template="" primary="archive" virtual="/shared"/><mapping archive="{web-root-directory}/../archives/libraries-1.0-SNAPSHOT.ra" inspect-template="" primary="archive" virtual="/libraries"/></component> | |
| <regional/> | |
| <debugging template="/railo-context/templates/debugging/debugging.cfm"/> | |
| <application cache-directory="{railo-web}/cache/" cache-directory-max-size="100mb"/> | |
| <logging> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/remoteclient.log" layout="classic" level="info" name="remoteclient"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/requesttimeout.log" layout="classic" name="requesttimeout"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/mail.log" layout="classic" name="mail"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/scheduler.log" layout="classic" name="scheduler"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/trace.log" layout="classic" name="trace"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/application.log" layout="classic" level="info" name="application"/> | |
| <logger appender="resource" appender-arguments="path:{railo-config}/logs/exception.log" layout="classic" level="info" name="exception"/> | |
| </logging> | |
| <rest/> | |
| <gateways/> | |
| <orm/> | |
| <cache default-object="defObj"> | |
| <connection class="railo.runtime.cache.ram.RamCache" custom="timeToIdleSeconds=0&timeToLiveSeconds=0" name="defObj" read-only="false" storage="false"/> | |
| </cache> | |
|</railo-configuration>""".stripMargin | |
val railoConfigFile = railoConfigDir / "railo-web.xml.cfm" | |
IO.write(railoConfigFile, railoConfig) | |
railoConfigDir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment