Thursday, October 30, 2014

Top Ten Reasons for learning Java Programming Language

Java is the best programming languages created ever as it has last 20 years by gaining popularity every passing day. Although there were occasions when Java development slowed down, but with path breaking changes in form of Enum, Autoboxing and Generics in Java 5, Google's choice of language for Android apps development and performance improvement with Java 6, kept Java as top programming language. Also In terms of Job opportunities and popularity Java outscore every one with lots of Jobs opportunity available. You can work on developing core Java based server side application, can even go for Android based mobile application development and J2EE web and enterprise applications.

Here are top 10 reason for Learning Java Programming Language

1) Java is Easy to learn

Java has fluent English like syntax which makes it easy to read Java program and learn quickly. Once you are familiar with initial hurdles with installing JDK and setting up PATH and understand How Classpath works, it's easy to write program in Java.

2) Java is an Object Oriented Programming Language

Java is an Object Oriented Programming language. Developing OOPS application is easier, and it also helps to keep system modular, flexible and extensible. You can use all key concepts like AbstractionEncapsulationPolymorphism and Inheritance. Java also promotes use of SOLID and Object oriented design principles in form of open source projects like spring, which make sure your object dependency is well managed by using dependency Injection principle.

3) Java has Rich API

Java provides API for networking, I/O, utilities, xml parsing, database connection, and almost everything. Whatever left is covered by open source libraries like Apache Commons, Google Guava and others.

4) Powerful development tools e.g. Eclipse, Netbeans

Eclipse and Netbeans has played huge role to make Java one of the best programming language. Coding in IDE is a treat, especially if you have coded in DOS Editor or Notepad. They not only help in code completion but also provide powerful debugging capability, which is essential for development and testing. Integrated Development Environment made Java development much easier, faster and fluent. Apart from IDE, Java platform also has several other tools like Maven and ANT for building Java applications, JConsole, decompilers, Visual VM for monitoring Heap usage etc.

5) Good collection of Open Source libraries

Open source libraries ensures that Java should be used everywhere. Apache, Google, and other organization has contributed lot of great libraries, which makes Java development easy, faster and cost effective. There are framework like Spring, Struts, Maven, which ensures that Java development follows best practices of software craftsmanship, promotes use of design patterns and assisted Java developers to get there job done.

Tuesday, October 7, 2014

Java : File Encryption and Decryption using Blowfish

The Java security APIs span a wide range of areas, including cryptography, public key infrastructure, secure communication, authentication, and access control. Java security technology provides the developer with a comprehensive security framework for writing applications, and also provides the user or administrator with a set of tools to securely manage applications.
Source : http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html

javax.crypto.Cipher
This class provides the functionality of a cryptographic cipher for encryption and decryption. It forms the core of the Java Cryptographic Extension (JCE) framework.
Cipher API : http://docs.oracle.com/javase/6/docs/api/javax/crypto/Cipher.html

Cipher: initialized with keys, these used for encrypting/decrypting data. There are various types of algorithms: symmetric bulk encryption (e.g. AES, DES, DESede, Blowfish, IDEA)
http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html

Blowfish  
Blowfish has a 64-bit block size and a variable key length from 1 bit up to 448 bits
Blowfish Wiki : http://en.wikipedia.org/wiki/Blowfish_%28cipher%29

Here are the general steps to encrypt/decrypt a file in Java -

  • Create a Key from a given byte array for a given algorithm.
  • Get an instance of Cipher class for a given algorithm transformation.
  • Initialize the Cipher with an appropriate mode (encrypt or decrypt) and the given Key.
  • Invoke doFinal(input_bytes) method of the Cipher class to perform encryption or decryption on the input_bytes, which returns an encrypted or decrypted byte array.
  • Read an input file to a byte array and write the encrypted/decrypted byte array to an output file accordingly.


Please see the below java code

Wednesday, September 24, 2014

Javascript code for 2048 number puzzle

Other day I was playing this game on my android mobile and I was so amazed with it that I thought why not try to write a JavaScript code for this game. So here I am with it.

new game

Score :

HOW TO PLAY: Use your arrow keys to move the tiles.

Please see the complete source code -


Output -

Sunday, August 31, 2014

Five Common Questions from JavaScript Beginners

What is JavaScript?


