Wednesday, December 9, 2009

Steps to add Versign certificate in Tomcat server

  • Create a Key Pair
keytool -alias <alias_name> -genkey -keyalg "RSA" -keystore <keystore_filename>
  • Generate the CSR file from the Key pair created
keytool -certreq -alias <alias_name> -file <csr filename> -keystore <keystore_filename>
  • Submit the CSR file to Versign to obtain certificate
  • This step is only for Trail SSL certificate
keytool -import -trustcacerts -alias EV_root -keystore <keystore_filename> -file primary_EV_inter.cer
keytool -import -trustcacerts -alias EV_intermediate -keystore <keystore_filename> -file secondary_EV_inter.cer
  • Store the Certificate obtained from Versign as cert.cer
keytool -import -trustcacerts -alias <alias_name> -keystore <keystore_filename> -file cert.cer

Configuration in Tomcat

Open server.xml in conf folder
Add following node in service node
<connector
className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8443" minProcessors="5" maxProcessors="75"
enableLookups="false" acceptCount="10" SSLEnabled="true"
connectionTimeout="60000" debug="0" scheme="https" secure="true" Protocol="TLS" clientAuth="false"
keyAlias="<alias_name>" keystore="<keystore_filename>"
keystorePass="<password>"/>

NOTE:
Change the port value for desired port
UI to add certificate is available at http://portecle.sourceforge.net/


Wednesday, July 23, 2008

Open Letter to Prime Minister

Dear PM,

Congratulation on winning trust vote. As common man I require few clarifications from you.

What is guarantee that we wouldn’t face another situation like Dabhol Power Plant?

What is arrangement to dispose nuclear waste? Even in US nuclear waste are stored not disposed? I don’t think in India we have foolproof mechanism to store nuclear waste(Bride to guard will help me get into storage facility)?

Why government does not on developing Renewable energy (Government can divert fund given as power subsidies)?

Why does government not considering reservation based on economic than caste?

What is the timeline to remove caste is based reservation from India?

Thanks,

Prakash

Friday, May 9, 2008

Custom Error message in XML - XSD validations for Java.

When you validate your XML with XSD you will get error message with some code and
Text. Based on the error code we can customize the error message.
Always In error message values(node name and ndoe value) will come within
single qoutes. By using string tokenier we can decode the node name and value ,
but order of apperance in error message should be known for writing custom message.

In properties file value is assinged against each errorcode.

Poperties file:

cvc-complex-type.2.4.a=Value of ''{1}'' is empty (or) expected before ''{0}''.

Java
Validator
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

/**
* Validator.java
* Class extends org.xml.sax.helpers.DefaultHandler
* Author : Prakash Krishnan
* Date : 09-May-08
**/
public class Validator extends DefaultHandler {
public boolean validationError = false;
public SAXParseException saxParseException = null;
/**
Receive notification of a recoverable parser error.
**/
public void error(SAXParseException exception) throws SAXException {
validationError = true;
saxParseException = exception;
}
/**
* Report a fatal XML parsing error.
**/
public void fatalError(SAXParseException exception) throws SAXException {
validationError = true;
saxParseException = exception;
}
/**
* Receive notification of a parser warning.
**/
public void warning(SAXParseException exception) throws SAXException {
}
}

XMLXSDValidator
import java.io.StringReader;
import java.io.FileInputStream;
import java.text.MessageFormat;
import java.util.StringTokenizer;
import java.util.PropertyResourceBundle;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

/**
* XMLXSDValidator.java
* Utility to validate an xml string input against an xsd file.
* Returns a String with the validation results
**/

/* Author : Prakash Krishnan
Date : 09-May-08
*/

public class XMLXSDValidator {

/**
* Retuns a report of the results of validating an xml String against an xsd with
a property file
* The property file is used to customize the error message.
* Note:The XSD and properties file name paramerter require full path
**/
synchronized static String ValidateXML(String XSDUrl, String xmlContents,
String propertyFileName) {
{
//convert String to an InputSource; required for the validator.
source = new InputSource(new StringReader(xmlContents));

System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
XSDUrl);
DocumentBuilder builder = factory.newDocumentBuilder();
//instantiate com.exel.www.hubware.Validator. This class extends Default
// handler
Validator handler = new Validator();
builder.setErrorHandler(handler);
builder.parse(source);
if (handler.validationError == true)
return handleError(handler.saxParseException,propertyFileName);
else
return null; // return nothing if there is no exception;
} catch (Exception e) {
return e.toString(); //if any exception is caught, then return null.
//The application will take care of reporting an error for this case.
}
}

