How to serve media in Lift app? - lift

I am trying to migrate a simple django app to lift, but I can't seem to find a way to serve a simple image file!
Here is how it was in my django app:
<img src="/site_media/images/logos.jpg" />
Is there equivalent "site_media" directory where I can point lift (I am running jetty in eclipse right now)?
Any help appreciated!

In Boot.scala, you have to tell lift to let certain files be handled by the container (jetty or tomcat or whatever you're using).
LiftRules.passNotFoundToChain = true
LiftRules.liftRequest.append {
case Req("my_stuff" :: _, _, _) => false
}

Turns out I just needed to put my images into the src/webapp folder in my project. So for the above path to work, the image should be in src/webapp/site_media/images/logos.jpg.

Related

Revel framework and Go code completion

is is possible to use Revel framework with Go code completion support. As far as i know the gocode utility requires the code to be compiled into a library into a pkg subfolder in order to function, but the framework does compilation on the fly.
I am kind of lost on the topic. Would the proper way be calling the go install for relevant subpackages? That seems to work but it is not the most elegant way of doing this from my perspective.
Hope that someone can point me in right direction.
EDIT: the problem is focused only on sources that I write as part of my Revel application. Downloaded packages have autocompletion as expected
EDIT2: This is the best solution I have found so far - executing go get command on your project's app/tmp subfolder. So if your project is called my_project then you would call something like go get my_project/revel/app/tmp Because this folder contains the main function for the project, it will pull all the dependencies and build them into packages. If the tmp folder does not exist you have to do revel run on your project and open your web app so it gets created on the fly. Hope this helps at least a bit. I am still open for a better alternative :)
You revel application needs to reside inside of your $GOPATH/src folder and then code completion will work for your web app.
Update
Either the process of compilation by Revel's harness has changed or gocode has been improved. But everything works now out of the box. No additional efforts are required.
Old answer
I have faced the same problem. My solution is a modified version of your EDIT 2 workaround.
In my app/init.go I added:
import "os/exec"
and
// Build the project packages on app start so it's possible to use autocomplete.
revel.OnAppStart(func() {
if revel.Config.BoolDefault("mode.dev", false) {
go func() {
_, err := exec.Command("go", "get", "bitbucket.org/USERNAME/PROJECT/app/tmp").Output()
if err != nil {
revel.ERROR.Printf("failed to 'go get' project, error: %v", err)
}
}()
}
})
So, now in dev mode it automatically recompiles all the packages on every recompilation of revel project.

Play framework 2 with sass and compass config file

I am testing stuff with scala, play framework 2.1.1 and I wanted to add sass with compass stylesheets using the compass plugin "compass-normalizer". For the sass part I am using the jlitola plugin.
I already got play working with sass and compass but using compass plugins has proven to be a nightmare for me. I have tried adding it as a ruby requirement:
SassPlugin.sassOptions := Seq("--compass","-r","compass-normalizer")
This was just a try and obviously didn't work because normalizer needs compass to be already initialized, however I can make it work from the terminal if I have the contrib.rb compass config file where I call sass #sassfile# --compass.
In that way of thinking I tried adding the contrib.rb file in the play project with no luck. I tried to add it to the app, conf and project folders with the same luck in all of them.
Can someone tell me what am I doing wrong?
It looks like it's just using the "current working directory" when running (see: https://github.com/jlitola/play-sass/blob/master/src/main/scala/SassCompiler.scala#L16). This is using a shady implicit to convert the Seq[String] => ProcessBuilder.
So, you may be able to put the contrib.rb file in the default directory (should be where you're running sbt from) and have the work. If not, according to the JVM docs:
The default value is the current working directory of the current process, usually the directory named by the system property user.dir.
So you could make a task that prints this in sbt to see what it is:
TaskKey[Unit]("show-user-dir") := println(sys.props("user.dir")

Gwt Tomcat Deploy : Just Does Nothing

if I deploy my project to the Tomcat server which uses just client side code , it works perfectly.
But if my project has a server side code , for example, a button which uses RPC , when i clicked the button, project does nothing at all. No Warnings, no errors etc. Just does nothing at all.
And also, when I deploy "the default GWT example ( greetings project )" to the Tomcat server, it doesn't work.
( I mean my problem is not related with my project's code )
p.s. : My project works perfectly in the Dev Mode.
Could you help me please?
Let us say, wWhen you run on dev mode, your URL was
localhost:port#/page1.
And that the war file name is happy.
Therefore, when you deploy to Tomcat, the server no longer serves it as localhost:port#/page1.
Your app would now be served as
localhost:port#/happy/page1
In your rpc remote service interface file you would have specified the relative path as "/page1".
However, you have to check your web.xml and make sure the servlets are specified in relative paths as well. Check your web.xml to ensure the servlet paths are not hard-coded to
localhost:port#/page1.

Play framework weblogic 10.3.3.0 deployment

I built a Play app and tried to deploy on weblogic using the following commands:
play war -o myApp myApp
Later I just deployed the exploded war directory to weblogic, everything worked fine but everytime I try to access a route. I get the following error:
Not found
GET /myApp/params
This is a rest service not an application with UI's. I tried to deploy on tomcat and everything worked fine but I had to make the application context root to be /. I tried the same thing with weblogic but it did not work.
Here is my route file:
GET / Application.index
GET /sectorinformer/{telephone} Application.show
GET /sectorinformer/public/ staticDir:public
* /{controller}/{action} {controller}.{action}
And here is my controller code:
package controllers;
import models.InstalAddress;
import models.SectorInfo;
import play.Logger;
import play.mvc.Controller;
public class Application extends Controller {
public static void index() {
render();
}
public static void show(String telephone) {
Logger.debug("Starting request");
Logger.debug("domain: '%s'", request.domain);
String instalAddressId = InstalAddress.getInstalAddressId(telephone);
SectorInfo si = new SectorInfo();
si.initializeSectorInfo(instalAddressId);
renderXml(si.generateXmlResponse());
}
}
Thanks in advance for any help.
Weblogic 10 is a fully compliant J2EE 5 application server, as a consequence it is bundled with JPA 1.0.
There are two little issues to get Play running on weblogic.
Applying an Oracle patch to have weblogic support JPA 2.0
Adding a deployment descriptor property to prioritize class resolution from web-inf
Both are trivial and the Play documentation should probably mark weblogic 10 as a working deployment target.
To fix #1, open to following oracle link.
For the lazy readers, add this declaration at the top of wlserver/common/bin/commEnv.sh
export PRE_CLASSPATH=$MW_HOME/modules/javax.persistence_1.0.0.0_2-0-0.jar:$MW_HOME/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar
for windows, the file is wlserver/common/bin/commEnv.bat
set PRE_CLASSPATH=%MW_HOME%/modules/javax.persistence_1.0.0.0_2-0-0.jar;%MW_HOME%/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar
To fix #2, create the file weblogic.xml at the following location myplayapp/war/WEB-INF/weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
The war folder is automatically picked up by play war when the web archive is built.
That's it!
I personally believe Play should create weblogic.xml itself, but that's not how it works as of 1.2.1
Unfortunately I don't have either weblogic know nor time to investigate in you interesting problem. I can only can give you some hints what I would do:
Try to connect the app with a debugger or if this doesn't work checkout the Code and build your own version, with a lot of log-statements.
As far as I know every request will handled by ActionInvoker. invoke. Look how the argument comes in. The other point is the Router, which has still a lot of trace-logs. So perhaps you start first and let the whole stuff run on trace-level. Perhaps that give you some hint's where to look in more detail.
To do this start with a clean app and make no configuration tricks, specially don't run it in ROOT-Context. Just create play war myapp -o myapp.war --zip and deploy it (Don't forget --zip). Then analyze the log.
Good look.
Niels
I deployed my Play app (play 1.1.1) to Websphere 6.1 and I encountered some issues. Not sure you have the same issues but here there are (hope it can help you):
1- JDK version: My "play war xxxx --zip" use a JDK 1.6, and Websphere 6.1 uses a JDK 1.5. When I tried to launch my webapp an UnsupportedClassVersionException was thrown. I regenerated my war file using the correct JDK et voilĂ  !
2- When you deploy a war aplication to Websphere, you can specify the context's name. I don't know how to do it with Weblogic, but did you set the correct value ?
As Niels said, analyze logs files: you should find what happens !
Unfortunately, Play! doesn't support Weblogic.
See: http://www.playframework.org/documentation/1.2/deployment

Advice on creating self contained project, and distributing a web server with the source code

I need some advice on configuring a project so it works in development, staging and production environments:
I have a web app project, MainProject, that contains two sub-projects, ProjectA and ProjectB, as well as some common code, Common. It's in a Subversion repository. It's nearly all HTML, CSS and JavaScript.
In our current development environment we check MainProject out, then set up Apache virtual hosts to point at each of the sub-project's directories, as paths within each project are relative to their root. We also have a build process that then compiles each of the sub-projects into their own deliverable package, with the common code copied into each.
So - I'm trying to make development of this project a bit easier. At the moment there is a lot of configuration of file paths in Apache http.conf files, as well as the build.xml file and in a couple of other places too.
Ideally I'd like the project to be checked out of SVN onto a fresh computer, with a web server as part of the project, fully configured, that can then be run from the checkout directory with very little extra configuration, either on a PC or Mac. And I'd like anyone to be able to run the build to compile it too.
I'd love to hear from anyone who has done something like this, and any advice you have.
Thanks,
Paul
If you can add python as a dependency, you can get a minimal HTTP server running in less than ten lines of code. If you have basic server side code, there is a CGI server as well.
The following snippet is copied directly from the BaseHTTPServer documentation
import BaseHTTPServer
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
I've done this with Jetty, from within Java. Basically you write a simple Java class that starts Jetty (which is a small web server) - you can make then this run via an ant task (I used it with automated tests - Java code made requests to the server and checked the results in various ways).
Not sure it's appropriate here because you don't mention Java at all, so apologies if it's not the kind of thing you're looking for.