Development Tools and Deployment
Development Tools and Deployment
- Controller Class
Spring uses the Rest Controller classes to handle the REST service lifecycle.
We have supplied an example for such Controller: ExampleController.
In this example we will demonstrate the authentication, access to database and configuration class utilities we supply as out-of-the-box services built in to CLEK.
- Application Class
Every Spring Boot application requires a main class, the CLEK main class is ExtensionsApplication and this class content must NOT be changed
- WebSecurityConfig Class
WebSecurityConfig class supplies the campusM authentication
Framework and should be using the security filter;those filters should not be removed but more filters may be added as needed.
Since the services are deployed as a .war file, we provide a web.xml which has the following entries which should be changed:
- Start-up servlet to load configuration and database setting
- Basic tomcat authentication for the campusM user (same as set in the application manager)
- Optional path to configuration (see here)
This is Spring Boot’s main settings file and optionally may hold the path to the configuration files (see here)
CLEK utilities and support classes
To enable the Authentication for a specific REST service, you must annotate the service with the annotation – @PreAuthorize(“isAuthenticated()”) which applies campusM authentication filters on the REST request.
Also, you may annotate the Controller class with this annotation, which will impact all the REST services in that class.
We recommend that the databases setting and configuration data for REST services not be hard-coded in the code, but should be kept in json configuration files for easier maintenance.
Under src/main/configuration, you can see a few JSON configuration files examples.
The path to these configuration files can be edited in one of the following files:
- properties file – set the property campusm.configuration.path.
- xml file – set the context-param PATH_TO_CONFIGURATION.
ConfigurationManager class handles the access to the configuration; if needed inject it to your controller.
For example, in the ExampleController class:
An example for a configuration file may be found under src/main/configuration: “grades.json”:
To retrieve the information in that json file you may use the ConfigurationManager per the following:
The ConfigurationManager will use the path to the configuration files (from the application.properties or the web.xml files), and will return the configuration data of the requested file as a JSON object.
All database info required for your REST services should be kept in the “datasources.json” configuration file (located under src/main/configuration).
Each database’s info will have a data source name which will be used to retrieve the information of that database.
In the datasources file above there is only one datasource defined named “test”. You can retrieve this datasource in your code using the ConfigurationManager per the following:
You may use QueryRunner to exeute queries and map the results into objects, as is shown in the example above.
The CLEK uses the log4j mechanism embedded in it, including default log4j.properties.
Example can be found in ExampleController below.
The logs can then be found on the Tomcat CL server under the “logs” folder. You can change the settings of where the logs will be printed out to in the log4j.properties file.
Debugging your Application Server Locally
The application can be deployed on a local Tomcat (as Spring Boot app) by running as a Java application using the main method of the ExtensionsApplication class.
You can then use the value of the parameter listed in the application.properties class in the property “server.contextPath” as the name of your application in the url.
If your application.properties class is set as follows:
Your URL would be the following::
Deploy on Tomcat Server
- Create a .war file from your extension kit application project (please see Set the maven launcher section).
- Upload the .war file to the webappsfolder on each Connect Layer Tomcat server. Please make sure you have enough memory for an extra .war file and folder.
Recommended machine sizing and specification can be found in –
Under “Machine Memory Sizing” section.
- Create a folder (i.e. configuration) for the json files in the conf folder on the Tomcat server, this folder will hold the json configuration files with the data (for more info please see Configuration Files).
- Extract the json files from the .war file (under \configuration folder) to the configuration folder created above (in 4).
- Make sure that the application points correctly to the configuration folder (for more info please see Configuration Files).
You are then able to call the application using the following URL pattern: