Embedding Xpeak(ing) into a Java Applet
Sebastian November 27, 2012
 
Hello everyone,

I have been working with Xpeak and Xpeaking for a while and I had not come across real problems til now.

My issue, as said in the title, is related to embedding the entire solution (Xpeak + Xpeaking) in a java Applet running in a web browser (Google Chrome).

First of all, I decided to use the Embedded Java Xpeak server, would you have discarded this choice for any reason?

Now, what really matters. The problem appears when trying to load configuration files from the web server. I've managed to load the Xpeaking.properties file through a URL pointing to the Applet's codebase:

URL XpeakingProperties = new URL( getCodeBase(), 'configuration/Xpeaking.properties');

XClassManager.getReference().setRepository( XpeakingProperties);

So far so good. But at this point I have not come up with the way of loading the files referenced inside Xpeaking.properties from the web server too. My Xpeaking.properties contains the following:

server.Embedded.configurations.url=file:///C:/xpeak/configuration/
server.Embedded.services.path=C:/xpeak/XpeakServices.jar

Obviously, this is working locally, but in a real environment those paths won't exist and I probably won't be able to create them previously.

So, my question is:

Is there a way to load configuration files and the jar containing Xpeak services remotely from the web server? I have tried the following with no luck:

server.Embedded.configurations.url=http://myserver.mydomain/configuration/
server.Embedded.services.path=http://myserver.mydomain/XpeakServices.jar

I think the first one should work, but cannot be sure because the second one makes my applet crash.

Thank you in advance.

Greetings!!,

Seb.

Fernando November 29, 2012
 
Hi,

Same problem here! From what I have been researching, the problem is that there is not support to load services by URL. The path of the services must be a local path:

server.Embedded.services.path=C:/xpeak/XpeakServices.jar

Fortunately, source code is available, so the solution is very simple:

at org.xpeak.xpeaker.devices.server.XClassServerManager.getDevicesFromJarFile()

You will find the code that loads the services from the jar file, so you can change it to support URL's:


private void getDevicesFromJarFile( String path)
{
InputStream TheStream = null;

if( path.startsWith( 'http')) {
TheStream = new URL( path).openStream();
} else {
/* current code*/
}
}

This change allows you to use a path with this format:

server.Embedded.services.path=http://myserver.mydomain/XpeakServices.jar


I hope you find it useful,

Regards,

Maria November 29, 2012
 
Hi, good issue Sebastian and very good solution Fernando!!

This source code modification will be included in the next Xpeaker version published.

Have a nice day!