JavaScript is an easy-to-use version of programming language (a constructed language that communicates instructions to a computer).  JavaScript is a scripting language (this means it is a programming language that supports scripts, which can interpret and automate the execution of tasks). Developed by Brendan Eich, while working for Netscape Communications Corporation, this program code was designed to appeal to nonprofessional programmers.  JavaScript runs inside an Internet browser. JavaScript is not a stand-alone programming language.  JavaScript is designed to embed information  in a web browser.  JavaScript includes the following features: dynamic typing and has first-class functions.  

Is Java the same as JavaScript?

Though both Java and JavaScript are both programming languages they are also immensely different.  Java is a very complex programming language while JavaScript is an easy-to-use version that is great for those beginners learning about program languages.  JavaScript and Java have the same expression syntax, naming conventions, and basic control-flow constructs.  JavaScript was previously named LiveScript; the name change has caused much confusion between Java and JavaScript.  Java is a programming language that can be used as a ‘stand-alone’ whereas JavaScript must rely on the environment it is operating in.


How Does JavaScript Work?

JavaScript works by placing code within a Web page.  When a browser loads the page, the built in interpreter reads the JavaScript code it finds within the page and runs it.


What is JavaScript Used For?

JavaScript is mostly used to allow ‘client-side’ scripts to interact with the user.  It is also used to control a Web browser, alter content that is displayed in a document, game development, as well as desktop and mobile applications.  Real life applications where this can be used (outside of web pages) include PDF documents, site-specific browsers, and desktop widgets.


What are the Various Data types used in JavaScript?

Number: Numbers can be written with or without decimals and may use scientific (exponential) notation if they are large enough. Does not allow the use of non-numbers such as NaN.

String: Strings are written with quotes.  Either double or single. 
Boolean: Can only have two values: true or false.
Array: Arrays use square brackets ‘[]’ while separating elements with comas.
Object: Objects are written with curly brackets ‘{}’. Comas separate each pair while the colon ‘:’ separates the name from its value.
Null: An empty value.  Variables can be emptied by setting the value to null.
Undefined: The value of a variable with no value.

Right brain, meet left brain. We're the whole brain. Objective in Salt Lake City, Utah is a web development and design firm with both creative and technological expertise. Learn more about Objective. .

Tuesday, July 29, 2014

JAXB marshalling and unmarshalling of Hashtable

It is not possible to Marshall or Unmarshall a Hashtable directly however you can achieve it using a Holder class (wrapper class). With the help of Holder class you can get the default XML format as shown below -

Default XML format -
<mapHolder>
    <htmlColorCode>
        <entry>
            <key>blue</key>
            <value>0000FF</value>
        </entry>
        <entry>
            <key>green</key>
            <value>00FF00</value>
        </entry>
        <entry>
            <key>red</key>
            <value>FF0000</value>
        </entry>
    </htmlColorCode>
</mapHolder>

However if you need to customize the XML format like the one shown below you may need to use XmlAdapter.

<colorMap>
    <colors>
        <item code="0000FF" color="blue"/>
        <item code="00FF00" color="green"/>
        <item code="FF0000" color="red"/>
    </colors>
</colorMap>

Method 1 - Using Wrapper class

Output -
--Marshalling--
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mapHolder>
    <htmlColorCode>
        <entry>
            <key>blue</key>
            <value>0000FF</value>
        </entry>
        <entry>
            <key>green</key>
            <value>00FF00</value>
        </entry>
        <entry>
            <key>red</key>
            <value>FF0000</value>
        </entry>
    </htmlColorCode>
</mapHolder>

--Unmarshalling--
{blue=0000FF, green=00FF00, red=FF0000}


Java - JAX-WS Jar files for SOAP web services

If you are writing a SOAP based webservice you may need to add below JAR files in your applications classpath

Error: java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
Add: jaxws-rt.jar

Error: java.lang.NoClassDefFoundError: com/sun/istack/localization/Localizable
Add: jaxb-core.jar

Error: java.lang.NoClassDefFoundError: com/sun/xml/stream/buffer/XMLStreamBuffer
Add: streambuffer.jar

Error: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/JAXBRIContext
Add: jaxb-impl.jar

Error: java.lang.NoClassDefFoundError: com/sun/xml/ws/policy/PolicyException
Add: policy.jar

