Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Loading local html in browser widget
Loading local html in browser widget [message #1122513] Tue, 01 October 2013 16:59 Go to next message
Julia Kurde is currently offline Julia Kurde
Messages: 66
Registered: November 2011
Location: Berlin, Germany
Member
Hi,

Is it possible to load an html file which is located in a plugin folder within the RAP?

I can get the server url and the context path of the application but then, how does it continue? Let's say the file is in the plugin [eub.jlzhtools] in folder [js/].

So, serverUrl + contextPath + pluginName + folderName + fileName =
http://127.0.0.1:50787/jLZHweb/eub.jlzhtools/js/chart.html

This leads to the error [ERR_TOO_MANY_REDIRECTS]
(A HttpServlet is registered to redirect to a welcome page)

Inserting also the servlet path [/web]
http://127.0.0.1:50787/jLZHweb/web/eub.jlzhtools/js/chart.html

leads to [HTTP ERROR: 404 Not Found]

Is it possible to access the file like this and, if yes,
how do I get the correct URL for it?

Thanks and regards, Julia

PS: I guess I have to register the file as resource, but somehow,
Thread.currentThread().getContextClassLoader().getResourceAsStream("js/chart.html");

always returns null, although the [js] folder is on the class path. Actually, how to check that? I thought it needs to be included the project's [bin] folder, which is defined in the build.properties file:
bin.includes = jlzhtools.jar,\
               META-INF/,\
               js/

[Updated on: Tue, 01 October 2013 17:59]

Report message to a moderator

Re: Loading local html in browser widget [message #1122559 is a reply to message #1122513] Tue, 01 October 2013 17:59 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1839
Registered: July 2009
Senior Member
Hi Julia,
you have to register the html as resource and get its path from the
resource manager - see MarkupExample#|registerImage|.

[ 1]
http://git.eclipse.org/c/rap/org.eclipse.rap.git/tree/examples/org.eclipse.rap.examples.pages/src/org/eclipse/rap/examples/pages/MarkupExample.java
HTH,
Ivan

On 10/1/2013 7:59 PM, Julia Kurde wrote:
> Hi,
>
> Is it possible to load an html file which is located in a plugin
> folder within the RAP?
>
> I can get the server url and the context path of the application but
> then, how does it continue? Let's say the file is in the plugin
> [eub.jlzhtools] in folder [js/].
>
> So, serverUrl + contextPath + pluginName + folderName + fileName =
> http://127.0.0.1:50787/jLZHweb/eub.jlzhtools/js/chart.html
>
> This leads to the error [ERR_TOO_MANY_REDIRECTS]
> (A HttpServlet is registered to redirect to a welcome page)
>
> Inserting also the servlet path [/web]
> http://127.0.0.1:50787/jLZHweb/web/eub.jlzhtools/js/chart.html
>
> leads to [HTTP ERROR: 404 Not Found]
>
> Is it possible to access the file like this and, if yes,
> how do I get the correct URL for it?
>
> Thanks and regards, Julia

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Loading local html in browser widget [message #1122618 is a reply to message #1122559] Tue, 01 October 2013 19:25 Go to previous messageGo to next message
Julia Kurde is currently offline Julia Kurde
Messages: 66
Registered: November 2011
Location: Berlin, Germany
Member
Hi Ivan,

Thanks for the link!
I really don't know, what I'm doing wrong, but
ClassLoader#getResourceAsStream always returns null!

I checked
a) the resource folder is on the class path
b) the class where I get the classLoader from is in the same plugin as the resource folder

What else can be the reason that the resource is not found?

Re: Loading local html in browser widget [message #1123159 is a reply to message #1122618] Wed, 02 October 2013 08:52 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1839
Registered: July 2009
Senior Member
Hi Julia,
where is the "resource" folder located - root of the bundle or in the
"src" folder? Did you check if the specified resource path is correct?
Best,
Ivan

On 10/1/2013 10:25 PM, Julia Kurde wrote:
> Hi Ivan,
>
> Thanks for the link! I really don't know, what I'm doing wrong, but
> ClassLoader#getResourceAsStream always returns null!
> I checked
> a) the resource folder is on the class path
> b) the class where I get the classLoader from is in the same plugin as
> the resource folder
>
> What else can be the reason that the resource is not found?
>
>

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Loading local html in browser widget [message #1123220 is a reply to message #1123159] Wed, 02 October 2013 10:22 Go to previous messageGo to next message
Julia Kurde is currently offline Julia Kurde
Messages: 66
Registered: November 2011
Location: Berlin, Germany
Member
I guess I found the problem:

It seems when calling ClassLoader#getResourceAsStream the complete stacktrace needs to stay in the plugin that contains the resource.

What I mean is that in a snipped where the resource is in the same plugin the resource is found, but when this snipped calls a method in a different plugin which is doing the registering in order to use the resource from the other plugin it will not be found.

So probably each plugin needs to have its own resources!
Re: Loading local html in browser widget [message #1125430 is a reply to message #1123220] Fri, 04 October 2013 13:57 Go to previous message
Julia Kurde is currently offline Julia Kurde
Messages: 66
Registered: November 2011
Location: Berlin, Germany
Member
There was some confusion on my site.... I just like to put my solution here, which finally works Very Happy

Static resources which are located in a folder named "js" under the plugin root are registered in the plugin.xml file (needs org.eclipse.equinox.http.registry in the dependencies):
<extension
      point="org.eclipse.equinox.http.registry.resources">
   <resource
         alias="/js-chart"
         base-name="js">
   </resource>
</extension>

html files which are generated during runtime are registered with the ResourceManager:
String fileName = "chart_" + System.currentTimeMillis() + ".html";
InputStream inputStream = new ByteArrayInputStream(htmlContent.getBytes());
try {
	RWT.getResourceManager().register(fileName, inputStream);
} finally {
	inputStream.close();
}

I'm using the currentTimeMillis to keep the file name unique. One could also use the session id plus a counter.
The nice thing is that I don't need to save this file, but get the input stream directly from the string (this resource should be unregistered when it is no longer needed).

In the html file static resources in the "js" folder (e.g. date_format.js) can be accessed like
<script language="javascript" type="text/javascript" src="../js-chart/date_format.js"></script>

Maybe someone finds this helpful Wink
Julia
Previous Topic:Error: AnimationRenderer failed: Cannot read property 'length' of null
Next Topic:[ANN] RAP 2.2 M2 is available
Goto Forum:
  


Current Time: Tue Oct 21 05:42:38 GMT 2014

Powered by FUDForum. Page generated in 0.02761 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software