Learn Perl in 2 hours: hour-1

Introduction:
Perl was originally developed for string manipulation and unix scripting in 1987, since then it has evolved and now its mainstream programming language which is used for a wide range of tasks including system administration, web development, network programming and GUI development. The best thing about Perl is that it's easy to use, efficient and complete. It supports both procedural and object-oriented programming (OOP), it has powerful built-in support for text processing as well and it also has impressive collections of third-party modules. Perl comes per-installed on unix systems, if its not or you are using windows system then download its installer and make sure that perl can be found in your system classpath. In this tutorial I have provided enough example code with explanation directly written above the code as a comment. Please copy this code, run it and play with it while learning.

Hello World:
Perl code can be written in simple text editor, I am using vim on unix. Create hello.pl file and put following code into this file. To run this program just type on command line: hello.pl
#!/usr/bin/env perl

# Its a good practice to start perl file with below two lines.
# It will stop execution of program if a potential problem occurs.
use strict;

# Only generates warning but let program continue when a potential problem occurs.
use warnings;

print "Hello World \n";
Variables:
Variables in perl can be defined in two ways one starting with 'my' keyword and other without it. Defining a variable with keyword 'my' is recommended as it stricts the scope of variable within the intended context when program executes.
# Scalar holds single value, starts with $
my $scalar_var = "I am scalar";

# Array holds multiple value, starts with @
my @array_var = (1,2,3,4,5);

# Hash holds multiple value, starts with %
my %hash_var = (1,'red',2,'green',3,'blue');
my @keys = keys %hash_var;
my @values = values %hash_var;

# To print a value stored in a variable, just put it with $/@ sign in double quote after print
# keyword, To print only integer there is no need to put it in double quote.
print "scalar_var = $scalar_var \n";
print "array_var = @array_var \n";
print "hash_keys = @keys, hash_values = @values \n";

# Multi-line print without \n
print <<ANYMARKER; 
To write multiple lines without using new line character in perl you have to 
follow a syntax starting with << and then  a string then and then actual string 
content. And then in a new line you have to close that delimeter string.
ANYMARKER

Output:
scalar_var = I am scalar
array_var = 1 2 3 4 5
hash_keys = 1 3 2, hash_values = red blue green
To write multiple lines without using new line character ...

Conditions:
print "Enter a number \n";
my $num = readline STDIN;
chomp $num;

# Simple if
if($num > 10) {
 print "From if: > 10, val: $num \n";
}

# if-else
if($num > 10) {
 print "From if-else: > 10, val: $num \n";
}
else {
 print "From if-else: < 10, val: $num \n";
}

# if-elseif
if($num > 10) {
 print "From if-elseif: > 10, val: $num \n";
}
elsif($num < 10) {
 print "From if-elseif: < 10, val: $num \n";
}

# if-elseif-else
if($num > 10) {
 print "From if-elseif-else: > 10, val: $num \n";
}
elsif($num < 10) {
 print "From if-elseif-else: < 10, val: $num \n";
}
else {
 print "From if-elseif-else: = 10, val: $num \n";
}

# Opposite of if, elseif and else can also be written with unless but it will become confusing
unless($num == 10) {
 print "!= 10\n";
}

# While loop, runs as long as condition is true
my $count = 1;
while ($count <= 5) {
 print "From while -> $count \n";
 $count++;
}

# Until loop, runs as long as condition is false
until ($count == 1) {
 print "From until -> $count \n";
 $count--;
}

# For loop, useful for iterating a list
my @days = qw(mon tue wed thu fri sat sun);
for my $i (1..5) {
 print "From for -> $i \n";
}
for (my $i = 1; $i <= 5; $i++) {
    print "From C style for -> $i \n";
}
for (@days) {
 print "From for, value in \$_ = $_ \n";
}
foreach my $day (@days) {
 print "From foreach = $day \n";
}

# do-while
do {
 print "From do-while $count \n";
 $count++;
} while($count <= 3);

# do-until
do {
 print "From do-until $count \n";
 $count--;
} until($count == 1);
Arrays:
my @months = ('jan', 'feb', 'mar');
print "Array printing = @months\n";

# Same Array can contain multiple types
my @array = (1, 2,'3',"4");
print "Printing 1st element of an array = $array[0] \n";

# qw is short of Quoted word which is used to declare string array
my @myArray = qw(My Name is Mukesh);

# One array variable can be assigned to another one
@myArray = @array;

# You can also put an array inside an array declaration, new array will be union of all elements
my @array2 = (@array, @myArray);

# Array of ints can be defined using ..
my @array3 = (1..20);