Error: java.lang.NoClassDefFoundError: org/jvnet/staxex/XMLStreamReaderEx
Add: stax-ex.jar

Error: java.lang.NoClassDefFoundError: org/glassfish/gmbal/ManagedObjectManager
Add: gmbal-api-only.jar

Error: java.lang.NoClassDefFoundError: org/glassfish/external/amx/AMXGlassfish
Add: management-api.jar

Error: java.lang.NoClassDefFoundError: org/glassfish/ha/store/api/BackingStoreException
Add: ha-api.jar

You can download latest version of JAR file (E.g. jaxws-ri-2.2.8.zip ) from https://jax-ws.java.net/2.2.8/. For more information please see the link https://jax-ws.java.net/.

Java - JAXB marshalling and unmarshalling of ArrayList

Marshalling and unmarshalling of ArrayList using JAXB is rather simple however you cannot directly marshall ArrayList. You will need a holder class (wrapper class). It will hold the arraylist that you want to marshall or unmarshall.

Please see the self explanatory java code below -

Output -

--Marshalling--
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<List>
    <Value>one</Value>
    <Value>two</Value>
    <Value>three</Value>
</List>

--Unmarshalling--

[one, two, three]

Wednesday, July 23, 2014

Integration of DWR using DWRSpringServlet

DWR is a Easy Ajax for Java. To know more click here.

In this article we will see sample codes for integration of DWR with DWRSpringServlet

Step 1 - Create a web project in eclipse.

Step 2 - Add below Spring libraries

  • Spring Core libraries
  • Spring Web libraries
  • Spring AOP libraries
Step 3 - Add dwr.jar
Download appropriate version of dwr.jar and add it in your application classpath. For example DWR 3 requires Spring version 2.5 or greater.

Step 4 - Create dependent files

web.xml
The DwrSpringServlet can be used if you are not using Spring MVC. This servlet gains access to the Spring context configured in your web.xml. You can create your own context file, in our case it is dwrcontext.xml.


dwrcontext.xml


DWRService.java


index.jsp


Step 5 - Deploy the project in tomcat (or any other web server) and check the output


Integration of DWR using Spring MVC

DWR is a Easy Ajax for Java. To know more click here.

In this article we will see sample codes for integration of DWR with spring MVC

Step 1 - Create a web project in eclipse.

Step 2 - Add below Spring libraries

  • Spring Core libraries
  • Spring Web libraries
  • Spring AOP libraries

Step 3 - Add dwr.jar
Download appropriate version of dwr.jar and add it in your application classpath. For example DWR 3 requires Spring version 2.5 or greater.

Step 4 - Create dependent files

web.xml
Create spring DispatcherServlet and map URL pattern as shown below

javaxp-servlet.xml
If you are using Spring MVC you must declare dwr controller and url mapping i.e. SimpleUrlHandlerMapping as shown below

DWRService.java

index.jsp

Step 5 - Deploy the project in tomcat (or any other web server) and check the output


Thursday, June 19, 2014

Java - Authenticate users in Active directory and using LDAP

First lets me try to explain you in brief what is Active directory and LDAP

Active Directory is a database based system that provides authentication, directory, policy, and other services in a Windows environment

LDAP (Lightweight Directory Access Protocol) is an application protocol for querying and modifying items in directory service providers like Active Directory, which supports a form of LDAP.

In short, Active Directory is a directory services database and LDAP is one of the protocols you can use to talk to it.

1. Authenticate users in Active Directory

Directly you can run this code, no need to add any jar file.



Friday, June 6, 2014

Java - To Load a property file

Property files are used to store static information in a key-value pair. Things that you do not want to hard code in your Java code, which tend to change in future goes into properties files. Also as it is a static information you do not want to load the property file for each and every request as it may hamper performance. You may need it to be loaded only once at the begining of the loading of application.

You can load properties file using below methods. You can provide absolute path as well as relative path however mostly relative path is preferred.

prop.load(AppProperties.class.getClassLoader().getResourceAsStream("app.properties"));
OR
prop.load(new FileInputStream(new File("C:/temp/app.properties")));

Please see the self explanatory java code below - 

Monday, June 2, 2014

LINUX - Shell script to detect file change

