Hobione's Weblog

Living & Breathing in Web 2.0 Era

RSA premaster secret error

I wrote how to use SSL connection string using JDBC driver in my previous blog. I deployed the code on the Unix server from Windows 7 pc and I got RSA premaster secret error.


Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available

I figured it out after banging my head on the wall for couple of days. I had to explicitly use sunjce_provider.jar file name on the class path.


$JAVA_HOME/bin/java -Xms64m -Xmx256m -Djava.ext.dirs=.:$SURVEY_LIB -cp .:$JAVA_HOME/jre/lib/ext/sunjce_provider.jar:$CLASSPATH:$SURVEY_BIN/surveys.jar com.hobi.survey.SurveyMainClass getAllSurveys

Advertisements

August 29, 2014 Posted by | SSL | Leave a comment

SSL connection from Java to MSSQL Database Server using JDBC driver

First of all, need to get the self-signed certificate from database administrator and install/import to the following path.
C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts

How to install ssl certificate?
Step 1: Get the certificate from certificate owner, it is usually .cer file (SQLcert.cer)
Step 2: Make a dir under c drive (c:\certificate)
Step 3: Copy the cacerts from C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts to c:\certificate
Step4: Copy SQLcert.cer to c:\certificate
Step5: Open up a command prompt and change directory to c:\certificate
Step6: Execute this command
keytool -import -keystore cacerts -file SQLcert.cer

How to import SSL certificate

Step8: Copy cacerts file back to the original path –> *C:\Program Files\Java\jdk1.7.0_17\jre\lib\security

How to install jdbc4 driver to local maven repository?

Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
To add the jar file in pom.xml since Microsoft don’t make this available via any maven repository.

Download the jar from the Microsoft website, and then manually install it into local maven repository using following command.
mvn install:install-file -Dfile=sqljdbc4.jar –DgroupId=com.microsoft.sqlserver –DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

How to install jdbc4 driver to local maven repository

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>

How to setup jdbc ssl connection string for MSSQL server 2012?
jdbc:sqlserver://arc-xxx-xxx.xxx.xxx.com\\CSDTEST;databaseName=surveySys;EncryptionMethod=ssl

Pay attentions on slashes (forward slash vs backward slash: before server name, it has forward slash but after the server name there are two back slashes). I also had to use full server name instead of an ip address.

I was able to connect to the SQL server after few days of hard work.

 

How to list all certificates in cacerts file?
c:\Program Files\Java\jdk1.7.0_17\jre\lib\security>keytool -list -v -keystore cacerts

August 18, 2014 Posted by | SSL | , | Leave a comment

Oracle 11g on Windows 7 professional (32 bits)

I have downloaded two zip files for Oracle 11g release 2 from Oracle site as follows.

Unzipped ’em and ran setup.exe from \win32_11gr2_database_1of2\database\setup.exe and got zillion of file not found errors as follows.

–> \application\em.ear, \bin\db2gc\, \config\system-application.xml\

–> Template General_Purpose.dbc does not exist

–> Oracle Database Configuration Assistant failed

Anyway, after fiddling with some times, I found out that the two zip files I have downloaded, needed to combine together to solve file not found errors. So I copied win32_11gR2_database_2of2\database to win32_11gR2_database_1of2\database to merge two database directories and here is the login page for Oracle 11g r2 after a successful install.


A video that I found to show step by step but it does not say to combine two zip files if you download the the software from web.

January 20, 2011 Posted by | Databases: Oracle,MySql | 2 Comments

HSSFWorkbook object write it to Excel, send it as an attachment


