Generate SSL Certificate and add it to JVM and Tomcat

# Steps to generate a certificate file in linux.
# Keep a common password whenever asked during the process. Commonly used password is "changeit".
# Minimum requirement - openssl and jdk must be installed.
# In this example domain name used for demonstration is "localhost".

# Run these commands in the same order as written.

# Generate a key
 

openssl genrsa -des3 -out localhost.key 1024 

# Generate a local certificate sigining request.
# In this step some information related to company will be asked to enter, keep in mind that "common name" must be the domain name.
 

openssl req -new -key localhost.key -out localhost.csr 

# Generate a certificate from csr file, it has validity of 365 days.  
openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
 

# Generate a pem file  
openssl pkcs12 -export -in localhost.crt -inkey localhost.key -out localhost.pem 

# Generate a keystore file which will be placed in tomcat. 
sudo keytool -importkeystore -deststorepass changeit -destkeypass changeit -destkeystore localhost.keystore -srckeystore localhost.pem -srcstoretype PKCS12 -srcstorepass changeit -srcalias 1 -destalias localhost 

# Add certificate in jvm 
sudo keytool -import -alias localhost -file localhost.crt -keystore /usr/lib/jvm/jdk1.6.0_33/jre/lib/security/cacerts 

# Modification of server.xml in tomcat 
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/home/mukesh/Documents/keystore/localhost.keystore" keystorePass="changeit"/>
 

 # File type explanation
  1. .csr file - This is a Certificate Signing Request. Some applications can generate these for submission to certificate-authorities. It includes some/all of the key details of the requested certificate such as subject, organization, state, whatnot. These get signed by the CA and a certificate is returned. The returned certificate is the public certificate, which itself can be in a couple of formats.
  2. .pem file -  This is the public-key of a specific certificate in X.509 format. This is also the format used for Certificate Authority certificates.
  3. .key file - This is the private-key of a specific certificate.
  4. .pkcs12 .pfx .p12 file - A passworded container format that contains both public and private certificate pairs. It can be broekn it into .key and .pem files.
  5. .cert, .cer, .crt file - A .pem file with a different extension in X.509 format. This extension is recognized by Windows Explorer as a certificate, which .pem is not.
Read More

Remove grid lines completely from excel jasperreports

Jasperreports version - 4.5.0
Apache poi version - 3.7

Jasperreports uses apache poi for xls report generation but for xlsx report generation it uses its own ooxml implementation so you have to modify both of these libraries to remove excel grid lines completely.

For XLS - Line 744, File location - poi-3.7-src/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
   HSSFSheet sheet = new HSSFSheet(this);
+ sheet.setDisplayGridlines(false);


For XLSX - Line 97, File location - jasperreports-4.5.0/src/net/sf/jasperreports/engine/export/ooxml/XlsxSheetHelper.java
- write("<sheetPr><outlinePr summaryBelow=\"0\"/></sheetPr><dimension ref=\"A1\"/><sheetViews><sheetView workbookViewId=\"0\"");
+ write("<sheetPr><outlinePr summaryBelow=\"0\"/></sheetPr><dimension ref=\"A1\"/><sheetViews><sheetView workbookViewId=\"0\" showGridLines=\"false\"");
Read More

Report design not valid

If content of a section doesn't fit in a page then following exception is thrown by jasperreports design validator. There are many ways to get rid of this exception.

  1. Increase your report's page height. But if you are not sure about subreport's height then this option might not work for you.
  2. If you are using dynamic reports (Wrapper around jasperreports) and suppose you are adding subreport in summary section then specifying summary split type to IMMEDIATE will solve the problem.
JasperReportBuilder reportBuilder = report().setSummarySplitType(SplitType.IMMEDIATE);

net.sf.dynamicreports.jasper.transformation.ComponentTransform$SubreportExpression evaluate
SEVERE: Error encountered while creating subreport design
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. The summary section and the margins do not fit the page height.
at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:258)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:140)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:212)
at net.sf.dynamicreports.jasper.transformation.ComponentTransform$SubreportExpression.evaluate(ComponentTransform.java:473)
at net.sf.dynamicreports.jasper.base.JasperScriptlet.getValue(JasperScriptlet.java:56)
at net.sf.dynamicreports.jasper.base.JasperCustomValues.getValue(JasperCustomValues.java:112)
at Report_1335085550494_722509.evaluate(Report_1335085550494_722509:202)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:876)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:284)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:347)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:275)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:257)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:473)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1067)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1032)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:296)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:135)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:836)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:765)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
Read More

Google Ad sense sign up error

Problem:
Error
We apologize for the inconvenience, but we are unable to process your request at this time. Our engineers have been notified of this problem and will work to resolve it.

Solution:
This problem occurs when you retry same thing again and again. So you need to sign out from the google account reopen the browser possibly open Internet Explorer and clear cookies and cache then try to sign up again. It will work.
Read More

How to set Java CLASSPATH Environment variable

Set Java Environment Variable on Windows 7 and Windows vista
Right click on My Computer, go to properties and then click on Advanced System Settings.
Now click on Environment Variables , Add JAVA_HOME path in system variables and then change Path system variable to add one more path. Details are described in below picture.
Set Java Environment Variable on Windows XP
Right click on My Computer, go to properties and then click on Advanced.
Now click on Environment Variables , Add JAVA_HOME path in system variables and then change Path system variable to add one more path. Details are described in below picture.

Set Java Environment Variable on Ubuntu/Unix
Edit .bashrc file in the home directory and add following lines at the end. Note JAVA_HOME should point to your jdk installation directory.
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

To check whether path has been set correctly or not type echo $JAVA_HOME at the command prompt, you should get result /usr/lib/jvm/java-6-sun.
Read More