Below is the simple shell script which can be used to detect the file change in a particular directory. It can detect file modified, file touched, new file created, file deleted / moved, files mode change (chmod) / files owner change (chown). It runs continuously after a sleep of specified interval and compare the list of files against the list of files prior to sleep.

Please see the self explanatory shell script below.

Saturday, May 24, 2014

New Features of Java 7

Java 7 contains many new features, enhancements and bug fixes to improve efficiency to develop and run Java programs.

Here is a brief summary of the enhancements included with the Java 7 release:

  • Improved performance, stability and security.
  • Enhancements in the Java Plug-in for Rich Internet Applications development and deployment.
  • Java Programming language enhancements that enable developers with ease of writing and optimizing the Java code.
  • Enhancements in the Java Virtual machine to support Non-Java languages.

In this article, we will explore some of those capabilities through code samples.

1. Binary literals

You can use the binary number system (0s and 1s) to express integral types byte, short, int, and long. To specify a binary value, prefix the value with a 0b or 0B.


--------------------- Output ---------------------
a = -88
b = 112
c = 73
d = 1467

2. Underscore literals

To improve readability of numeric literals in the code, you can use underscores between digits to separate a group of digits. You can use as many underscores as you need.


--------------------- Output ---------------------
a = -86
b = 4554
c = 123456789
d = 111222333
e = 11.227799


Monday, April 14, 2014

Java program to create doc/docx file

Apache POI can be used to create a doc/docx file. To know more click here.

You can download latest version of jar files(i.e. poi-bin-3.10-FINAL-20140208.zip) form below link.
http://poi.apache.org/download.html

Add below mentioned Jar files in your classpath -

  • poi-3.10-FINAL-20140208.jar
  • poi-ooxml-3.10-FINAL-20140208.jar
  • poi-ooxml-schemas-3.10-FINAL-20140208.jar
  • poi-scratchpad-3.10-FINAL-20140208.jar
  • xmlbeans-2.3.0.jar
  • dom4j-1.6.1.jar

Please see the self explanatory java code below

Java program to read doc/docx file

Apache POI can be used to read doc/docx file. To know more click here.

You can download latest version of jar files(i.e. poi-bin-3.10-FINAL-20140208.zip) form below link.
http://poi.apache.org/download.html

Add below mentioned Jar files in your classpath -
  • poi-3.10-FINAL-20140208.jar
  • poi-ooxml-3.10-FINAL-20140208.jar
  • poi-ooxml-schemas-3.10-FINAL-20140208.jar
  • poi-scratchpad-3.10-FINAL-20140208.jar
  • xmlbeans-2.3.0.jar
  • dom4j-1.6.1.jar
Please see the self explanatory java code below


Monday, March 17, 2014

Shell script - function to split a string based on a delimiter

#!/bin/ksh

#function to split a string based on a delimiter
function split {

        string=$1
        delimiter=$2

echo "split string '"$string"' with delimiter '"$delimiter"'"
        for word in $(echo $string | tr "$delimiter" "\n")
        do
                echo $word
        done
}

#call the split function with arguments string and delimiter
split "transient;private;protected;public;synchronized;native" ";"

split "float|short|char|double" "|"

UNIX/LINUX - How to encrypt/decrypt a text file

crypt command can be used to encrypt/decrypt a particular text file in UNIX/LINUX. It is a simple encryption algorithm which works on a secret-key basis. It encrypts or decrypts a stream of data from standard input, and writes the result to standard output. Encryption and decryption is a symmetric process.

Encryption
This will create an encrypted file enTextFile.txt  from a text file textFile.txt. You can use either of the commands both does one and the same task.

crypt ENCRYPTION_KEY < textFile.txt > enTextFile.txt

OR

cat textFile.txt | crypt > enTextFile.txt

Decryption
This will decrypt an encrypted file enTextFile.txt and store the output in textFile.txt

crypt ENCRYPTION_KEY < enTextFile.txt (to show data on console)
crypt ENCRYPTION_KEY < enTextFile.txt > textFile.txt

OR

cat enTextFile.txt | crypt > textFile.txt

Thursday, March 13, 2014

Linux - Copy/paste block of codes from Windows editor to Vi editor

Below is the command used to Copy/paste a block of code(s) from Windows editor to Vi editor. Basically to replace complete text from a particular file.

