Web Integration

Overview

Web integration is based on a standard org.osgi.service.http.HttpService that is provided by OSGi platform. But in addition to available functions - servlets and resources registration only, the framework supports almost all web application configuration features that are available in a common J2EE application. org.sevenhats.web.api.WebConfiguration interface and org.sevenhats.web.WebConfigurationImpl its implementation are base components of Web integration module. org.sevenhats.web.api.WebConfiguration interface describes functionality for web configuration that allows to get notification after configuration changing. org.sevenhats.web.WebConfigurationImpl implements this functionality and aggregates all information about servlets, filters, and other web resources that need to be registered. It includes data similar to servlet, servlet-mapping, filter, filter-mapping and welcome-file-list web.xml deployment descriptor elements.

Servlet Registration

org.sevenhats.web.api.ServletProvider provides API for registering servlets through ServletRegistrator interface. It is under the necessity to force servlet registration code to be executed in a servlet provider's bundle.

Filter Registration

org.sevenhats.web.api.FilterProvider interface should be implemented to register a filter. Initially, the framework registers only one system filter in the OSGi HttpService. This filter knows about other user-defined filters, and selects proper ones on each request in order to build appropriate filter chain for this request.

Welcome Files Support

org.sevenhats.web.api.WelcomeFileListProvider interface should be implemented to add new welcome file information.

Url Path Mapping Support

org.sevenhats.web.api.UrlMappingListProvider interface should be implemented to add new alias mapping information.

Exposed Services

Web bundle exposes org.sevenhats.web.api.WebConfiguration service for other bundles.

interface WebConfiguration {

	List<FilterProvider> getFilterProviders();

	List<ServletProvider> getServletProviders();

	List<WelcomeFileProvider> getWelcomeFileProviders();

	List<UrlPathMappingProvider> getUrlPathMappingProviders();

	void addWebConfigurationListener(WebConfigurationListener listener);

	void removeWebConfigurationListener(WebConfigurationListener listener);

}


Beans

Beans which are used in the Web Integration solution are described bellow.

1. org.sevenhats.web.WebConfigurationImpl bean implements org.sevenhats.web.beans.WebConfiguration interface.

WebConfigurationImpl bean that provides functioning of Web integration solution creates sevlets, filter servlets, and joins them (creates filter chain).

properties:

List<ServletProvider> servletProviders;
List<FilterProvider> filterProviders;
List<WelcomeFileProvider> welcomeFileProviders;
List<UrlPathMappingProvider> urlPathMappingProviders;

All properties of  this bean are lists of other beans of the Web Integration solution.
2. org.sevenhats.web.beans.WelcomeFileProviderBean bean implements org.sevenhats.web.api.WelcomeFileListProvider interface.WelcomeFileProviderBean bean provides mapping support of a some resource (file) to a necessary resource (for example, the 'index.xhtml' file can be mapped to the 'index.jsf' file).

properties:

List<WelcomeFileRegistration> files;

Class WelcomeFileRegistration contains properties resourceName and alias, where resourceName - source resource ('index.xhtml') and alias - destination resource ('index.jsp').

class WelcomeFileRegistration {    
private String resourceName;    
private String alias;    
...
}

3. org.sevenhats.web.beans.UrlPathMappingProviderBean bean implements org.sevenhats.web.api.UrlPathMappingListProvider interface.

UrlPathMappingProviderBean bean provides mapping support of a source url part to a necessary url path (for example, '/' can be mapped to '/org/sevenhats/smoreapp').properties:

List<UrlPathMappingRegistration> urlPathMappings;

Class UrlPathMappingRegistration contains properties sourceUrlPath ('/') and destinationUrlPath ('/org/sevenhats/smoreapp').

class UrlPathMappingRegistration {
private String sourceUrlPath;    
private String destinationUrlPath;    
...
}

4. org.sevenhats.web.beans.ServletProviderBean bean implements org.sevenhats.web.api.ServletProvider interface.

 ServletProviderBean bean allows to create new servlets and join mapping pattrens (some resources) to these servlets.

properties:

String name;
String mappingPattern;
Servlet servlet;
ApplicationContext applicationContext;
BundleContext bundleContext;
Properties initParameters;

5. org.sevenhats.web.beans.FilterProviderBean bean implements org.sevenhats.web.api.FilterProvider interface.

FilterProviderBean bean allows to map pattrens (filters) to created servlers by ServletProviderBean bean (i.e. this bean wides ServletProviderBean bean functionality) . 

properties:

Filter filter;
String name;
String mappingPattern;
String mappingServletName;
Properties initParameters;
Collection<String> dependencies;

Configuring Solution

