Re: [Lift] How to get the servlet context

2009-11-30 Thread Heiko Seeberger
All this is brittle, at least special! Please use the temp dir the
servlet context will offer you. Tomcat and Jetty offer one.

Heiko

On Monday, November 30, 2009, jhonig al...@xs4all.nl wrote:
 Marius,

 I tried to create a link from the webapp dir to another location with
 rw-access, but that was not allowed...  My conclusion was that you
 can't have symbolic links to locations outside the war.

 My problem is that there are three different locations that could all
 be interpreted as a root for looking up resources.  I've found
 nothing
 suggesting one over the other, and none of them works.  I assume
 there are more variables involved that I don't even know of.

 Job

 On Nov 30, 10:27 pm, Marius marius.dan...@gmail.com wrote:
 Ok I may be missing something essential from all this thread but why
 not use a folder from the user's home directory? If your app runs say
 under jetty OS user should heve read/write rights to write on the
 home user file-system. Even if not (although I haven't encountered the
 case) those rights can be granted by an admin. So why do you need
 special container allocated locations to write files?

 Br's,
 Marius

 On Nov 30, 11:18 pm, jhonig al...@xs4all.nl wrote:

  Hi Tim, Jeppe, and others who have replied...

  I have spent a few more hours, but there are just too many variables
  and I haven't been able to figure them out.
  I logged the various locations (running under a standalone jetty, not
  mvn jetty:run, and got this:

    INFO - TEMP = /tmp/Jetty_0_0_0_0_8080_tent.
  0.1.SNAPSHOT.warvtra6b
    INFO - REAL = /tmp/Jetty_0_0_0_0_8080_tent.
  0.1.SNAPSHOT.warvtra6b/webapp
    INFO - URL = file:/tmp/Jetty_0_0_0_0_8080_tent.
  0.1.SNAPSHOT.warvtra6b/webapp/WEB-INF/classes/

  I tried to access images, both from the HTML served to my browser and
  from Scala snippets.   I used the
  following paths:

    Images/testimage.jpg
    work/Images/testimage.jpg
    classes/work/Images/testimage.jpg
    WEB-INF/classes/work/Images/testimage.jpg.

  The latter path is what I see in my .war file...   I have no special
  filters.  I tried to add entries to my site map,
  but none of them worked.  About to give up.  Hope somebody will help
  me.

  Job H.

  On Nov 28, 3:14 pm, jhonig al...@xs4all.nl wrote:

   Dear Tim and Heiko,

   I tested a few things under mvn jetty:run...:

     getRealPath gives me ./src/main/webapp
     the temp attribute is set to ./target/work
     and the location is ./target/classes

   While the war contains classes/work which is again different...   I
   didn't manage to get jetty to serve contents from any other directory
   than the first one.

   Didn't try to run it on the standalone jetty, since I still don't know
   how
   to tell jetty to serve contents that is not under the webapp
   directory.
   Probably have to do something with the site map which I don't fully
   understand.

   Guess my main problem is that I don't have any experience in this
   field (jetty/lift) and thought it wouldn't be to difficult to port my
   website
   to lift and enhance it a little on the fly.

   To be continued...

   Job Honig

   On Nov 28, 12:52 am, Timothy Perrett timo...@getintheloop.eu wrote:

Here's a nugget of information for you that will help (as I do 
something similar to what you want in one of my applications):

  val protectionDomain: ProtectionDomain = 
classOf[bootstrap.liftweb.Boot].getProtectionDomain()
  val location: URL = protectionDomain.getCodeSource().getLocation()

Print the value of location, and that will get you headed in the right 
direction ;-) Moreover, if your using jetty, if there is a work 
directory next to where the war file is, jetty will automatically 
expand the war into that work folder... if not, it makes a temp 
directory in the relevant OS temp directory (/var/tmp on *nix OS)

Godspeed.

Tim.

On 27 Nov 2009, at 21:49, Heiko Seeberger wrote:

 Job,

 

-- 
Heiko Seeberger

My job: weiglewilczek.com
My blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net

--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




Re: [Lift] How to get the servlet context