First copy the block of code(s) from windows editor then go to Vi editor and use the following command sequentially as given below

<ESC>
d
Shift+g
i
Shift+Insert
<ESC>

Above command says delete (d) the codes form specific line number (0 in this case) upto end of the file i.e. last line (note - capital G, hence Shift+g). Then go to insert mode (i) and paste the copied lines.

Linux - Block of comments in shell script

There is no block comment on shell script however there are few options that you can try out -

Method 1

#!/bin/bash
echo "This is a statement"
: << 'COMMENTS'
echo "The code that you want be commented out goes here"
echo "This echo statement will not be called"
COMMENTS
echo "This statement is outside the comment block"

At the beginning of the block you wish to comment out put -
: << 'COMMENTS'

The '' around the COMMENTS delimiter is important, otherwise things inside the block will be parsed and executed. I have used 'COMMENTS' as it should be a string of characters which is not used in you code, modify it in your code if needed.

And at the end of the block put -
COMMENTS

Method 2

#!/bin/bash
echo "This is a statement"
if [ 1 -eq 0 ]; then
echo "The code that you want be commented out goes here"
echo "This echo statement will not be called"
fi
echo "This statement is outside the comment block"

Added a false condition in the IF block so that it won't get executed.

Method 3

Using vi editor you can easily comment/uncomment from line n to m

Comment

<ESC>
:10,100s/^/#/

Above command says from line 10 to 100 substitute line start (^) with a # sign

Uncomment

<ESC>
:10,100s/^#//

Above command says from line 10 to 100 substitute line start (^) followed by # with noting //

Saturday, February 22, 2014

Java : Encode/Decode Base64

We will be using Apache Commons codec to Encode and Decode Base64 data.

Apache Commons Codec (TM) software provides implementations of common encoders and decoders such as Base64, Hex, Phonetic and URLs. To know more, click here.

To run below example you will need to add commons-codec.jar in your classpath. Download commons-codec-1.4.jar.

Please see the self explantory java code below.

Friday, February 21, 2014

Linux : Base64 Encode & Decode with OpenSSL

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that is designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.

In Linux you can achieve Base64 Encoding and Decoding using pre-installed OpenSSL package.

Encode

Below command will encode any text contents within the quotes and display the encoded contents on a new line.

echo 'text content' | openssl base64

You can also encode multiple lines using below command

echo 'text content' | openssl base64 && echo 'another text content' | openssl base64

Decode

Similarly you can decode using '-d' flag as shown below

echo 'dGV4dCBjb250ZW50Cg==' | openssl base64 -d


Using the OpenSSL package, you can also encode or decode a specific file, as shown below:

encode file
openssl base64 -in 'file.txt' -out 'encodedFile.txt'

decode file
openssl base64 -d -in 'encodedFile.txt' -out 'file.txt'

Friday, February 14, 2014

Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError: no db2jcct2 in java.library.path: ERRORCODE=-4472, SQLSTATE=null

com.ibm.db2.jcc.a.SqlException: [jcc][10389][12245][4.3.111] Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError: no db2jcct2 in java.library.path:  ERRORCODE=-4472, SQLSTATE=null
at com.ibm.db2.jcc.a.dd.a(dd.java:660)
at com.ibm.db2.jcc.a.dd.a(dd.java:60)
at com.ibm.db2.jcc.a.dd.a(dd.java:94)
at com.ibm.db2.jcc.t2.a.a(a.java:37)
at com.ibm.db2.jcc.t2.T2Configuration.(T2Configuration.java:94)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:188)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:524)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:588)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:617)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:625)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:657)
at com.hewitt.hro.ssb.dao.jdbc.JdbcBuildTypeDao.getBuildType(JdbcBuildTypeDao.java:100)
at com.hewitt.hro.ssb.dao.jdbc.JdbcBuildTypeDao.getBuildTypeWithArguments(JdbcBuildTypeDao.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:299)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy4.getBuildTypeWithArguments(Unknown Source)
at com.hewitt.hro.ssb.admin.LinkedBuildTypeLocator.init(LinkedBuildTypeLocator.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1147)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:271)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1047)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:843)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.directwebremoting.spring.SpringContainer.getBean(SpringContainer.java:105)
at org.directwebremoting.impl.ContainerMap.init(ContainerMap.java:53)
at org.directwebremoting.impl.ContainerMap.entrySet(ContainerMap.java:78)
at org.directwebremoting.spring.DwrController.afterPropertiesSet(DwrController.java:198)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:683)
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:248)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:125)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:103)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:304)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:311)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:258)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:229)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:115)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1189)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4915)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5242)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5237)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