public static void loadDailyDataToExcel(ResultSet rs, Statement st, Connection connection, Properties properties) {

 try {
 HSSFWorkbook workBook = new HSSFWorkbook();
 HSSFSheet sheet = workBook.createSheet("Excel Sheet");
 HSSFRow rowhead = sheet.createRow((short) 0);
 rowhead.createCell((short) 0).setCellValue("RESPONSE DATE");
 rowhead.createCell((short) 1).setCellValue("SERVICE ID");
 rowhead.createCell((short) 2).setCellValue("Q");
 rowhead.createCell((short) 3).setCellValue("T");
 rowhead.createCell((short) 4).setCellValue("V");
 rowhead.createCell((short) 5).setCellValue("CUSTOMER");
 rowhead.createCell((short) 6).setCellValue("OVERALL");
 rowhead.createCell((short) 7).setCellValue("COMMENTS");
 rowhead.createCell((short) 8).setCellValue("CONTACT");
 rowhead.createCell((short) 9).setCellValue("CONTACT INFO");

 int index = 1;
 Format formatter = new SimpleDateFormat("MM/dd/yy");

 while (rs.next()) {

 HSSFRow row = sheet.createRow((short) index);
 row.createCell((short) 0).setCellValue(formatter.format(rs.getDate(1)));
 row.createCell((short) 1).setCellValue(rs.getString(2));
 row.createCell((short) 2).setCellValue(rs.getString(3));
 row.createCell((short) 3).setCellValue(rs.getString(4));
 row.createCell((short) 4).setCellValue(rs.getString(5));
 row.createCell((short) 5).setCellValue(rs.getString(6));
 row.createCell((short) 6).setCellValue(rs.getString(7));
 String comments = rs.getString(8);
 if (comments != null) {
 row.createCell((short) 7).setCellValue(comments);
 }
 String contact = rs.getString(9);
 if (contact != null) {
 row.createCell((short) 8).setCellValue(contact);
 }
 String contactInfo = rs.getString(10);
 if (contactInfo != null) {
 row.createCell((short) 9).setCellValue(contactInfo);
 }
 index++;
 }//while

 if (index > 1) {
 String fileName = "SurveyResponsesDailyReport-TestServices.xls";
 String to = properties.getProperty("survey.emailToDailyReport3aTest"); //from property file
 String subject = "Customer Survey 'Please Contact' Daily Summary - Test Services";
 String body = "Daily Survey Report for Test Services in Microsoft excel format.\n\n";
 emailNotification = new EmailNotification();
 emailNotification.sendEmailWithAttachment(to, subject, body, fileName, workBook, index);

 try {
 String hobiOneDirectoryPath = properties.getProperty("survey.hobiOneDirectoryPath"); // c:\\temp\\hobi\\
 FileOutputStream fileOut = new FileOutputStream(hobiOneDirectoryPath+"SurveyResponsesDailyReport-TestServices.xls");
 workBook.write(fileOut);
 fileOut.close();
 System.out.println("SurveyResponsesDailyReport-TestServices.xls was copied to "+ hobiOneDirectoryPath);

 } catch (FileNotFoundException fnfe) {
 emailNotification = new EmailNotification();
 emailNotification.sendEmail(emailToSystemAdmin, "Survey error from : ExportSurveyResponsesTestServicesToExcel.jar", "Environment: " + serverName + " : " + fnfe);

 System.out.println("Oops, FileNotFoundException caught. " + fnfe);
 }
 }
 } catch (Exception e) {
 emailNotification = new EmailNotification();
 emailNotification.sendEmail(emailToSystemAdmin, "Survey error from : ExportSurveyResponsesTestServicesToExcel.jar", "Print Stack Trace " + e);
 e.printStackTrace();
 } finally {
 try {
 if (rs != null) {
 rs.close();
 }
 if (st != null) {
 st.close();
 }
 if (connection != null) {
 connection.close();
 }
 } catch (SQLException sx) {
 sx.getMessage();
 }
 }
 }//close method

 