# Multiple assignment
(my $x1, my $x2, my $x3) = (1, 2, 3);
print "Multiple assignement x=$x1, y=$x2, z=$x3 \n";

# Swap
($x1, $x2) = ($x2, $x1);
print "Swapping values x=$x1, y=$x2 \n";

# Variable and list declaration in a single line
(my $y1, my @y2) = (1, 2, 3, 4);
print "Printing variable a=$y1, list b[0]=$y2[0]) \n";

($y1, @y2, my $y3) = (1, 2, 3, 4, 5, 6);
print "Printing variable a=$y1, list b[0]=$y2[0]), c=$y3 \n";

# Two ways to get size of an array
my $size1 = scalar @y2;
my $size2 = @y2;
print "scalar \@b = $size1, assignment of an array to a scalar = $size2 \n";

# $#varname is used to get index of last element of an array
my @z1 = (1..100);
print "Last index of an array of 100 elements = $#z1 \n";

my @z2 = ();
print "Last index of an empty array = $#z2 \n";

my $z3 = shift @z2;
print "shift removes first element of an array and assigns it to the variable s=$z3, $z2[0] \n";

unshift(@z1, "first");
print "unshift replaces first element of an array, now d[0] = $z1[0] \n";

# Similar to shift and unshift there is pop and push function which operates on last element
# Reverse is a function to reverse an array
@z1 = reverse(@z1);
print "Reversed array d[0] = $z1[0] \n";

my @testarray = qw(e T c d);
print "Printing an array @testarray, size $#testarray \n";

my @sorted = sort (@testarray);
print "Sorted array @sorted \n";

my @num = qw(1 2 3 22 11 0 23 5);
my @num = sort {$a <=> $b} @num;
print "To sort numerically you have to use {\$a <=> \$b}  @num \n";

# splice function is used to remove n number of elements from an array.
# It returns removed elements
splice (@num, 1, 3);
print "Applying splice which will remove 1st, 2nd and 3rd element from num array @num \n";
Hash:
# hash can be defined just like array, but interpertation becomes different
# in case of has each pair becomes key-value.
my %hash = qw(1 2 3 22 11 0 23 5);
my @values = values %hash;
print "@values \n";

my %country_map = ("India", "Delhi", "USA", "New York", "Japan", "Tokyo");

# Another way to define hash
%country_map = (
    India => "Delhi",
    USA => "New York",
 Japan => "Tokyo"
);
my $indiaCapital = $country_map{"India"};
print "$indiaCapital \n";

my @countries = keys %country_map;
my @capitals = values %country_map;
File Handling:
Save below content in a file 'file.pl', modify the code accordingly like change filename etc.. Run with command file.pl arg1 arg2 ... where arg1, arg2 are filenames.
#!/usr/bin/perl

use strict;
use warnings;

# STDIN is the standard input handle while <STDIN> is the content of the handle
# chop removes last character 
# chomp removes last character only if it is new line, this is special version of chop
print "Enter your name \n";
my $name = <STDIN>;
chomp $name;
chop($name);
print "Your name = $name \n";

# Opening a file, Open with any marker here 'IN' then $. and $_ contains line number and line
# content, $! returns error. It reads one line at a time in $_ variable
open IN,"temp.txt" or die "Error in opening $!";
while (<IN>) {
 print "$.| $_";
}
close IN;

# Writting in a file, > sign means you are opening this file for output
open OUT, ">out.txt" or die "Error in opening $!";
for my $i (1..20) {
 print OUT "$i :: Hello, The time is", scalar(localtime) ," \n";
}
close OUT;

# Appending to a file, use >> instead of > and do what you did in case of writting
open OUT, ">>out.txt" or die "Error in opening $!";
for my $i (1..20) {
 print OUT "$i :: Hello, The time is", scalar(localtime) ," \n";
}
close OUT;

# Printing a file, $_ is the default variable so if we don't give anything to print then $_
# value will be printed.
open AP, "out.txt" or die "Error in opening $!";
while (<AP>) {
 print;
}
close AP;

# @ARGV is a special array which will hold parameters passed with perl command
foreach (@ARGV) {
 print;
 print "$_ \n";
}

# STDIN, STDOUT, STDERR, ARGV these 4 are important constructs in perl
# @ARGV is used to store commandline arguments whereas <argv> will each file in turn which is
# again specified in commandline, if no file is specified then it starts reading from standard 
# input, shortcut for <argv> is <>
foreach(<>) {
 print "$. : $_";
}
In the next part I'll talk about subroutines and Object Oriented Programming in Perl.
Read More

Logging in java Part-2

In the Part-1 I discussed about different logging frameworks in java. In this part I'll discuss about setting up slf4j and logback in your project.