Configuration contains several xml files which describe beans and OSGi services for Spring FrameWork and his components (web-context.xml, web-context-osgi.xml and jsf-context.xml and jsf-context-osgi.xml configuration). It's necessary to add some . WebIntegrattion registers OSGi service WebConfiguration и org.sevenhats.web.WebConfigurationImpl bean in files (web-context.xml and web-context-osgi.xml, see bellow). Other bundles can provide loading of beans and regestering them as OSGi services (jsf-context.xml, jsf-context-osgi.xml, smokeapp-context.xml, smokeapp-context-osgi.xml). Web Integration contains several bean implementations. These beans can be exported to other bundles and noticed as OSGi services  (WelcomeFileListProviderBean, UrlPathMappingListProviderBean, ServletProviderBean, FilterProviderBean). Tuning beans WelcomeFileListProviderBean and UrlPathMappingListProviderBean, it's possible to provide mapping a some Url resource to another Url resource (for example, source Url http://sevenhats.org:8080/index.xtml, destination Url http://sevenhats.org:8080/org/sevenhats/smokeapp/view/index.jsf).

Examples of solution

Examples of xml files, that provide configuration of flow are presented bellow:

1. Configuration file (web-context.xml) describes webConfiguration  bean and his properties:

 
	<bean id="webScopesRegistrator"
		class="org.sevenhats.web.ScopelessBundleRegistrator" />

	<bean id="webConfiguration"
		class="org.sevenhats.web.WebConfigurationImpl">
		<constructor-arg ref="webScopesRegistrator" />
		<property name="servletProviders" ref="servletProviders" />
		<property name="filterProviders" ref="filterProviders" />
 		<property name="welcomeFileProviders"  ref="welcomeFileProviders" />
 		<property name="urlPathMappingProviders"  ref="urlPathMappingProviders" />
 	</bean>

	<osgi:list id="servletProviders"
		interface="org.sevenhats.web.api.ServletProvider"
		cardinality="0..N">
		<osgi:listener ref="webConfiguration" bind-method="addServlet"
			unbind-method="removeServlet" />
	</osgi:list>

	<osgi:list id="filterProviders"
		interface="org.sevenhats.web.api.FilterProvider" cardinality="0..N">
		<osgi:listener ref="webConfiguration" bind-method="addFilter"
			unbind-method="removeFilter" />
	</osgi:list>

	<osgi:list id="welcomeFileProviders"
		interface="org.sevenhats.web.api.WelcomeFileProvider"
		cardinality="0..N">
		<osgi:listener ref="webConfiguration"
			bind-method="addWelcomeFiles"
			unbind-method="removeWelcomeFiles" />
	</osgi:list>

	<osgi:list id="urlPathMappingProviders"
		interface="org.sevenhats.web.api.UrlPathMappingProvider"
		cardinality="0..N">
		<osgi:listener ref="webConfiguration"
			bind-method="addUrlPathMappings"
			unbind-method="removeUrlPathMappings"/>
	</osgi:list>

2. Configuration file (web-context-osgi.xml) provides registering webConfiguration OSGi service.

<osgi:service ref="webConfiguration"
		interface="org.sevenhats.web.api.WebConfiguration" />

3. Configuration file (jsf-context.xml) describes several beans (these beans have been imported from web bundle). Every bean description contains information, how these beans have to be config

<bean id="facesServletProvider"
		class="org.sevenhats.jsf.FacesServletProvider">
		<constructor-arg ref="taglibProviders" />
	</bean>

	<bean id="welcomeFileProviderBean"
		class="org.sevenhats.web.beans.WelcomeFileProviderBean">
		<property name="files">
			<list>
				<bean
					class="org.sevenhats.web.api.WelcomeFileRegistration"
					p:resourceName="index.xhtml" p:alias="index.jsf" />
			</list>
		</property>
	</bean>

	<bean id="sessionFilterProvider"
		class="org.sevenhats.web.beans.FilterProviderBean"
		p:name="org.sevenhats.jsf.sessionhandler"
		p:mappingServletName="Faces Servlet" p:filter-ref="sessionFilter" />

4. Configuration file (jsf-context-osgi.xml) registes OSGi services imported from web bundle.

<osgi:service ref="facesServletProvider"
		interface="org.sevenhats.web.api.ServletProvider"
		context-class-loader="service-provider" />

	<osgi:service ref="welcomeFileProviderBean"
		interface="org.sevenhats.web.api.WelcomeFileProvider" />

	<osgi:service ref="sessionFilterProvider"
		interface="org.sevenhats.web.api.FilterProvider" />

5. Configuration file (smokeapp-context-.xml) registers one more instance of UrlPathMappingListProviderBean.

 	<bean id="urlPathMappingProvider"
		class="org.sevenhats.web.beans.UrlPathMappingProviderBean">
		<property name="urlPathMappings">
			<list>
				<bean
					class="org.sevenhats.web.api.UrlPathMappingRegistration"
					p:sourceUrlPath="/" p:destinationUrlPath="/org/sevenhats/smokeapp/view/" />
				<bean
					class="org.sevenhats.web.api.UrlPathMappingRegistration"
					p:sourceUrlPath="/org/sevenhats/smokeapp/" p:destinationUrlPath="/org/sevenhats/smokeapp/view/" />
			</list>
		</property>
	</bean>

6. Configuration file (smokeapp-context-osgi.xml) registers OSGi service.

<osgi:service ref="urlPathMappingProvider"
		interface="org.sevenhats.web.api.UrlPathMappingProvider" />
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.