public void sendEmailWithAttachment(String recipients, String subject, String body,String attachmentFileName, HSSFWorkbook hssWorkBook, int totalRows) {

 properties = new Properties();
 properties.put("mail.smtp.host", host);
 properties.put("mail.smtp.port", port);

 if (recipients.equals("") || subject.equals("") || body.equals("") || attachmentFileName.equals("") || hssWorkBook.getBytes().length < 0 ) {
 System.out.println("Usage: sendEmailAttachemt() method parameter might be missing, you may check for the /test/local/surveyToExcel-test.properties for any recent changes");
 System.exit(1);
 }
 Session session = Session.getInstance(properties, null);
 try {
 // create a message
 MimeMessage msg = new MimeMessage(session);
 DataSource ds = null;
 msg.setFrom(new InternetAddress(from));

 ArrayList recipientsArray = new ArrayList();
 StringTokenizer stringTokenizer = new StringTokenizer(recipients, ",");

 while (stringTokenizer.hasMoreTokens()) {
 recipientsArray.add(stringTokenizer.nextToken());
 }
 int sizeTo = recipientsArray.size();
 InternetAddress[] addressTo = new InternetAddress[sizeTo];
 for (int i = 0; i < sizeTo; i++) {
 addressTo[i] = new InternetAddress(recipientsArray.get(i).toString());
 }
 msg.setRecipients(Message.RecipientType.TO, addressTo);

 // Parse a comma-separated list of email addresses. Be strict.
//            msg.setRecipients(Message.RecipientType.CC,
//                    InternetAddress.parse(<a href="mailto:test@aa.test">test@aa.test</a>, true));

 msg.setSubject(subject);

 // create and fill the first message part
 MimeBodyPart mimeBodyPart1 = new MimeBodyPart();
 mimeBodyPart1.setText(body);

 // create the second message part
 MimeBodyPart mimeBodyPart2 = new MimeBodyPart();

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 try{
 hssWorkBook.write(baos);
 byte[] bytes = baos.toByteArray();
 ds = new ByteArrayDataSource(bytes, "application/excel");
 }catch (IOException ioe ){
 this.sendEmail("hobione@hobione.com", "Survey excel file send error", "ByteArrayOutputStream: " + ioe);
 ioe.printStackTrace();
 }
 DataHandler dh = new DataHandler(ds);
 mimeBodyPart2.setHeader("Content-Disposition", "attachment;filename="+attachmentFileName+".xls");
 mimeBodyPart2.setDataHandler(dh);
 mimeBodyPart2.setFileName(attachmentFileName);
 // create the Multipart and add its parts to it
 Multipart multiPart = new MimeMultipart();
 multiPart.addBodyPart(mimeBodyPart1);
 multiPart.addBodyPart(mimeBodyPart2);

 // add the Multipart to the message
 msg.setContent(multiPart);

 // set the Date: header
 msg.setSentDate(new Date());

 // send the message
 javax.mail.Transport.send(msg);
 System.out.println("Report emailed successfully to: " + recipients +" Total rows count:" + totalRows);

 }catch (MessagingException mex) {
 mex.printStackTrace();
 Exception ex = null;
 if ((ex = mex.getNextException()) != null) {
 this.sendEmail("hobione@hobion.com", "Survey excel file send error", "Print Stack Trace: " + ex);
 ex.printStackTrace();
 }
 }
 }

January 12, 2011 Posted by | Java | 3 Comments

2010 in blog review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Wow.

Crunchy numbers

Featured image

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 93,000 times in 2010. If it were an exhibit at The Louvre Museum, it would take 4 days for that many people to see it.

 

In 2010, there were 4 new posts, growing the total archive of this blog to 69 posts. There were 17 pictures uploaded, taking up a total of 738kb. That’s about a picture per month.

The busiest day of the year was May 6th with 411 views. The most popular post that day was jQuery-ThickBox (Launch thickbox onload instead of onclick).

Where did they come from?

The top referring sites in 2010 were sitepoint.com, coderanch.com, google.co.in, google.com, and draptik.wordpress.com.

Some visitors came searching, mostly for tb_show, com.sun:tools:jar:1.4.2, thickbox onload, java.lang.classnotfoundexception: org.springframework.web.context.contextloaderlistener, and facesmessage.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

jQuery-ThickBox (Launch thickbox onload instead of onclick) December 2007
40 comments

2

RichFaces Tabs: switch dynamically April 2008
22 comments

3

Missing com.sun:tools:jar:1.4.2 March 2009
4 comments

4

dataTable and radio button in JSF May 2009
11 comments

5

JSF: f:selectItem vs. javax.faces.model.SelectItem May 2009
1 comment

January 7, 2011 Posted by | 1 | Leave a comment

Maven Jetty-plugin and IntelliJ IDEA

