Register   Login   About   Study   Enterprise   Share
AI / Internet Technology University (AITU)
Fast Login - available after registration







|

Top Links: >> 80. Technology >> Internet Technology Summit Program >> 4. Web Apps Frameworks >> 4.4. Spring with Apache Maven and Data Service Frameworks >> 4.4.4.Data Service Framework and Troubleshooting >> 4.4.4.6.Data Service Library
Current Topic: 4.4.4.6.1. Handling actions and related configurations
You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
Handling actions and related configurations

The main configuration-environment parameters are placed in the web.xml file.
Services are provided via the Rest API with essential parameter, called action.

The basic class com.its.util.ItsBaseServlet, which plays the role of a controller in the traditional Model-View-Controller (MVC) architecture, interprets such APIs as calls to an action class.

The Data Service framework does not use complex mapping schemes.
Instead there are naming conventions.

According to the naming convention the name of the action class contains the name of action in the Rest API and ends with the word Action.
For example, the Rest API can include the parameter action = login.
The framework will call the Java class LoginAction.

All Action classes are implemented the com.its.util.BaseAction interface.
All Action classes are usually located in the same directory, which is defined in the web.xml file.
The Action classes start the business logic processing and represent the Model tier for a specific service.

Action classes usually call Data Services classes located in the com.its.ds package.
In the end of this MVC processing control is passed to the View, which can be implemented with the Java Service Pages (JSP) located, for example, in the jsp directory.

Due to many reasons, the View tier with their screens are often changed.
To achieve necessary flexibility, screens are filled with configuration parameters.

In the Data Service framework, JSP files have same names as related actions and all parameters for the action and JSP are stored in a configuration file.
For example, the parameters and messages for LoginAction class and login.jsp are stored in the file login-messages.txt.

A standard location for action-configuration files is under config/its-msg
There are configuration parameters common for all actions.
They are located in the config/configuration.txt file
All SQL statements are located in config/sql - directory in the one-two line files, like getUserName.sql

Directory hierarchy looks this way:

BASE
- config
- sql
o getUserName.sql
o ....
- configuration.txt
- its-msg
o login-messages.txt
o register-messages.txt
o ......

When and how this information is processed?

When we start an application, for example, BASE, the class loader will load the classes, including the controller class, ItsBaseServlet.
This class implements the HttpServlet interface.
This means that on loading there will be automatic invocation of the contextInitializrd() method.
The Data Service framework includes two major initializations placed in this method:
- Initializing data sources with their pool connections, via the DataService.initData() method.
o During this initialization all SQL statements are cached and if necessary, new tables are created according to the descriptions, usually stored in the web.xml file.

- Reading and caching all configuration parameters via the ConversationManager.init() method.

Web applications, which are exposed to more than one country, can store navigation instructions and text messages in the configuration files, like en-login-messages.txt - for English speaking users and sp-login-messages.txt - for Spanish speaking users.

Besides DB and configuration initialization there might be the need for other initialization actions.
Such initializers are provided with their class names as another context parameter, initializers, in the web.xml file.


Sample
Was it clear so far?

For example,


initializer

com.its.helpers.ConversationManager



Such initializer classes implements the com.its.util.BaseInitializer interface and must include the init() methods, see example in the ConversationManager class.




Assignments
Assignments:
1. Create a small application with two services, register and login.
2. Provide necessary SQL statements in the config/sql - directory
3. Provide major environment and DB parameters in the web.xml - file
4. Provide common parameters in the config/configuration.txt - file
5. Provide necessary configuration parameters for login and register actions in the config/its-msg/login-messages.txt and register-messages.txt
6. Test, Debug and make it work!
7. Rename the configuration files into en-configuration.txt, en-login-messages.txt, en-register-messages.txt
8. Add two more sets of configuration files with the prefix sp- for Spanish texts and ru- for Russian texts.
9. Add to the web.xml file a new parameter, language, and make sure you can provide any prefix: en, sp, or ru.
10. Add an initialization class com.its.util.LanguageChooser that must have the method init(String dsName) and will check the language parameter.
The web.xml file will be modified to:


initializer

com.its.util.LanguageChooser,com.its.helpers.ConversationManager



In the LanguageChooser class include the methods:

