Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Packaging resources into a "web" bundle
icon5.gif  Packaging resources into a "web" bundle [message #1663363] Tue, 10 March 2015 11:40 Go to next message
Alessandro Da Rugna is currently offline Alessandro Da RugnaFriend
Messages: 43
Registered: December 2014
Member
I've created a bundle which serves webpages using OSGi HttpService, much like org.eclipse.kura.web bundle. I start the bundle into the emulator and it works fine, I can retrieve webpages and call servlets. However I'm unable to correctly deploy such bundle into a running kura instance.
Using mToolkit to install to remote OSGi container from within Eclipse correctly installs the bundle but I get 404 on all static resources, servlets work ok. I suspect my resources inside "www" folder (symlink to src/main/webapp) are not deployed.
Creating a *.dpp file requires a "Resource Processor" to be set, and Eclipse proposes only "org.osgi.deployment.rp.autoconf". This mess up with the bundle install.
2015-03-10 11:13:28,553 [DeploymentAgent] ERROR o.e.k.d.a.i.DeploymentAgent - Exception installing package at URL file:/tmp/myweb.dp
org.osgi.service.deploymentadmin.DeploymentException: No resource processor for resource: 'www/index.html'
        at org.apache.felix.deploymentadmin.spi.ProcessResourceCommand.execute(ProcessResourceCommand.java:119)
        at org.apache.felix.deploymentadmin.spi.DeploymentSessionImpl.call(DeploymentSessionImpl.java:73)
        at org.apache.felix.deploymentadmin.DeploymentAdminImpl.installDeploymentPackage(DeploymentAdminImpl.java:214)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installDeploymentPackageInternal(DeploymentAgent.java:462)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.installer(DeploymentAgent.java:315)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent.access$0(DeploymentAgent.java:300)
        at org.eclipse.kura.deployment.agent.impl.DeploymentAgent$1.run(DeploymentAgent.java:184)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)


This is my activate method.
protected void activate(BundleContext context, Map<String,Object> properties) {
		s_logger.info("Activate");
		
		HttpContext httpCtx = new OpenHttpContext(m_httpService.createDefaultHttpContext());	
		try {
			m_httpService.registerResources("/site", "www/index.html", httpCtx);
			m_httpService.registerResources("/sitestatic", "www/static", httpCtx);
			
			m_httpService.registerServlet("/rest/status", new StatusServlet(), null, httpCtx);
			m_httpService.registerServlet("/rest/network", new NetworkingServlet(), null, httpCtx);
		} catch (NamespaceException e) {
			s_logger.error("No http", e);
		} catch (ServletException e) {
			s_logger.error("No servlet", e);
		}
}


I would like to build a deployment package (*.dp file, as the modbus bundle) containing a "web" bundle, how do I include my resources? Is maven the only way?


My project: Kura web log level changer https://github.com/darugnaa/kura-web-log
My blog: http://darugnaa.github.io
Re: Packaging resources into a "web" bundle [message #1667023 is a reply to message #1663363] Wed, 11 March 2015 23:44 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello Alessandro,

The static html content should be in the jar of your web bundle. How are you constructing the bundle (maven-war-plugin)? I would recommend manually extracting your bundle's jar file and examining the contents. The archive should have a "www" directory at the root.

For deployment packages, I don't think you want the static html files in your deployment package. Again, the static content should be in the web bundle. According to the DeploymentAdmin specification, only files ending in *.jar are handled natively. For any other resources, you must specify a class file to tell the DeploymentAdmin how to handle the file(s).

Thanks,
--Dave
Re: Packaging resources into a "web" bundle [message #1668765 is a reply to message #1667023] Thu, 12 March 2015 16:33 Go to previous messageGo to next message
Alessandro Da Rugna is currently offline Alessandro Da RugnaFriend
Messages: 43
Registered: December 2014
Member
I resolved half of the problem. Please forgive me if I use wrong terms but I'm not a maven expert.
I compile using maven-war-plugin and assemble with maven-assembly-plugin, packaging as a jar.
The resulting jar's content is:
unzip org.darugna.alessandro.webexample-1.0.0.jar 
Archive:  org.darugna.alessandro.webexample-1.0.0.jar
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    
   creating: org/
   creating: org/darugna/
   creating: org/darugna/alessandro/
   creating: org/darugna/alessandro/webexample/
  inflating: org/darugna/alessandro/webexample/OpenHttpContext.class  
  inflating: org/darugna/alessandro/webexample/StatusServlet.class  
  inflating: org/darugna/alessandro/webexample/WebConsole.class  
   creating: www/
   creating: www/static/
  inflating: www/index.html          
  inflating: www/static/jquery-1.11.2.min.js  
  inflating: www/static/yeah.jpg     
   creating: OSGI-INF/
  inflating: OSGI-INF/web.xml 

This jar is an OSGi bundle, when deployed it serves a basic website. So far so good, but how to deploy it remotely?
mToolkit in Eclipse does not embed the www/* resources and thus I cannot install on remote instances. I thought to use Maven to build a *.dp instead of a *.jar to remote deploy and update my website using Kura's DEPLOY-V1 cloudlet but no luck (that's why I'm interested in Franz Schnyder's question [2]).
I rolled my own "make this a DP" script [1], it would be nice to have this feature with Maven's POMs I just don't know where to start. I used a single POM for my web example, when declared as a module of a parent POM Maven wouldn't use Tycho's P2 local repos/ Tycho's compiler and just raise errors. I don't understand why since the plugins and dependencies are the same, just declared in different files. I'd like to just "mvn clean verify" and have a deployment package with all my bundles in, but I think it will take less time to just write some bash scripts to glue together all the build artifacts.


[1] https://github.com/darugnaa/deployment-package-example/blob/master/org.darugna.alessandro.webexample/make_deployment_package.sh
[2] https://www.eclipse.org/forums/index.php/t/1028830/


My project: Kura web log level changer https://github.com/darugnaa/kura-web-log
My blog: http://darugnaa.github.io
Re: Packaging resources into a "web" bundle [message #1680396 is a reply to message #1668765] Tue, 17 March 2015 00:44 Go to previous message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

Sorry if I missed understood your question. It sounds like you have a working web bundle and that bundle works as a deployment package if you create the deployment package manually . Is that correct? So, you are looking to create the deployment package as part of the build process? I was a little confused by your statement about the POM files. Is your web bundle building correctly as part of the Maven build? The Tycho compiler errors can be difficult to debug, if you are having build errors please post your bundle's POM file and the error you are seeing. This problem I believe is a bit different than Franz, who is trying to distribute and build his code without having the Kura target platform on his local machine. We don't have a good solution for this yet, but are working on it. One thing to make clear, the Maven local repository (~/.m2/repository) is different than the P2 repository in Kura (~/target-definition/common/repository/). You must be explicit in Maven when you are referencing a P2 repository.

If your web bundle is building correctly and you have the JAR file, you should be able to create the deployment package as part of the build. As you are aware, the DP is nothing more than a JAR file with a special manifest. So, you could use the Maven antrun plugin [1] to create the JAR with an ant jar task [2]. Let me know if you need an example of this.

[1] http://maven.apache.org/plugins/maven-antrun-plugin/
[2] https://ant.apache.org/manual/Tasks/jar.html

Thanks,
--Dave
Previous Topic:How to keep the bundle even when kura restarts
Next Topic:Question regarding CloudClient.release()
Goto Forum:
  


Current Time: Sat Apr 27 03:10:25 GMT 2024

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

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

Back to the top