/**
* @param handler
* @throws Exception
*/
private static String handleError(SAXParseException saxParseException,
String propertFileName) throws Exception {
//get the error message
String errorMessage = saxParseException.getMessage();
//split error message using :, error messages will be of the format
//errorcode:errormessage
int spiltpoint = errorMessage.indexOf(':');
//get the error code
String errorcode = errorMessage.substring(0, spiltpoint);
//get the error message
errorMessage = errorMessage.substring(spiltpoint + 1, errorMessage.length());

//open the property file errormsg.properties
try
{
PropertyResourceBundle properties = new PropertyResourceBundle
(new FileInputStream(propertFileName ));
// check if the errocode has a match in the property file
String propStr = (String) properties.handleGetObject(errorcode);

if (propStr == null || propStr.length() == 0) {
return errorMessage; //if no match return the error message
}

StringTokenizer stringTokenizer = new StringTokenizer(errorMessage, "\'");
//two quotes make a string. So,
// the number of elements will be the number of tokens.
//+1 is done in case the number of quotes reported are in odd number.
//This will avoid exceptions.
String[] values = new String[stringTokenizer.countTokens() / 2 + 1];
int i = 0;
//Extract data within the quotes into the array
while (stringTokenizer.hasMoreElements()) {
stringTokenizer.nextElement();
if (stringTokenizer.hasMoreElements()) {
values[i++] = (String) stringTokenizer.nextElement();
}
}
return MessageFormat.format(propStr, values); //replace the patterns {0}, {1} ,
// etc. with the values array.
} catch (Exception e) {
// if the property file cannot be loaded or in case of any exception in the
//property extraction just return the errorMessage
return errorMessage;
}
}


}


Output:

Praser error message:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'XXXX'. One of '{YYYY}'
is expected.
After running below program you will get:
Value of '{YYYY}' is empty (or) expected before 'XXXX'.

Saturday, May 3, 2008

SSH over Ant, Java

For File transferring files in SSH you require following jar "jsch-0.1.37.jar"

ANT Script

<target name="copy" description="Copy file via SSH" >
<scp file="sourcefile"
todir="userid@$hostname:destdirectory"
trust="true"
password="passowrd" />
</target>

Make sure Trust is set to true.

Java Program
Following are the java program.

import org.apache.commons.configuration.PropertiesConfiguration;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;

public class SshFileTransfer {

private static class UserDetails implements UserInfo {
/*
Inner Class. Userinfo has to implemented for getting password Information and seeing console message.
*/
private String password;

public String getPassphrase() {
return null;
}

public String getPassword() {
return password;
}

public boolean promptPassphrase(String arg0) {
return true;
}

public boolean promptPassword(String arg0) {
return true;
}

public boolean promptYesNo(String arg0) {
return true;
}

public void setPassword(String password) {
this.password = password;

}

public void showMessage(String arg0) {
//Show the Console message
System.out.println(arg0);
}

}

ChannelSftp channel;

public void connect(String server, String destFilename, String src) throws Exception {
//Connection details are Stored in Properties files.
PropertiesConfiguration properties = new PropertiesConfiguration("conf/sftp.properties");
String hostname = properties.getString("server.hostname");
String userid = properties.getString("server.user");
String password = properties.getString("server.password");
int port = Integer.parseInt(properties.getString("server.port"));
if (hostname == null || hostname.trim().length() == 0 || userid == null
|| userid.trim().length() == 0 || password == null || password.trim().length() == 0) {
throw new Exception("Server details is empty/null");
}
// System.out.println("User -->" + userid);
// System.out.println("hostname -->" + hostname);
// System.out.println("password -->" + password);
// System.out.println("port -->" + port);

JSch shell = new JSch();
Session session = shell.getSession(userid, hostname, port);
UserDetails ui = new UserDetails();
ui.setPassword(password);
session.setUserInfo(ui);
session.connect();
channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
if (isConnected()) {
channel.put(src, destFilename);
//Disconnect after file tranfer.
channel.disconnect();
}
}

public boolean isConnected() {
return (channel != null && channel.isConnected());
}

}

Sunday, April 27, 2008

Long Live politicians.........

Recent Supreme Court judgment is shocking that caste can be factor for reservation. I don't how did supreme gave this judgment but one thing we should be happy was they ask govt exclude creamy layer from reservation. On seeing current trend i don't think creamy layer will be excluded or Definition of creamy will be changed(they will increase income limit to 10 LPA (current is 2.5 LPA)).

I remember one story butterfly is struggling hard to come out from egg. On seeing this a boy helped butterfly breaking its egg but after coming out of egg butterfly tries to fly but it was not able fly and dies. Reason was while struggling to come out egg it gives full power and by that way wings get strength. But on helping butterfly wings don't have strength eventually butterfly dies.

Similarly just by reservation they cannot bring equality. Instead it will widen the gap. People with real talent will become entrepreneur one day and other will work under them. Who know tomorrow politicians will bring reservation in starting business also and finally they will increase the reservation to 100% ask forward community to vacate country .