Scenario: You have a maven project and you want to tie with IntelliJ 9 to make it part of IDE built-in commands instead of using command line interface.

Pre-requisite: Need to read Maven Jetty-Plugin User Guide.

Solution: Here is a skeleton project hierarchy:
BenchStock
You also should have a pom.xml file directly under the project.

Now, open up the IntelliJ. Go to File –> Open Project and choose the pom.xml file to bring the project into Intellij and here how it looks. Notice, Idea has created few extraneous files like .impl, .ipr and .iws.
Project in Intellij

How to configure Run command?
In the IDEA, go to Run –> Edit Configurations
You see the “Run/Debug Configurations” window. Under Parameters tab choose the directory and set the goal command:
Run/Debug Configurations

Under Runner tab, set VM Parameters to these: (You may not need to sett all these)

-Xms512m
-Xmx512m
-Dcron.properties="c:\MySDP\cron.properties"
-Dcrowd.properties="C:\Documents
and
Settings\hobee
haq\My
Documents\buildLocal\itrsbenchstock\src\etc\resources\crowd.properties"
-Dlogin.jsp="C:\Documents
and
Settings\hobee
haq\My
Documents\buildLocal\itrsbenchstock\src\webapp\pages\login.jsp"

Runner Tab

Application is ready to run by click the play button.
Play Button
Here is the proof:
Jetty Run

How to configure Build?
Build

It should shows the Build option to the IDEA drop down. Choose the Build option and click the play button.
Build with Play Button

How to configure clean?
Clean Project from target directory

How to configure scm bootstrap?
SCM BootStrap

Here is the final configured list looks like:
Configured List

Hopefully, this post will help me to remember and configure all my future apps with maven jetty-plugin in IntelliJ Idea.

September 22, 2010 Posted by | Maven | Leave a comment

Exadel Tiggr Mockups

I have just started using Exadel Tiggr mockups. It is an online mockup tool, very easy to use and the closest design I can deliver it to the client before develop the product. Components like, text box, table, tabs, panels are very real looking. We are using JSF Richfaces implementations so; it does make sense to use Tiggr during mockups building.
Another cool feature that I love the most; it is a pure online-based tool, which eliminates all download and configurations issues. Tiggr creates shares and collaborate mockups with any number of designers, developers, project manager, scrum master ….. you name it.

Benchstock mockup screenshot

August 25, 2010 Posted by | Mockup | 2 Comments

Spring 3.0 and ROO

Had a great training on Spring 3.0 from Craig Walls.  Here are highlighted topics.

– Wiring
– Testing
– AOP
– Transactions
– Spring MVC
– RESTful Spring
– Messaging
– RabbitMQ
– Security and
– Spring ROO 1.0

It was good to see ROO (Real Object Oriented) in action, just few commands, created the whole application, entity, controller, wiring and packaged up the application which was ready to deploy. Great tutorial from Ben Alex to build wedding RSVP app using ROO. One simple command created these following basic app hierarchy.

roo> project –topLevelPackage com.hobione.roo

ROO screenshot

May 7, 2010 Posted by | Spring Framework | Leave a comment

JSF @ UCO

I was honored to give a presentation at the University of Central Oklahoma Computer Science department on Java Server Faces. I was invited by Dr. Sung who teaches Java Server Programming and also he is my java guru.  I took my first java class with him 10 years ago (man I am getting old …) while I was finishing up my degree.   Anyway, it was a great experience.  I was little nervous standing front of a class specially front of Dr. Sung and preach about a java framework.  It went really well, I believe.  Dr. Sung and along with students seemed to enjoy the presentations and I was happy to deliver my materials as well.

April 16, 2010 Posted by | Java Server Faces | 1 Comment

Balsamiq Mockups

What a cool way to mock up web app.  Here is my first design that I am about to work on.

Balsamiq Mockups

To, Balsamiq team: Keep up the good work, and probably need to give a catchy name.  Balsamiq is too hard to remember.  Really like the integration approach with Atlassian product like Jira and Confluence.  Thumbs UP!

November 3, 2009 Posted by | Mockup | 2 Comments