Creating Web Applications
You can create a basic web application using the yempty extension template.
To create a web application within SAP Commerce, do the following:
-
Create new extension using templates,
-
Apply Spring MVC framework.
-
Apply Platform filters.
-
Rebuild SAP Commerce
Create A New Extension
SAP Commerce provides a set of extension templates that can be used to create a new extension. For the list of available extension templates see also Creating a New Extension. To create a basic web application it is enough to use yempty extension template.
For more information, see Creating a New Extension.
Apply Spring MVC Framework
Your web application has to be created using Spring MVC framework. See also Spring Framework in SAP Commerce, section Using Spring MVC. Follow the instruction below to apply Spring MVC:
-
Download the latest release of Spring MVC library.
-
Put the JAR file into the web/webroot/WEB-INF/lib directory of your extension. If you use the SpringSource Tool Suite, reference this library in the build path of your project.
-
Add a servlet definition to the web.xml file located in the web/webroot/WEB-INF directory of your extension. Add the following lines:
web.xml
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> -
Now add the servlet context XML file in which you can define the controller for the servlet. Create a new file with the name extensionname-servlet.xml in the web/webroot/WEB-INF directory.
-
Add the following code to the extensionname-servlet.xml file:
extensionname-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> </beans>This file is used by the servlet automatically according to the Spring naming convention.
Apply Platform Filters
Currently every web application requires Platform filters, which are triggered on every HTTP request. The most important actions during an HTTP request are making sure that:
-
A session is properly handled
-
A catalog version is set as expected
Platform Filter Chain
The Platform filter chain solution gives you a possibility to easily set up a custom filter chain for your web application. This filter chain may contain only necessary filters without unnecessary logic. Every web application can be different and you may not need all filter functionality. For example, you do not need the ProfileFilter, which measures the time taken by HTTP request, for every Web application. The Platform by default provides some filters: These should not be excluded from your custom filter chain. There are also several additional filters which you can use. You may also develop your own filter and add it to your filter chain.
Figure: This diagram shows the default Platform filter chain registered in platformservices extension and a custom Platform filter chain registered in any web application.
Below you can find a short description of the most important filters necessary for your web application:
-
SessionFilter One of the mandatory filters. It has to handle the session properly for every request: it checks if there is already a jaloSession() attached to the HTTP session and activates it or creates a new one. Also some additional actions are done, for example session replication. Only if the session is correctly activated, can the filter chain successfully continue handling another functionalities.
-
Log4jFilter Mandatory filter that makes sure to store the remote IP address before the request gets processed and removes it afterwards.
-
CatalogVersionActivationFilter Even though these filters are not mandatory and not included in the default Platform filter chain, they contains very important functionalities needed for most of web applications. The main functionality covered by these filter are:
-
SimpleCatalogVersionActivationFilter: It assures that configured names of catalog versions are set as session catalog versions. Mentioned configuration is done through Spring property activeCatalogVersions.
-
DynamicCatalogVersionActivationFilter: It takes care for activating the catalog versions at runtime. It allows to activate them also with proper URL parameter.
-
SAP Commerce is shipped also with other filters, which can be easily included in every single web application. For the list of all available filters see also Platform Filters, section Available Filters.
Configure Custom Filters Chain
To configure your own filters chain you need to:
-
Create the filter chain in a Spring application context of your extension with:
-
Mandatory filters instantiated by default in the platformservices extension.
-
Other filters shipped with SAP Commerce. For the list of all available filters, see also Platform Filters.
-
You own custom filters. For instruction on how to create a new filter, see also Platform Filters
-
-
Activate the filter chain and set the mapping correctly in the web.xml file of your extensions.
For more details see also Platform Filters.