Long live India. Long Live politicians.

Thursday, January 17, 2008

Life at Chennai....

Finally settled in chennai. For last five years i was visitor(guest) to my home and I was treated rayolly but now i am no more a guest i have to do household activities i can't say no to it. I booked TVS Flame bike but i don't know when it will delivered to me(Waiting for it).
Everyday morning i have to take my pet dog(Caesar) for walking and then Breakfast finally to office at 9:30 a.m. Thank god there is no fixed timing here(I have to be in for 8 Hours 30minutes at minimum including lunch). Everyday Traveling in MTC bus for office and taking lunch from home after span of 10 years.
Even though its too early comment about my office but i can say So far So Good I like the HR process here everything is well organized compare to my previous organization. On work part of it no comment only yesterday work has assigned to me.
Back to home at 9:00 p.m.

Friday, December 28, 2007

Taare Zameen Par.....

As part of farewell My team took me to movie "Taare Zameen Par".
It is a nice movie which emphasis that everyone has their own talent. One problem is that how to identify it.?
While watching the movie it remind me of my school days. Most of the time i will be in defaulters list, Outstanding student(i.e always stand outside class), lots of spelling mistake but situation changes for after my 10 class.
I will recommend all teachers to watch this movie so that they will find Root cause analysis for student who is lacking behind instead of scolding. and punishing them. Society shouldnot consisder exam marks only way to judge child performance for some child it easy to remember what they read and reproduce it, for some child they will understand but can't able to reproduce in words. Our education system doesn't gives any importance to sports, painting, arts. Exams are conducted only for Languages , Science, Maths History, etc., If we are giving importance to marks then mean of everything should be taken.

Retrospective of My life in Bangalore(Siemens).....

Finally day has arrived. Today will be my last in Siemens,tomorrow i am vacating Bangalore and moving to Chennai. I enjoyed very much in Siemens simultaneously i learned a lot both professionally and personally .
Following are my retrospective in Siemens

What went well
  • Learned Java, JSP etc..,
  • Cleared SCJP Exam.
  • Received excellence award from SISL.
  • Worked has a Team player
  • Had my own responsibilities (Integration Coordinator) - Performed it to my satisfaction.
  • Tasted different variety of food(Pizza, Burger, North Indian, Pasta.... )
  • Kept my promise and expectation most of the time.
What went bad
  • Assumed many things and acted upon my assumption.
  • Believed in everyone(Sometimes it is good, Sometimes it is bad).
  • Fall sick due to chicken pox.
  • Spend the money lavishly.
  • Bad Communication.
  • Did not take care of my health.
Happiest Moment is Siemens:
  • My project Days between April 2006 - June2006
Unforgettable Moments
  • 13-October-2006.

Tuesday, December 11, 2007

Tomorrows Generation.....

Yesterday I and My roommate Johnny had arguments regarding "Whether media has a role in shaping behavior of the child?". Johnny arguments are that parent should filter what child should see. I accept it but in current trends how can parents know to what a child is exposed? In current scenario media performs a destructive role than a constructive role in society. Media just covering Junk politician interview and hatred speech among them, Cine star Dress and love affairs, Cricketers hair styles than Scientists Interview , Philosopher advices and scientific discovery. Now it is only the business from them. Recently in a magazine i read article about ill-effect of Junk Food but next page of that article there is advisement for one of the Junk food which they mention. In a news channel there was breaking news that "Bomb blast in railways station" but later they say it is just a cracker. Dhoni haircut is front-page news of Leading newspaper. In Current family system especially metro it is difficult to watch children all the times whereas previously we had elder(Grandpa & Grandmother) to watch child activities now in nuclear family it is very difficulties to watch child activities all the times. There one problem with parents also they don't want their children to suffer has they were in their childhood so they provide everything whatever child ask(Gaming Console, Toys, foods, Dress) they didn't teach their children how much struggle they made to get that money. Therefore now the question is who is responsible for tomorrow generation?

17


Days to go

Tuesday, December 4, 2007

Everything is confirmed......

Finally my release date from Siemens and Joining Date to Cambridge Solution(CS) has been confirmed. I think all the problem has been resolved. My last date in Siemens is 28-Dec then i will be traveling to Chennai 29-Dec-2007 and join CS on 31-Dec-2007(Last Day of 2007 is my first day at new Company).

Switching to new company is toughest part of my life till now.Anyway all the problem got cleared. This is the gamble in my life leaving huge organisation like Siemens and joining CS just for working in Chennai but decision has to make i just followed my inner instinct I will definitely win this gamble like previous(Such as skipping interview of Infy, TCS, CTS,Wipro in campus,Applying only to REC and PSG for MCA ignoring Anna University). Before joining CS I have to be masters in struts and i started learning struts.

Thanks to god for helping me to come out of trouble.

23

Days to go