public String init(ServletContext context) {
String appName = Stats.getAppDetailsByKeyName("its", "appName");
if(context != null) {
appName = context.getInitParameter("appName");
}
return init(appName);
}
public String init(String dsName) {
String appName = Stringer.getAppNameOfDsName(dsName);
String language = Stats.getAppDetailsByKeyName(appName, "language");
String pathToDeploy = Stats.getAppDetailsByKeyName(appName, "pathToDeploy");
String pathToConfig = pathToDeploy+appName+"/config";
boolean success = IOMaster.copy(pathToConfig+"/"+language+"-configuration.txt", pathToConfig+"/configuration.txt");
success = IOMaster.copy(pathToConfig+"/its-msg/"+language+"-login-messages.txt", pathToConfig+"/its-msg/login-messages.txt");
success = IOMaster.copy(pathToConfig+"/its-msg/"+language+"-register-messages.txt", pathToConfig+"/its-msg/register-messages.txt");
}

This init() method will copy a specific-language configuration file, for example, en-configuration.txt into a generic configuration.txt. Then the generic configuration files will be used as usual.
11. Test, Debug and make it work!

Send the source to dean@ituniversity.us

References:
Check the library at http://JavaSchool.com/downloads/com.its.zip


| Check Your Progress | Propose QnA | Have a question or comments for open discussion?
<br/> <context-param>
<br/>    <param-name>initializer</param-name>
<br/>    <param-value>
<br/>com.its.helpers.ConversationManager
<br/>    </param-value>
<br/>  </context-param> 
<br/>

Such initializer classes implements the com.its.util.BaseInitializer interface and must include the init() methods, see example in the ConversationManager class.




Assignments
Assignments:
1. Create a small application with two services, register and login.
2. Provide necessary SQL statements in the config/sql - directory
3. Provide major environment and DB parameters in the web.xml - file
4. Provide common parameters in the config/configuration.txt - file
5. Provide necessary configuration parameters for login and register actions in the config/its-msg/login-messages.txt and register-messages.txt
6. Test, Debug and make it work!
7. Rename the configuration files into en-configuration.txt, en-login-messages.txt, en-register-messages.txt
8. Add two more sets of configuration files with the prefix sp- for Spanish texts and ru- for Russian texts.
9. Add to the web.xml file a new parameter, language, and make sure you can provide any prefix: en, sp, or ru.
10. Add an initialization class com.its.util.LanguageChooser that must have the method init(String dsName) and will check the language parameter.
The web.xml file will be modified to:
<br/> <context-param>
<br/>    <param-name>initializer</param-name>
<br/>    <param-value>
<br/>com.its.util.LanguageChooser,com.its.helpers.ConversationManager
<br/>    </param-value>
<br/>  </context-param> 
<br/>

In the LanguageChooser class include the methods:
<br/>	public String init(ServletContext context) {
<br/>		String appName = Stats.getAppDetailsByKeyName("its", "appName");
<br/>		if(context != null) {
<br/>			appName = context.getInitParameter("appName");
<br/>		}
<br/>		return init(appName);
<br/>	}
<br/>    public String init(String dsName) {
<br/>    	String appName = Stringer.getAppNameOfDsName(dsName);
<br/>       String language = Stats.getAppDetailsByKeyName(appName, "language");
<br/>	String pathToDeploy = Stats.getAppDetailsByKeyName(appName, "pathToDeploy");
<br/>       String pathToConfig = pathToDeploy+appName+"/config";
<br/>       boolean success = IOMaster.copy(pathToConfig+"/"+language+"-configuration.txt", pathToConfig+"/configuration.txt");
<br/>               success = IOMaster.copy(pathToConfig+"/its-msg/"+language+"-login-messages.txt", pathToConfig+"/its-msg/login-messages.txt");
<br/>success = IOMaster.copy(pathToConfig+"/its-msg/"+language+"-register-messages.txt", pathToConfig+"/its-msg/register-messages.txt");
<br/>}
<br/>

This init() method will copy a specific-language configuration file, for example, en-configuration.txt into a generic configuration.txt. Then the generic configuration files will be used as usual.
11. Test, Debug and make it work!

Send the source to dean@ituniversity.us

References:
Check the library at http://JavaSchool.com/downloads/com.its.zip



| Check Your Progress | Propose QnA | Have a question or comments for open discussion?

Have a suggestion? - shoot an email
Looking for something special? - Talk to me
Read: IT of the future: AI and Semantic Cloud Architecture | Fixing Education
Do you want to move from theory to practice and become a magician? Learn and work with us at Internet Technology University (ITU) - JavaSchool.com.

Technology that we offer and How this works: English | Spanish | Russian | French

Internet Technology University | JavaSchool.com | Copyrights © Since 1997 | All Rights Reserved
Patents: US10956676, US7032006, US7774751, US7966093, US8051026, US8863234
Including conversational semantic decision support systems (CSDS) and bringing us closer to The message from 2040
Privacy Policy