If you get the above error try adding DB2 bin folder in the library path as shown in the below figure

Example - C:\Program Files (x86)\IBM\SQLLIB_01\BIN 

MyEclipse Servers -< (server) -> Configure Server Connector -> (Preferences pop up) -> MyEclipse -> Servers -> Tomcat -> Tomcat 7.x -> Paths -> Add DIR


Add the BIN directory and Click Apply/OK


nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'

SEVERE: StandardWrapper.Throwable
Invocation of init method failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'
Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:329)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:405)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:413)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:107)
at com.hewitt.hro.dcd.modb.dao.jdbc.JdbcUserDao.preloadCache(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

To get rid of above error you may need to add db2jcc4.jar or db2jcc.jar  in your applications classpath. To download Jar files : Click here.

Tuesday, February 11, 2014

Handling Suspicious Email Messages

There has been significant increase in the circulation of spam and malicious emails in the recent past. In this article we will discuss how to handel suspicious email messages. It is very important for you to identify the spam and take steps to safeguard yourself against potential threats.


How to identify spam without opening the message?

A malicious email can infect your system immediately. Downloading a file from a suspicious email is enough to infect your system, including a PDF. Do not open suspicious or unsolicited emails.

It is recommended :


  • Do not open suspicious emails
  • Try to identify a message as spam by looking at the 'From' field and the 'Subject' line. If the sender and the domain (@company.com) does not relate to the subject, the message is probably spam
  • Never trust emails that are trying to sell you something or unknown clients. Ask yourself, does the sender identify you by your name? If the answer is no, the message is spam. 


You can identify spam emails by looking at the 'From' field, if :


  • You get any email with your name in as the sender (which you may not have sent) 
  • The 'From' field is blank or generic (example: friend, try this, etc.)
  • The mail has strange name or all numbers – 9222594_1970@tst-inc.com 
  • Has scrambled, random-appearing addresses – X12YT853@yahoo.com 
  • Is from someone you do not recognize or from a domains like yahoo.com, gmail.com, msn.com, hotmail.com. Attackers use these domains to send spam 
  • If the message is from another country, especially, if you do not work regularly with them (Example - m5wangzhi@wahaha.com.cn – here CN means the domain is China) 


You can identify spam emails by looking at the 'Subject' field, if :


  • The subject is unrelated to your work profile or domain (example: Do you want to get rich?) 
  • There are strange characters in the subject (example: best m0rtgage qu0te!s") 
  • There are obvious spelling errors (Example: buy yourself Bacheelor/MasteerMBA/Doctoraate dip1omas)
  • The subject is outrageous or doesn't make any sense (Example: BREAKING NEWS: Nuts! Jackson Backs Neutering Stray Politicians)
  • The subject appears to be an order of confirmation for something you did not order (Example: Your Tracking # 77328515")
  • Your email address is in the subject line, this is usually done to gain your interest to open the email
  • The subject line indicates an important notification ("Install update for Microsoft Outlook"), and the message appears to be from the vendor (for example, Microsoft). Remember, Patches can be installed by clicking on Start -> Control Panel -> Windows Update


Friday, February 7, 2014

Exception in thread "main" javax.xml.ws.WebServiceException

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:8080/SOAPWebservice/HelloWorldPort?wsdl. It failed with: 
Connection refused: connect.
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:162)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:144)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:263)
at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:226)
at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:174)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104)
at javax.xml.ws.Service.(Service.java:56)
at com.hewitt.ws.HelloWorldImplService.(HelloWorldImplService.java:55)
at com.hewitt.ws.TestClient.main(TestClient.java:7)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at java.net.URL.openStream(URL.java:1009)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:805)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:262)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:129)
... 7 more

If you get above error, please check if the wsdl url is working fine. Just hit the URL in a browser and see if you get response. If not check with your service provider.

Example -
http://localhost:8080/SOAPWebservice/HelloWorldPort?wsdl