3

I've looked around a lot (trust me :) before posting this questions and I'm still confused. Here's the scenario:

Hosting a J2EE web-app on glassfish v3 using Restlet 2.0 The freemarker template files are located in the /WEB-INF folder. The templates link to jQuery/javascript files, some static images and stylesheets using relative URLs.

Since it's not a good practice to store them in /WEB-INF (as stated at many places on the web) I moved the files to the WebContent folder


WebContent:
+--Images
   -.jpg, .gif files
+--Styles
   -myStyle.css
+--Scripts
   +--jQLabel
   +--mColorPicker
      +--Images
      +--javascripts
         -.js files

I refer to them in the freemarker template/html as:

<link rel="stylesheet" type="text/css" href="${baseRef}/Styles/myStyle.css"  />

where ${baseRef} is the Root Reference of the site. The site is deployed at /Winbook. So the URL on the localhost for the css looks like this:

http://localhost:8080/Winbook/Styles/winbookwall.css <-- retrieved using a GET

Problem(s):

For each of the above resources I get a 404 :( I'm not sure if this is really how one should store css, images or scripts and whether the WebContent folder is a good place for it be stored.

Question(s):

  1. Why is the above not working? I mean there has to be a mistake and I just don't know about it :)
  2. What is the best place to store the above files on the web server/glassfish?
  3. How do I refer to those resources (in the HTML/freemarker template) if they are deployed in the .war? (They will get deployed in the war file if they are placed in WebContent, right? Is this 'legal' or good practice? Seems to smell :)
  4. Do we have to create alternate doc roots in glassfish for all such resources (or the equivalent Directory class in Restlet?)
  5. What is the 'best' way/place of/for such a deployment for an intranet based application to seamlessly locate the resources? JNDI based lookup? (I don't know how that would work, another question probably on SO ;)

I am totally confused! It's been a while since I had to write a full end to end web app and this was usually taken care of by the 'others' :)

Thanks!

PhD
  • 11,202
  • 14
  • 64
  • 112
  • If these resources are going to be loaded by clients via http, they go under WebContent and they'll go in the .war, as is right and 100% appropriate. Re. 3, when you say 'refer to these resources' do you mean access them from the sever side? You don't explicitly say this, but I can't think why else you're confused; static content goes under WebContent, no problem. – Jim Blackler Apr 12 '11 at 18:37
  • @Jim: by 'refer' I meant from the client browser. Even after doing that I still get 404s. I don't know if Restlet is intercepting the URLs and since it doesn't have a route to match it too it just returns a 404? Not sure, but can't figure out a way to get around it for almost 2 days now :P – PhD Apr 12 '11 at 18:55
  • Can you view any resources at all in the browser? – Jim Blackler Apr 12 '11 at 19:10
  • @Jim: Nope :( That's the first test that I did and I showed the URL that I'm trying to link to from the CSS – PhD Apr 12 '11 at 19:23
  • I'm stumped.. but if you can't see any http resources *at all* when running your project locally (and it's all under WebContent) I'd be looking at my server configuration, I'd also be looking in the server error logs for clues. – Jim Blackler Apr 12 '11 at 19:31
  • @Jim: So am I :) The error logs are just by Restlet stating a 404. I'm not sure how to handle that...and hence the question. I have put content under WebContent before and been able to link but this one tops the list of 'frustration' :) – PhD Apr 12 '11 at 19:50
  • @Jim: You may want to see the solution I posted :) – PhD Apr 21 '11 at 18:43

2 Answers2

1

I'm probably late on posting an answer to this but here it is. As I mentioned it Restlet intercepts the URLs and you HAVE to use the Directory class to return static content - initialized with the path "war:///" or "war:///images/" etc., for each of the folders.

The reason it wasn't working was with the Routing issues of Restlet - The directory folder was 'last' in the code order of URLs. Directories are created with Template.MODE_STARTS_WITH and the others (i.e., Restlets or other resources) are Template.MODE_EQUALS

You should either change the order of routing manually or push it at the top of the list of URIs when routing.

Hope that helps anyone stumbling on the same problem.

Here is the related question that Jerome answered: Restlet Routing Nightmare

Community
  • 1
  • 1
PhD
  • 11,202
  • 14
  • 64
  • 112
  • Hi, way too long after you've posted this but I'm giving it a shot here. My question is not exactly identical to your one, but I'm getting a 404 error for the images in my web application, which is hosted on glassfish. I then tried to store the images locally in various places but no luck(and I'm getting `Not allowed to load local resource` error). Any clue on where should I store the image files? My gut feeling is that glassfish server does not have access to the local directories I specified. If that's the case, I'm wondering where does it have access to. – akilat90 Jan 27 '17 at 10:58
0

Try "resource" JARs - see here : http://alexismp.wordpress.com/2010/04/28/web-inflib-jarmeta-infresources/

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Alexis MP
  • 750
  • 3
  • 8