2009-11-27 Thread Ross Mellgren
A way you can get the Servlet context is like this:

LiftRules.context match {
 case context: HTTPServletContext = // do something with  
context.ctx which is the javax.servlet.ServletContext
 case _ = // do something when the context is not a servlet  
context, perhaps log an error
}

The reason you need the match is because Lift can run on non-servlet  
web containers, so Lift does not guarantee there is a Servlet context  
in scope.

Hope that helps,

-Ross

On Nov 27, 2009, at 10:51 AM, jhonig wrote:

 LS,

 After Ross' kind invitation to post any other questions I might have,
 I'll start with
 this one:

 The web application I am developing needs a scratch directory to white
 scaled
 images to.  I first try to use a subdir of /tmp and put a symbolic
 link in place to
 access that directory from my project's context.  However, this got me
 an
 error message (something about an aliased resource), so after some
 searching
 around I decided the best way is to create a directory inside WEF-INF
 and
 access it through getServletContext ().getRealPath (/...).

 From the APIdocs I found out that an instance of a ServiceContext is
 passed
 to HTTPServletContext, but I haven't been able to find if that is the
 instance I
 need, or how to get an instance of HTTPServletContext...

 Note: I am currently able to read/write temporary finds when running
 through
 mvn getty:run, but I need a solution that still works when I deploy a
 war with
 an existing jetty server.

 Thanks for any hints!

 Job Honig

 --

 You received this message because you are subscribed to the Google  
 Groups Lift group.
 To post to this group, send email to lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com 
 .
 For more options, visit this group at 
 http://groups.google.com/group/liftweb?hl=en 
 .



--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




Re: [Lift] How to get the servlet context

2009-11-27 Thread Heiko Seeberger
According to the Servlet spec each webapp has got a private temporary
directory. I cannot remember exactly how to get this, maybe
ServletContext.getTmpDir(). Please take a look at the spec.

Heiko

On Friday, November 27, 2009, jhonig al...@xs4all.nl wrote:
 Thanks Ross, I will try this!   Is there a generic way to get to a
 kind
 of sandbox directory where snippets can read/write files?

 Job

 On Nov 27, 5:12 pm, Ross Mellgren dri...@gmail.com wrote:
 A way you can get the Servlet context is like this:

 LiftRules.context match {
      case context: HTTPServletContext = // do something with
 context.ctx which is the javax.servlet.ServletContext
      case _ = // do something when the context is not a servlet
 context, perhaps log an error

 }

 The reason you need the match is because Lift can run on non-servlet
 web containers, so Lift does not guarantee there is a Servlet context
 in scope.

 Hope that helps,

 -Ross

 On Nov 27, 2009, at 10:51 AM, jhonig wrote:

  LS,

  After Ross' kind invitation to post any other questions I might have,
  I'll start with
  this one:

  The web application I am developing needs a scratch directory to white
  scaled
  images to.  I first try to use a subdir of /tmp and put a symbolic
  link in place to
  access that directory from my project's context.  However, this got me
  an
  error message (something about an aliased resource), so after some
  searching
  around I decided the best way is to create a directory inside WEF-INF
  and
  access it through getServletContext ().getRealPath (/...).

  From the APIdocs I found out that an instance of a ServiceContext is
  passed
  to HTTPServletContext, but I haven't been able to find if that is the
  instance I
  need, or how to get an instance of HTTPServletContext...

  Note: I am currently able to read/write temporary finds when running
  through
  mvn getty:run, but I need a solution that still works when I deploy a
  war with
  an existing jetty server.

  Thanks for any hints!

  Job Honig

  --

  You received this message because you are subscribed to the Google
  Groups Lift group.
  To post to this group, send email to lift...@googlegroups.com.
  To unsubscribe from this group, send email to 
  liftweb+unsubscr...@googlegroups.com
  .
  For more options, visit this group 
  athttp://groups.google.com/group/liftweb?hl=en
  .

 --

 You received this message because you are subscribed to the Google Groups 
 Lift group.
 To post to this group, send email to lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/liftweb?hl=en.




-- 
Heiko Seeberger

My job: weiglewilczek.com
My blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net

--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.