Menu

How dispatcher fulfill request?

When clients send HTTP requests to the web server, the URL of the requested page must be resolved to the content in the Dispatcher cache, and eventually to the content in the repository.

 

  1. The domain name system discovers the IP address of the web server which is registered for the domain name in the HTTP request.
  2. The HTTP request is sent to the web server.
  3. The HTTP request is passed to Dispatcher.
  4. Dispatcher determines whether the cached files are valid. If valid, the cached files are served to the client.
  5. If cached files are not valid, Dispatcher requests newly-rendered pages from the AEM publish instance.

References

Reading excel data in Java Sprint Boot

In this article, we will walk through the steps and program which we need to develop to read the excel data in Java program or spring boot application.

1. Maven dependency 

There is an Apache POI library that we need to add to our project, that will help us to easily perform read and write with excel. 


<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.2</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.1.2</version>
</dependency>

2. Apache POI

A major use of the Apache POI api is for Text Extraction applications such as web spiders, index builders, and content management systems.
The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.

There are four types of API available in Apache POI, that we can use to extract the text from different types of files.
  1. POIFS: POIFS APIs are used if you had a document written in OLE 2 Compound Document Format, probably written using MFC, that you needed to read in Java.
  2. HSSF: HSSF APIs are used if you needed to read or write an Excel file using Java (XLS).
  3. XSSF: XSSF APIs are used if you need to read or write an OOXML Excel file using Java (XLSX).
  4. SXSSF: SXSSF APIs can be used for large excel files, that allows you to write very large Excel (XLSX) files in a memory optimized way.
The above summary has been written from Apache POI documentation. To read and explore more about POI you may visit the official Apache POI site. https://poi.apache.org/ 

3. Reading from an excel file

After importing the required dependency let's see a sample program that will help us to read the text from an excel sheet.
An excel sheet name "role_mapping_sheet.xlsx" having the following data. This excel sheet you need to keep in the project and it path we have to define in the program. Below is the snapshot of excel data.

Now, we need to create a model class that maps the value of these two columns into two class variables.

RoleTableModel.java
/**
 * 
 */
package serialization;

/**
 * @author rashid
 *
 */
public class RoleTableModel {
	
	public RoleTableModel(String title) {
		super();
		this.title = title;
	}

	public RoleTableModel() {
	}

	private String title;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public String toString() {
		return "RoleTableModel [title=" + title + "]";
	}
}


Now, see the actual implementation class where we are performing the extraction. Below is the class InsertRoleData.java 

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thymeleaf.util.ClassLoaderUtils;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import serialization.RoleTableModel;


public class InsertRoleData {
	Workbook workbook;
	private static final Logger LOGGER = LoggerFactory.getLogger(InsertRoleData.class);
	public List<RoleTableModel> getExcelDataAsList() {
		
		List<String> list = new ArrayList<String>();
		int noOfColumns = 0;
		try {
			FileInputStream file = new FileInputStream(new File("src\\main\\resources\\static\\role_mapping_sheet.xlsx"));
			workbook = new XSSFWorkbook(file);
			Sheet sheet = workbook.getSheetAt(0);
			noOfColumns = sheet.getRow(0).getLastCellNum();

			for (Row row : sheet) {
				for (Cell cell : row) {
					String cellValue = cell.toString();
					list.add(cellValue);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		List<RoleTableModel> allRoles = createList(list, noOfColumns);
		LOGGER.info("Number of columns: "+noOfColumns);
		return allRoles;
	}
	
	private List<RoleTableModel> createList(List<String> excelData, int noOfColumns) {

		ArrayList<RoleTableModel> invList = new ArrayList<RoleTableModel>();

		int i = noOfColumns;
		do {
			RoleTableModel inv = new RoleTableModel();
			inv.setTitle(excelData.get(i));
			LOGGER.info("role model "+inv.toString());
			invList.add(inv);
			i = i + (noOfColumns);
			
		} while (i < excelData.size());
		LOGGER.info("role model list "+invList.toString());
		return invList;
	}
	
}

You may now simply run your spring boot or java application and read the text from excel sheet cell by cell. Hope this helps you in implementation. If you face any issue while implementation of Apache POI, feels free to ask your question in the comment section. Thank You!

Maven project configuration for module is not available

Build failed | computer programming guide
Maven build failed.

Maven resources compiler: Maven project configuration required for module '<project name>' isn't available. Compilation of Maven projects is supported only if external build is started from an IDE.

Solution

Right click on the POM.xml file of your project and click on the option "Add as Maven Project".

This will import your project as the Maven project and starts downloading the dependencies. 




Cloud Manager timeout

While using the cloud manager to build and deploy the code on Adobe Experience Manager (AEM), the default waiting time at a step is 7 days. If we left the pipeline waiting at any step for more than 7 days then the pipeline automatically gets failed.


Cloud Manager Pipeline
Cloud Manager Pipeline. Image Source Adobe Experience League


Reference 

datatables_table_0 - requested unknown parameter

While working with DataTable we may encounter some issues, and because of that on the load of DataTable we are seeing an alert that says "datatables warning: table id=datatables_table_0 - requested unknown parameter '<columnName>' for row 0, column 3". For me, this alert was showing because all the JSON objects which we were providing to create the table don't have consistent properties. In few objects column3 was present but in few column3 property is not present. To identify the issue with the column you may verify the column number mentioned in the alert and the same column number that we mentioned in the aoColumns(as showing in the below code snippet).

aoColumns: [
{ mData: 'column1' },
{ mData: 'column2' },
{ mData: 'column3' }]

After adding the column3 property in all objects data table start working perfectly.

Hope this helps you to investigate the data table issue.

Difference between the Process Thumbnails and Create Thumbnail workflow steps in AEM

Create thumbnail and process thumbnail workflow steps in AEM
Workflow steps
 
The Create Thumbnail step only creates thumbnail renditions for an asset, while the Process Thumbnails step can also create a folder thumbnail and web-enabled renditions also. 

Path or directory where Dispatcher cached files?

Question: Under which directory or path AEM dispatcher server cached the data or files?


Answer: Dispatcher server cached the files under path /var/www/html/. Here you will find the /apps, /content, /libs, and /etc(client libraries).


To read and understand more on dispatcher configs and settings, please visit Experience Manager Dispatcher.

Different between sudo and sudo su?

Sudo runs a single command with root privileges and Sudo su switches you to the root user account after that all your commands will be executed with root privileges.

No goals have been specified for this build

When we started a maven project without setting the run goal then the Maven build will get failed and generate the below error "No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]". 

In this case, we have to set the maven goal e.g. clean install to successfully build and run the project or application. 

Resolution

If you are running using IDE then please set the command line as mentioned below and restart the build. To set the command line with IntelliJ, please go to Run >> Edit Configurations >> Select your project >> Select Parameters tab from left >> put clean install in command line field.

Now rerun the maven build.


Error while running the Maven project.

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.882 s
[INFO] Finished at: 2021-06-09T07:28:32+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException

Process finished with exit code 1

Diamond operator is not supported in source

While running a Java project with IntelliJ, we might face an error stating "diamond operator is not supported in -source 1.5", which means we are trying to run the project on a lower version of Java which is developed on a higher version.

Error statement 

java: diamond operator is not supported in -source 1.5

  (use -source 7 or higher to enable diamond operator)


Solution/Apply the following fix

Go to File option from menu >> Project Structure >> Project Settings >> Modules. Here in Module, we need to use the higher version of language level under the Source tab 


Hope this helps you!



Cast an object to Integer in Java

We could cast an object that have integer value into an integer using below Java code.

int value = Integer.parseInt(object.toString());