Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a quick hack to run lift-example in GAE/J.
  * InetAddress is not available.
  * Scala's structual subtyping is not functional, bucause it will use
    java.lang.reflect.*
  * SessionMaster.start will throw an exception.
  * jdbc is not available, DB has been disable at this time.
  * lift-example's comet based clock can not run on GAE/J, it has been disabled.
  • Loading branch information
ymnk committed Apr 10, 2009
1 parent 5049765 commit fd81a29
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lift-util/src/main/scala/net/liftweb/util/Props.scala
Expand Up @@ -126,7 +126,10 @@ object Props {
/**
* The resource path segment corresponding to the system hostname.
*/
val hostName = InetAddress.getLocalHost.getHostName + "."
// TODO InetAddress is not available on GAE/J
// Should it be configurable in Boot.scala?
//val hostName = InetAddress.getLocalHost.getHostName + "."
val hostName = "GAE/J" + "."

/**
* The list of paths to search for property file resources.
Expand Down
27 changes: 22 additions & 5 deletions lift/src/main/scala/net/liftweb/http/LiftServlet.scala
Expand Up @@ -493,11 +493,28 @@ class LiftServlet extends HttpServlet {
var len = 0
val ba = new Array[Byte](8192)
val os = response.getOutputStream
len = stream.read(ba)
while (len >= 0) {
if (len > 0) os.write(ba, 0, len)
len = stream.read(ba)
}
// TODO
/**
* stream is given as structual subtyping,
* {def read(buf: Array[Byte]): Int}
* and it is not functional on GAE/J, because java.lang.reflet.*
* is used internally. To work around this problem,
* the casting to 'java.io.InputStream' should be tried.
*/
stream match{
case stream:java.io.InputStream =>
len = stream.read(ba)
while (len >= 0) {
if (len > 0) os.write(ba, 0, len)
len = stream.read(ba)
}
case _ =>
len = stream.read(ba)
while (len >= 0) {
if (len > 0) os.write(ba, 0, len)
len = stream.read(ba)
}
}
response.getOutputStream.flush()
} finally {
endFunc()
Expand Down
8 changes: 8 additions & 0 deletions lift/src/main/scala/net/liftweb/http/LiftSession.scala
Expand Up @@ -202,6 +202,14 @@ object SessionMaster extends Actor {
}
}

// TODO On GAE/J, we can not make a thread.
// If you use LiftRules.dispatch.prepend, SessionMaster will start
// automatically, and it will throw an exception.
override def start()={
try{ super.start }
catch{ case _:java.lang.ExceptionInInitializerError => this }
}

this.start

private def doPing() {
Expand Down
8 changes: 8 additions & 0 deletions sites/example/src/main/scala/bootstrap/liftweb/Boot.scala
Expand Up @@ -40,12 +40,20 @@ import Actor._
*/
class Boot {
def boot {

// TODO Unfortunately, jdbc is not available on GAE/J.
// JPA should be used.
/*
DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
*/
LiftRules.addToPackages("net.liftweb.example")

LiftRules.localeCalculator = r => definedLocale.openOr(LiftRules.defaultLocaleCalculator(r))

// TODO
/*
Schemifier.schemify(true, Log.infoF _, User, WikiEntry, Person)
*/

LiftRules.dispatch.prepend(NamedPF("Web Services Example") {
// if the url is "showcities" then return the showCities function
Expand Down
7 changes: 5 additions & 2 deletions sites/example/src/main/webapp/templates-hidden/default.html
Expand Up @@ -73,9 +73,12 @@ <h3 class="alt">simply functional</h3>
<hr/>
<div class="column span-6 colborder sidebar">
<lift:menu.builder/>


<!-- // CometActor is not functional on GAE/J -->
<!--
<div class="widget" style="text-align: center"><lift:comet type="Clock">Current Time: <clk:time>Missing Clock</clk:time></lift:comet></div>

-->

<div class="widget">
<center><b>Group Chat</b></center><br />
<lift:comet type="Chat">Chat Text</lift:comet>
Expand Down

0 comments on commit fd81a29

Please sign in to comment.