Maven dependencies:
slf4j-api: Contains interfaces for LoggerFactoryBinder, MDCAdaptor and MarkerFactoryBinder which will be implemented by any slf4j compatible logger service like logback. slf4j-api also contains implementation of some features which actual logging framework might not have like MDC.
logback-core: It contains classes and utilities with default and abstract level implementation which is used in logback-classic.
logback-classic: Implementation of slf4j-api, logback-core and logback-classic can be used without slf4j-api in a project just like log4j.
jcl-over-slf4j: Implementation of commons-logging to forward logging statements written with commons-logging into slf4j logging.
log4j-over-slf4j: Minimal implementation of log4j to forward logging statements written with log4j into slf4j logging.
jul-to-slf4j: Provides a SLF4J BridgeHandler which will redirect all JUL log records to the SLF4J API based logging.


   org.slf4j
   slf4j-api
   1.7.6
  

  ch.qos.logback
  logback-core
  1.1.1
 

  ch.qos.logback
  logback-classic
  1.1.1
 
 

   org.slf4j
   log4j-over-slf4j
   1.7.6
  

   org.slf4j
   jcl-over-slf4j
   1.7.6
  

   org.slf4j
   jul-to-slf4j
   1.7.6
  

   javax.mail
   mail
   1.4
  


In this blog I'll discuss about advanced options like MDC backed per customer logging in a web environment, per customer custom logging level control and email appender. logback.xml starts with configuration tag where you can define if automatic scanning of logback.xml is enabled you can also control scanning period. If debug="true" is specified then logback will also log its initialization steps, it is good practice to make it true always because it helps in detecting logback initialization problem quickly.

Per user log generation:

I am assuming that per user log generation is done in a web environment. To achieve this you must create an MDC entry containing user_email (or any unique identifier) for each request and remove it after completion of request. You must be keeping user email in session till user is logged in. Below is the definition of "PERUSER_LOGGING_APPENDER" which creates logging files like ../user_email/app.log.


    
      user_email
      unknown-user
    
    
      
  
   ${log.directory.name}/${user_email}/app.log
    
    
        ${log.directory.name}/${user_email}/app-%d{yyyy-MM-dd}.log
       
    
           
          %date{dd-MMM-yyyy HH:mm:ss.SSS} [%thread] %-5level %c %method - %msg%n %ex
       
  
    
  

SMTP Appender:
Logback provides SMTP appender which is used to send logs on email. This appender is configured with a Marker "SEND_EMAIL" also all logging events with logging level less than WARNING are discarded by this appender.
 
  
    
        
          WARN
        
     
     
     
            SEND_EMAIL
            ACCEPT
            DENY
        
        
            SEND_EMAIL
        
  
        
     
     
     true
     toaddress1@gmail.com
     toaddress2@gmail.com 
     fromaddress1@gmail.com
        ERROR : %X{host_name} %logger
        
        
          %date{dd-MMM-yyyy HH:mm:ss.SSS} %X{user_email} [%thread] %-5level %c %method - %n%msg%n%ex
        
        
       
      1
     
    
logger.error("SEND_EMAIL", "Exception in processing request.", e);

Marker class:
package com.changingtechblog.example;

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;

/**
 * Used to filter marked logging statement.
 * 
 *  <filter class="com.changingtechblog.example.MarkerFilter">
 *      <marker>MarkerName</marker>
 *      <onMatch>ACCEPT</onMatch>
 *      <onMismatch>DENY</onMismatch>
 *  </filter>
 *  <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
 *      <marker>MarkerName</marker>
 *  </evaluator>
 * 
* * @author Mukesh Kumar */ public class MarkerFilter extends AbstractMatcherFilter<ILoggingEvent> { private Marker markerToMatch; @Override public void start() { if (this.markerToMatch != null) { super.start(); } else { addError(String.format("The marker property must be set for [%s]", getName())); } } @Override public FilterReply decide(ILoggingEvent event) { Marker marker = event.getMarker(); if (!isStarted()) { return FilterReply.NEUTRAL; } if (marker == null) { return onMismatch; } if (markerToMatch.contains(marker)) { return onMatch; } return onMismatch; } public void setMarker(String markerStr) { if (markerStr != null) { markerToMatch = MarkerFactory.getMarker(markerStr); } } }

Per customer logging control:

  
     user_email 
     mukesh.kumar120in@gmail.com 
     DEBUG
     ACCEPT
  

MDCMatchingFilter:
package com.changingtechblog.example;

import org.slf4j.MDC;
import org.slf4j.Marker;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.turbo.MatchingFilter;
import ch.qos.logback.core.spi.FilterReply;


