Wiki source code of Dysoweb
Show last authors
1 | A Dysoweb application is at the same time an OSGi bundle and a mini "Web archive" (War) with some specificities (at least for the structure of the Web application) |
2 | |
3 | == OSGi Bundle == |
4 | |
5 | An OSGi bundle is usually a Jar file (altough at least Equinox and Felix support bundles as exploded directories) that contains some specific information in the manifest. |
6 | |
7 | Therefore, a Dysoweb application will get the following from its bundle structure: |
8 | |
9 | - META-INF/MANIFEST.MF |
10 | Contains the Bundle name, symbolic name, and version. |
11 | |
12 | Activator : A java class that will be called when the application is started (see extensive OSGi litterature on the subject) |
13 | The activator must declare a "WebAppService" that will be used by the Dysoweb processor to register the application: |
14 | |
15 | /* |
16 | |
17 | * (non-Javadoc) |
18 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) |
19 | */ |
20 | public void start(BundleContext context) throws Exception { |
21 | fWebApp = context.registerService(WebAppService.class.getName(), |
22 | new WebAppService(context.getBundle()) { }, |
23 | null); |
24 | } |
25 | |
26 | /* |
27 | |
28 | * (non-Javadoc) |
29 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) |
30 | */ |
31 | public void stop(BundleContext context) throws Exception { |
32 | // unregister the web app service |
33 | fWebApp.unregister(); |
34 | fWebApp = null; |
35 | }// |
36 | |
37 | |
38 | [[Creating an OSGi bundle>>DevelopOSGIBundle]] |
39 | |
40 | == Class path == |
41 | |
42 | This is an important point, since WEB apps and OSGi bundles have a different way of specifiying which classes should be loaded. |
43 | |
44 | In DysoWeb, the classes and librairies (jar) are loaded according to the OSGi spec, and are '''NOT loaded from WEB-INF/classes or WEB-INF/lib'''. They are loaded from the regular bundle class path (by default .), but it can be specified by the "Bundle-ClassPath" header in the manifest of the bundle. |
45 | |
46 | == Manifest Example == |
47 | |
48 | Manifest-Version: 1.0 |
49 | Bundle-ManifestVersion: 2 |
50 | Bundle-Name: Test Plug-in |
51 | Bundle-SymbolicName: com.requea.test |
52 | Bundle-Version: 1.0.0 |
53 | Bundle-Activator: com.requea.test.Activator |
54 | Import-Package: com.requea.dysoweb, |
55 | org.osgi.framework;version="1.3.0" |
56 | Bundle-ClassPath: bin/, |
57 | ., |
58 | lib/commons-lang-2.1.jar, |
59 | lib/commons-resources.jar |
60 | |
61 | |
62 | == Web App == |
63 | |
64 | The Web application content (static files, JSP, TLD, WEB-INF/web.xml) are put in the webapp directory in the bundle: |
65 | |
66 | Therefore, the structure of a Dysoweb app looks like: |
67 | |
68 | [[image:DysowebApp.png]] |
69 | |
70 | == web.xml == |
71 | |
72 | The web.xml defined in webapp/WEB-INF/web.xml has a typical servlet application structure. You can define servlets, servlets mappings, filter and filter mappings. |
73 | |
74 | <?xml version="1.0" encoding="ISO-8859-1"?> |
75 | <web-app> |
76 | <display-name>Demo4 WebApp</display-name> |
77 | <servlet> |
78 | <servlet-name>voteServlet</servlet-name> |
79 | <servlet-class>com.requea.dysoweb.demo4.VoteServlet</servlet-class> |
80 | <load-on-startup>1</load-on-startup> |
81 | </servlet> |
82 | <servlet-mapping> |
83 | <servlet-name>voteServlet</servlet-name> |
84 | <url-pattern>/demo4/vote</url-pattern> |
85 | </servlet-mapping> |
86 | </web-app> |