Call external images/video/other resources from external folder with (embebbed) jetty from GWT

195 views
Skip to first unread message

n3k0

unread,
Sep 13, 2013, 3:34:42 PM9/13/13
to google-we...@googlegroups.com
Hi.
I actually have a trouble with calls to external resources like image/video. I read in the jetty docs, and some examples on the internet, and i found i have to do
a configuration like this:

<Configure id="parentHandler" class="org.mortbay.jetty.handler.ContextHandler">
    <Set name="contextPath">/folder_name_of_static_resources</Set>
 <Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set> <Set name="handler"> <New class="org.mortbay.jetty.handler.ResourceHandler"> <Set name="cacheControl">max-age=3600,public</Set> </New> </Set> </Configure>

So, in my code, i want to get an image, in the form:

GWT.getModuleBaseURL()+"/folder_name_of_static_resources/the_image.jpg"

But, when jetty runs, it marks

Result: 404 image not found

Now, why i want to do in this way?
I want to get video from a form, and after that, can view it in a videoplayer. i don't want to use a database (blob) because some files can be too heavy (5 to 100 MB aprox) so, i want to save and recovery from a filesystem.

I can't use GAE, nor other web server (like tomcat) but i'm sure that my requeriment can be satisfied if i resolve this configuration; and i suppose that the configuration can works in a embebbed jetty(GWT included) and a regular jetty server.
Can you give a hand?
Thanks in advance.




Thomas Broyer

unread,
Sep 14, 2013, 7:45:40 AM9/14/13
to google-we...@googlegroups.com
getModuleBaseURL returns the "folder" where the *.nocache.js lives. You probably need getHostPageBaseURL, which is the "folder" in which your HTML page (which loads the *.nocache.js file) lives.

Also, those methods return a value that ends in "/", so you don't need to append "/" to it: GWT.getHostPageBaseURL() + "folder_name_of_static_resources/the_image.jpg"

Natanael Maldonado

unread,
Sep 20, 2013, 2:05:00 AM9/20/13
to google-we...@googlegroups.com
Ok, you're right in :
 You probably need getHostPageBaseURL, which is the "folder" in which your HTML page (which loads the *.nocache.js file) lives.

And:

Also, those methods return a value that ends in "/", so you don't need to append "/" to it: GWT.getHostPageBaseURL() + "folder_name_of_static_resources/the_image.jpg"

BUT, it still does not works:

Code:

DivElement outerSpaceImage = DOM.getElementById("outerSpaceImage").cast();
Element img = DOM.createImg();
img.setAttribute("src", GWT.getHostPageBaseURL()+"folder_name_of_the_static_resources/image/the_image.jpg");
outerSpaceImage.appendChild(img);


XML (modified):

<Configure id="sample" class="org.mortbay.jetty.webapp.WebAppContext">

<Array id="plusConfig" type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
</Array>


<New id="handler" class="org.mortbay.jetty.handler.ContextHandler">
<Set name="contextPath">/folder_name_of_the_static_resources</Set>
<Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set>
<Set name="handler">
<New class="org.mortbay.jetty.handler.ResourceHandler">
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</New>
</Configure>



Error:


[WARN] 404 - GET /folder_name_of_static_resources/image/the_image.jpg (127.0.0.1) 1436 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      Accept: image/webp,*/*;q=0.8
      User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: en-US,en;q=0.8
      Cookie: JSESSIONID=1fgoy48j2k9md
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1436


So, same error is present =(





Reply all
Reply to author
Forward
0 new messages