/**
 * Filter used to modify logger level for a particular mdc value at runtime.
 * It can be configured in logback.xml as:
 * 
 * <turboFilter class="com.changingtechblog.example.MDCMatchingFilter">
 *    <mdcKey>user_email</mdcKey> 
 *    <values>mukesh.kumar120in@gmail.com</values> 
 *    <OnMatch>ACCEPT</OnMatch>
 *      <logLevel>DEBUG</logLevel>
 * </turboFilter>
 * 
* * You can even specify multiple values of user_email as comma separated. * * @author Mukesh Kumar */ public class MDCMatchingFilter extends MatchingFilter { public static final String LOGGING_APPENDER_KEY = "user_email"; public static final String HOSTNAME_KEY = "host_name"; String mdcKey; String values; String logLevel; @Override public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { if (!isStarted()) { return FilterReply.NEUTRAL; } if (mdcKey == null || values == null) { return FilterReply.NEUTRAL; } String value = MDC.get(mdcKey); if(value == null) { return FilterReply.NEUTRAL; } if(values != null && !values.trim().equals("")) { String[] emails = values.trim().split("[,]"); for(String email : emails) { if (value.contains(email.trim().toLowerCase())) { if (level.isGreaterOrEqual(Level.valueOf(logLevel))) { return onMatch; } else { return FilterReply.DENY; } } } } return onMismatch; } public void setMdcKey(String mdcKey) { this.mdcKey = mdcKey; } public void setValues(String values) { this.values = values; } public void setLogLevel(String logLevel) { if(logLevel != null) { this.logLevel = logLevel.trim(); } else { this.logLevel = "DEBUG"; } } @Override public void start() { if (mdcKey != null && values != null) { String value = MDC.get(mdcKey); if(value != null) { super.start(); } } } }

Finally you will have to define root logger

  
  


Slf4j has support for all other popular logging frameworks. Most of the libraries are already using slf4j for logging but in case if your project is using multiple logging libraries and if you can move to slf4j based logging then you have to remove all those logging libraries(like log4j.jar, apache-commons.jar) and put slf4j based libraries which are listed at the start of this article. Below is an example illustrating use of multiple types of logging methods in a slf4j based setup.
package com.changingtechblog.example;

import org.apache.commons.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class LogbackLogger {

 private static final Logger logbackLogger = LoggerFactory
   .getLogger(LogbackLogger.class);
 private static final org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger
   .getLogger(LogbackLogger.class);
 private static final Log jclLogger = org.apache.commons.logging.LogFactory
   .getLog(LogbackLogger.class);
 private static final java.util.logging.Logger julLogger = java.util.logging.Logger
   .getLogger("com.changingtechblog.example.LogbackLogger");

 public static void main(String[] args) {
  logbackLogger.info("Logback logging");
  log4jLogger.info("Log4j logging");
  jclLogger.info("JCL logging");
  julLogger.info("JUL logging");
 }
}

Output:
2014-02-12 13:44:53,632 13:44:53.632 [main] INFO c.c.example.LogbackLogger - Logback logging
2014-02-12 13:44:53,633 13:44:53.633 [main] INFO c.c.example.LogbackLogger - Log4j logging
2014-02-12 13:44:53,633 13:44:53.633 [main] INFO c.c.example.LogbackLogger - JCL logging
12 Feb, 2014 1:44:53 PM com.changingtechblog.example.LogbackLogger main INFO: JUL logging
Read More

Free clean install Mac OS X Mountain Lion 10.8

This post will help you with installation guideline of Mac OS X Mountain Lion on Mac machine only not on pc. Before following the steps please make sure that your system configuration matches with minimum hardware requirement of Mountain Lion version. I am assuming that you have a Windows machine which will prepare installation media of fresh Mac OS X Mountain Lion but if you are upgrading from previous version then Windows is not mandatory requirement.

Step 1
Get an installation image
You can either download it from apple store which costs about $20 or go to any torrent hosting site like piratebay and search for "Mac OS X Mountain Lion" and download .iso or .img or .dmg file. It will take some time to finish downloading which depends on your network bandwidth because file size is around 4.3GB.
Step 2
Make a bootable drive
You can use a DVD or USB pendrive or external hard drive to create a bootable media containing Mac OS X Mountain Lion. Here I am writing steps for USB media but same is applicable for DVD also.  You can't use Lili USB Creator or UNetBootin to create bootable USB containing Mac OS X ML because mac won't boot from the filesystem used by these softwares so you must first format your pendrive in mac os compatible filesystem. To do this there is a software TransMac which comes with a 15 days trail period. Download TransMac from here. After installation of TransMac open it as Administrator, click on File tab and then select "Open Disk Image", now give the path of downloaded iso, img or dmg file. You can see the contents of image file on the right pane. In the left pane your USB drive will be visible, right click on it and select "Format Disk for Mac" as shown in the image.

When formatting completes then again right click on USB drive and then select "Restore with Disk Image", select the path of image file. It will show a message "Formatting will erase all data", select ok to continue. It will take about 20 minutes to finish creating bootable usb disk.

Step 3
Installation on Mac
Insert bootable usb device in you mac. Restart your mac and press alt/option key at the beginning. You can see all bootable media on the screen, select usb device. Next screen will show you four options to choose from. If you want fresh installation then select Disk Utilities and then erase whole disk and create partition then continue.Follow the installation process its quite easy. After installation completes then you can update your system to later version.


Read More

Logging in java Part-1

Logging is one of the most important part of an application development. A well logging enabled application not only keeps track of the application flow but it also helps in debugging. As application grows logging even becomes more important because it helps in finding a bug which seldom comes on production. There may be thousands of logging requests generated per second depending upon the application size in that case logging should not hamper application performance. Apart from performance there are other things like configuration, abstraction, encoders, appenders and filters which should be taken into consideration while choosing a logging framework. 
In java there are 5 commonly used logging frameworks:
  1. Java logging framework (JUL)
  2. Jakarta Commons logging (JCL)
  3. Simple logging facade for java (SLF4J)
  4. Log4j
  5. Logback
Log4j is most widely used logging framework in conjunction with JCL or SLF4j. In this article I'll start with basic comparasion between log4j and logback later on I'll go in detail about how to configure logback in your project. JCL and slf4j are abstract logging framework mostly used by library developers while other 3 libraries do actual logging. Earlier jcl was used by most of the libraries but since it has runtime class loading problems which often result in annoying exceptions so you will see library developers are upgrading to slf4j based logging which not only overcomes jcl class loading problem but it also provides other useful functionality like support for arguments in logging statement.  Slf4j can be plugged with most of the logging frameworks like jcl, log4j, logback and jul.

Log4j File Appender: Following code logs in a file test-log4j.log as well as console.

   
      
         
      
   
   
      
      
      
      
         
      
   
   
      
      
      
   

Logback File Appender: Following code logs in a file test-logback.log as well as console.

   
     
       %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
     
   
   
      /home/mukesh/logs/testing/test-logback.log
      
         %date %level [%thread] %logger{10} %msg%n
      
   
   
      
      
   


Logback vs Log4j File Appender Performance Graph

Above graph represents the performance of logback and log4j for file appender using single logging statement. Y-axis represents number of logging statements and X-axis represents number of threads. Both programs were run for same time for each thread set on the same machine. In this graph clearly logback has an advantage because it takes less time as compared to log4j in logging a statement.

Log4j JDBC Appender: Following code logs in a mysql table log4jTable as well as console.

   
      
         
      
   
   
      
      
      
      
      
   
   
      
      
      
   


Logback JDBC Appender: Following code logs in a mysql table logging_event as well as console.

   
      
         %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
      
   
   
      
         
            com.mysql.jdbc.Driver
            jdbc:mysql://localhost:3306/logback
            root
            
         
      
      
   
   
      
      
   


Logback vs Log4j JDBC Appender Performance Graph

Above graph represents the performance of logback and log4j for jdbc appender using single logging statement. Y-axis represents number of logging statements and X-axis represents number of threads. Both programs were run for same time for each thread set on the same machine. In this graph clearly performace of logback is miles ahead of log4j primarily because logback uses threadpooling and it has standard tables for logging, script is packaged with logback distribution. There is no out of box configuration for thread pool in log4j.

In the next part I'll discuss about how to configure slf4j and logback in a project. Stay tuned ...
Read More

Install subversion 1.7.x in ubuntu and mint

Ubuntu official software repository doesn't have subversion 1.7.x which is required by subclipse 1.8.x.
But you can download all relevant packages from debian repository and install it manually.
Packages required for 64-bit machine are listed below, for 32-bit machine replace amd64 with i386.

1. subversion_1.7.5-1_amd64.deb
2. libsvn1_1.7.5-1_amd64.deb
3. libsvn-java_1.7.5-1_amd64.deb
4. libaprutil1_1.4.1-3_amd64.deb
5. libserf1_1.1.0-2_amd64.deb

Download Link: http://packages.debian.org/ko/sid/subversion
You need to search package name in the search box and then download all packages listed above. Download link are at the end of page with files listed for different architecture machine for example in the below image mouse pointer is located at the file for 64-bit machine.


Read More

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