Wednesday, September 14, 2016

-startup

plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar

--launcher.library

plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444

--launcher.XXMaxPermSize

256M

-showlocation

--launcher.appendVmargs'

-vm

C:/Program Files/Java/jdk1.8.0_102/bin/javaw.exe

-Duser.name=RANGINY1

-product

org.eclipse.epp.package.jee.product

--launcher.defaultAction

openFile

-showsplash

org.eclipse.platform

--launcher.defaultAction

openFile

--launcher.appendVmargs

-vmargs

-Djava.net.preferIPv4Stack=true

-Declipse.p2.unsignedPolicy=allow

-Dcom.sun.management.jmxremote

-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4

-Xverify:none

-Dosgi.requiredJavaVersion=1.8

-XX:+UseG1GC

-XX:+UseStringDeduplication

-Dosgi.requiredJavaVersion=1.8

-Xms256m

-Xmx1g


Wednesday, September 7, 2016

Java Enum example

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public class EnumExample{
 public static void main(String args[]){
  // To Get the 'Day' by Abbreviation: 
  System.out.println("1 ="+Day.get("Su"));
  System.out.println("2 ="+Day.findByAbbr("Su"));
  // To get 'Day' name in String:
  System.out.println("3 ="+Day.valueOf("SUNDAY").toString());
  
  // To Get the Abbreviation by 'Day': 
  System.out.println("4 ="+Day.SUNDAY.getAbbreviation());
  System.out.println("5 ="+Day.valueOf("SUNDAY").getAbbreviation());  
 }
}

/**
 * Usage: 
 * 1. To Get the 'Day' by Abbreviation: Day.get("Su"))<br/>
 * 2. To Get the Abbreviation by 'Day': <br/>
 *    Day.SUNDAY.getAbbreviation();<br/>
 *        OR <br/>
 *    Day.valueOf("SUNDAY").getAbbreviation(); <br/>
 * 3. To get 'Day' name in String:<br/>
 *    Day.valueOf("SUNDAY").toString();
 */
 enum Day {
 //Enum types
 SUNDAY("Su"), MONDAY("Mo"), TUESDAY("Tu"), WEDNESDAY("We"), THURSDAY("Th"), FRIDAY("Fr"), SATURDAY("Sa");

 //internal state
 private final String abbreviation;

 // Reverse-lookup map for getting a day from an abbreviation
 private static final Map<String, Day> lookup_0 = new HashMap<String, Day>();
 
 
 
 // Populate the lookup table on loading time
 static {
  for (Day d : Day.values()) {
   lookup_0.put(d.getAbbreviation(), d);
  }
 }
 //Alternative way populating lookup table
 /*
 static {
  for (Day d : EnumSet.allOf(Day.class)) {
   lookup_0.put(d.getAbbreviation(), d);
  }
 }*/

 //Constructor
 private Day(final String abbreviation) {
  this.abbreviation = abbreviation;
 }

 public String getAbbreviation() {
  return abbreviation;
 }
 
 // This method can be used for reverse lookup purpose
 public static Day get(String abbreviation) {
  return (Day)lookup_0.get(abbreviation);
 }
 
 public static Day findByAbbr(String abbreviation){
     for(Day d : values()){
         if( d.abbreviation.equals(abbreviation)){
             return d;
         }
     }
     return null;
 }
}


Tuesday, May 31, 2016

Eclipse connectivity issue with Corporate Proxy

Overview 

Some applications we use need to access the web through the Corporate proxy and pull in content. In many cases what happens is the request fails as the application is unable to negotiate the connection using the NTLM protocol. Examples of this are the Marketplace in Eclipse Luna or installing packages with npm.
Cntlm is a tool that will work around this problem by proxying these requests locally and talking to the Corporate proxy to establish a connection. From the project website: "Cntlm is an NTLM / NTLMv2 authenticating HTTP/1.1 proxy. It caches auth'd connections for reuse, offers TCP/IP tunneling (port forwarding) thru parent proxy and much much more."

Setup Instructions

  1. Download and install cntlm from http://sourceforge.net/projects/cntlm/
  2. Edit C:\Program Files (x86)\Cntlm\cntlm.ini and make the following changes (make sure you are running your text editor as administrator​):​
    a. Add your Corporate username
    Username <corporate proxy server login>

    b. Comment out domain (we don’t need it)
    # Domain    corp-uk

    c. Change Proxy and Add additional NoProxy
    Proxy           <HTTPPROXYNAME>:<PORT>
    NoProxy         localhost, 127.0.0.*

    d. Get password hash from the command line
    > cd "C:\Program Files (x86)\Cntlm\"
    > cntlm -H -c cntlm.ini

    e. Paste the resulting 3 lines, which contain hashes of your password, back into your config.ini:
    PassLM          <HASH>
    PassNT          <HASH>
    PassNTLMv2      <HASH>    # Only for user <USERNAME>, domain '<HTTP PROXY NAME>'

    f. Comment out clear text password parameter
    # Password <fake password>

    g. Start CNTLM
    See instructions in README.txt (in the cntlm installation directory)

    h. Test CNTLM from the comand line
    > cntlm -M http://www.google.com

    After entering your Corporate password when prompted, you should see a response similar to the following (the HTTP 200 response indicating a success):

    Config profile  1/4... OK (HTTP code: 200)
    ----------------------------[ Profile  0 ]------
    Auth            NTLMv2
    PassNTLMv2      <your password hash>
    ------------------------------------------------
  3. Reboot your computer.  CNTLM will be installed and will run as a windows service and you won't have sto start it again manually unless of course you stop it manually.
After configuring and starting cntlm, applications should be able to access the web with no further action needed.

Changing CNTLM Password After CORPORATE Password Reset

  1. Get password hash from the command line
    > cd "C:\Program Files (x86)\Cntlm\"
    > cntlm -H -c cntlm.ini
  2. Copy the resulting 3 lines, which contain hashes of your passwordPassLM <HASH>
    PassNT <HASH>
    PassNTLMv2 <HASH> # Only for user <USERNAME>, domain '<HTTPPROXYHOST>'
  3. Open the cntlm.ini (configuration setting file) and replace (paste) the information from step two into your cntlm.ini file.
  4. Save, stop then start cntlm.  Information on how to do that can be found in the "Starting/Stopping CNTLM Manually" section below.

Starting/Stopping CNTLM Manually

  1. To start stop CNTLM manually open a command prompt as an Administrator
  2. To stop CNTLM type
    1. net stop cntlm
  3. To start CNTLM type:
    1. net start cntlm

Further info

Cntlm technical manual

How to Configure Eclipse Proxy Settings

Note: If installing from an external site hangs at “calculating requirements and dependencies” after following the instructions here, try unchecking the "Contact all update sites during install" box.
Beginning with Eclipse version 4.4 (Luna), special steps are needed in order for Eclipse to contact external sites (e.g. to install updates or plugins).
If when attempting to install plugins or open the Eclipse Marketplace, you receive an error stating "Proxy Authentication Required", this article is for you.

Background

The cause of the proxy error is a new set of HTTP client libraries that Eclipse uses beginning with v4.4. Removing those libraries, along with configuring Eclipse to talk to the proxy, will cause Eclipse to fall back on the JRE HTTP client libs. This should resolve the issue.

Part A: Configure Eclipse's Proxy Settings

First, you must configure Eclipse to play nice with the proxy by doing the following:
  1. In Eclipse go to Window>Preferences>General>Network Connections
  2. Choose Manual for the Active Provider
  3. For both HTTP and HTTPS, enter the following settings:
    • Host: <PROXY HOST>
    • Port: <PROXY PORT>
    • User: <PROXY USERID>
    • Password <PROXY USER PASSWORD>
    Note you will need to update this each time you change your password.
  4. Click OK to save your settings.

Part B: Remove Problematic Libraries

With Eclipse not running, go to Eclipse's plugins directory (e.g. C:\Program Files\Eclipse\plugins) and delete or rename the following three .jar files:

org.eclipse.ecf.provider.filetransfer.httpclient4.ssl_1.0.0.v20140528-1625.jar
org.eclipse.ecf.provider.filetransfer.httpclient4_1.0.500.v20140528-1625.jar
org.eclipse.ecf.provider.filetransfer.ssl_1.0.0.v20140528-1625.jar

After performing parts A and B above, Eclipse should be able to contact external update sites without any issues.    Notes
This information was compiled from this StackOverflow question and this bug report comment on the Eclipse bug tracker.

In addition to above 2 parts, see if https://wiki.eclipse.org/Disabling_Apache_Httpclient helps or
configure the following in eclipse.ini file.
-Djava.net.preferIPv4Stack=true
-Declipse.p2.unsignedPolicy=allow
-Dcom.sun.management.jmxremote
-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4


Thursday, May 12, 2016



Best way to create a Singleton Pattern.


The Singleton Design Pattern is one of the Creational (creation of instance in best possible way) patterns.

The usage of enum, a new feature from Java5, allows safe way to implement Singleton design pattern as Java ensures that any enum value is instantiated only once in memory (JVM).

This singleton instance is accessible from anywhere since Java Enum values are globally accessible.

The drawback is that the enum type is somewhat inflexible as it does not allow lazy
initialization.

package org.comp.core;
public enum MyEnumSingleton {
INSTANCE;

       private MyEnumSingleton(){}


  public static void method1(){

//Do something 
}

  public static List buildStateCodeList(){
              final List<String>  stateCodeList = new ArrayList<String>();
             stateCodeList.add("AR");
             stateCodeList.add("AZ");
             ....
             ....
             return stateCodeList ;
}
}

From Caller:
List<String> stateCode_USA_List = MyEnumSingleton.INSTANCE.buildStateCodeList();


The following is more appropriate in  Distributed environment.   

package org.comp.core;
import java.io.*;
public class MySerializedSingleton implements Serializable{
private static final long serialVersionUID = -12345678923456789123L;
// Private/default constructor
private MySerializedSingleton(){}
//Inner static class to create instance (A safer way)
private static class MySingletonHelper{
private static final MySerializedSingleton instance = new MySerializedSingleton();
}

//Return singleton instance
public static MySerializedSingleton getInstance(){
return MySingletonHelper.instance;
}

/**
* Implement the readResolve() method to avoid creating a new instance in 'Deserialization'            scenario.  
*/
protected Object readResolve() {
return getInstance();
}

}

Thursday, October 8, 2015

Testing - Glossary

Functional Testing:  (Iteration Testing) Testing the application against business requirements by testing a slice of functionality of the whole system ensuring that the software has all the required functionality that’s specified. 
System Testing:  Testing conducted on a complete, integrated system to evaluate the system’s compliance with its specified requirements, functional testing is also included in this phase.
Regression Testing: Software testing that seeks to uncover bugs in existing functional and non-functional areas after changes have been made to the system.
User Acceptance Testing: This is not System Testing, but rather ensures that the solution will work for the user. Testing is normally done by a subject-matter expert and is one of the final stages of a project often before a client or customer accepts the changes to the system.
Performance Testing: Testing performed to determine how the system performs in terms of responsiveness and stability under a particular workload. It can also serve to investigate, measure, validate or verify other quality attributes of the system, such as scalability, reliability and resource usage.
Beta Testing: Testing of a rerelease of a software product conducted by customers
Ad Hoc Testing: A testing phase where the tester tries to 'break' the system by randomly trying the system's functionality. Can include negative testing as well.
Testing a system or an Application on the fly, i.e just few tests here and there to ensure the system or an application does not crash out.
 

Thursday, August 7, 2014



Grails in Websphere - Not loading/working static resources in cluster env.

Problem:
It is observed that the Grails application was working fine in local (tomcat) developer box and not behaving the same when deployed into Websphere cluster.

Solution:
If you are using grails resources plugins then use the plugins in the following order.
        // Manually update the resoures plugin to resolove websphere look up errors
        runtime ":resources:1.2"
        runtime ":cached-resources:1.0"
        //runtime ":zipped-resources:1.0"
        compile ":cache-headers:1.1.5"


Friday, July 18, 2014

Proxy Settings for Grails application



If you happen to work on more than one Grails application then it makes more sense to configure the HTTP Proxy settings in one place than in BuildConfig.groovy of each Grails project.

The following steps are for Windows7 env.
1. Create 'ProxySettings.groovy' file in C:\Users\USERID\.grails directory.
2. Add the following entries to it.

client=['http.proxyHost':'PROXY URL', 'http.proxyPort':'8080', 
        'http.proxyUser':'DOMAIN\\USERID',         
        'http.proxyPassword':'PASSWORD',             
        'http.nonProxyHosts':'IF ANY' ] 

currentProxy='client'   

Reboot/Restarting of the machine is required to affect the changes.


Additional Settings to check-in/release Grails applications/plugins into your corporate/private SVN repository and Maven repositories.
1. Create 'ettings.groovy' file in C:\Users\USERID\.grails directory.
2. Add the following entries to it.

grails.project.repos."REPO_NAME_IN_NEXUS".url="FULL_URL_OF_REPO" 
grails.project.repos."REPO_NAME_IN_NEXUS".type = "maven" 
grails.project.repos.default="REPO_NAME_IN_NEXUS" 
grails.release.scm.enabled=false 

//Example:
//grails.project.repos."my-grails-plugins".url="http://nexus.mycomp.net:8081/nexus/content/repositories/my-grails-plugins"
//grails.project.repos."my-grails-plugins".type = "maven" 
//grails.project.repos.default="my-grails-plugins" 
//grails.release.scm.enabled=false
 

Friday, September 6, 2013


JOKES

------------------------------------------------------------------------------------------------------
Socialism: You have two cows, and you give one to your neighbor.
Communism:You have two cows,the government takes both and gives you the milk.
Fascism:You have two cows,the government takes both and sells you the milk.
Nazism:You have two cows,the government takes both and shoots you.
Bureaucrat-ism: You have two cows,the government takes both, shoots one, milks the other and throws the milk away.
Capitalism: You have two cows, you sell one and buy a bull to produce more animals
-------------------------------------------------------------------------------------------------------

Thursday, September 5, 2013



Accessing Grails components (Controllers and Services etc) from grails-app in classes /src/groovy

Requirement:
There is a need , sometimes, for groovy classses in /src/groovy/pkg1/ to access/work with Grails components (ex. services).  The service/controller/domain/views components are in /grails-app directory and can see/access each other. The classes (.groovy or .java) in /src/groovy or /src/java cannot see them.

Solution:

//Import the required classes
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes as GA
class GetServicesHelper {
   def getMyService(){
        //Get ServletContext 
        def servletContext = SCH.servletContext
        //Get GrailsApplicationContext from GrailsApplicationAttributes saved in ServletContext
        def grailsApplicationContext = servletContext.getAttribute(GA.APPLICATION_CONTEXT)
        //Get the service that is injected into Grails Application Context
        def myService = grailsApplicationContext.myService
        return myService
    }
}

Monday, August 26, 2013

Perception



Once there was this guy who was in love with a girl. She wasn't the most beautiful and gorgeous but for him, she was everything.
He used to dream about her, about spending the rest of his life with her.
His friends told him, "Why do you dream so much about here, when you don't even know if she loves you or not? First tell her your
feelings, and get to know if she likes you or not". He felt that was the right way. The girl knew from the beginning that this guy loved her.
One day when he proposed, she rejected him.

His friends thought he would take to alcohol, drugs etc. and ruin his life. To their surprise, he was not depressed. When they asked
him how was it that he was not sad, he replied, "Why should I feed bad? I lost one who never loved me and she lost the one who really loved
and cared.
"When life give you a 100 reason to cry, show life that you have 1000 reason to smile."
"Life is wonderful if you know how to live."

Grails Application configuration in Websphere container.

For the first time install of Groovy/Grails app on any server, make sure following properties are set for the web container on all application servers/nodes/clusters.

§         In "Application servers > server name > Process Definition > Java Virtual Machine" add to the "Generic JVM arguments"
       -Xverify:none

§         In "Application servers > server name > Process Definition > Java Virtual Machine > Custom Properties", add a custom property
   name: com.ibm.ws.classloader.getInputStream.enableIOException
   value: true
  description: Invoke IO Exception override processing

§         In "Application servers > server name > Web container > Custom Properties", add a custom property
     name: com.ibm.ws.webcontainer.invokeFiltersCompatibility
     value: true

     description: Invoke Filter compatibility patch


Websphere WAS 6.1/7 often logs the following exceptions into SystemOut.log files.


[Servlet Error]-[Filter [DeclaredResourcesPluginFilter]: filter is unavailable.]: java.lang.NullPointerException
    at com.ibm.ws.webcontainer.srt.SRTServletResponse.setContentType(SRTServletResponse.java:1141)


Solution:
1. Log into Admin console of Websphere Apllication Server.
2. Navigate to

WAS Admin -> Environments -> Virtual Hosts -> default_host -> MIME Types

Add/Modify following as the MIME TYPE 

MIME Type
Extensions
image/gif
GIF gif
image/jpeg
JPE JPEG JPG jpe jpeg jpg
image/tiff
TIFF TIF tiff tif
image/png
PNG png
image/psd
PSD psd
image/icon
ICON ICO icon ico


Note: The Extensions can be separated by whitespace


Do it in all Virtual Hosts.

See the below image for reference.



Thursday, April 25, 2013

Interesting story on Finance



Here's a very interesting anecdote that describes how an 'asset bubble' builds up and what are its consequences. Read it even if it confuses you a bit...things will be clear as you reach the end.... 
ANCEDOTE - Once there was a little island country. The land of this country was the tiny island itself. The total money in circulation was 2 dollar as there were only two pieces of 1 dollar coins circulating around.

1) There were 3 citizens living on this island country. A owned the land. B and C each owned 1 dollar.
2) B decided to purchase the land from A for 1 dollar. So, A and C now each own 1 dollar while B owned a piece of land that is worth 1 dollar.The net asset of the country = 3 dollar.
3) C thought that since there is only one piece of land in the country and land is non produce-able asset, its value must definitely go up. So, he borrowed 1 dollar from A and together with his own 1 dollar, he bought the land from B for 2 dollar. A has a loan to C of 1 dollar, so his net asset is 1 dollar. B sold his land and got 2 dollar, so his net asset is 2 dollar. C owned the piece of land worth 2 dollar but with his 1 dollar debt to A, his net asset is 1 dollar.The net asset of the country = 4 dollar.
4) A saw that the land he once owned has risen in value. He regretted selling it. Luckily, he has a 1 dollar loan to C. He then borrowed 2 dollar from B and acquired the land back from C for 3 dollar. The payment is by 2 dollar cash (which he borrowed) and cancellation of the 1 dollar loan to C. As a result, A now owned a piece of land that is worth 3 dollar. But since he owed B 2 dollar, his net asset is 1 dollar. B loaned 2 dollar to A. So his net asset is 2 dollar. C now has the 2 coins. His net asset is also 2 dollar.The net asset of the country = 5 dollar. A bubble is building up.
5) B saw that the value of land kept rising. He also wanted to own the land. So he bought the land from A for 4 dollar. The payment is by borrowing 2 dollar from C and cancellation of his 2 dollar loan to A. As a result, A has got his debt cleared and he got the 2 coins. His net asset is 2 dollar. B owned a piece of land that is worth 4 dollar but since he has a debt of 2 dollar with C, his net Asset is 2 dollar. C loaned 2 dollar to B, so his net asset is 2 dollar.
The net asset of the country = 6 dollar. Even though, the country has only one piece of land and 2 Dollar in circulation.
6) Everybody has made money and everybody felt happy and prosperous.
7) One day an evil wind blowed. An evil thought came to C's mind. 'Hey, what if the land price stop going up, how could B repay my loan. There is only 2 dollar in circulation, I think after all the land that B owns is worth at most 1 dollar only.' A also thought the same.
8) Nobody wanted to buy land anymore. In the end, A owns the 2 dollar coins; his net asset is 2 dollar. B owed C 2 dollar and the land he owned which he thought worth 4 dollar is now 1 dollar. His net asset become -1 dollar. C has a loan of 2 dollar to B. But it is a bad debt. Although his net asset is still 2 dollar, his Heart is palpitating.The net asset of the country = 3 dollar again.Who has stolen the 3 dollar from the country?
Of course, before the bubble burst B thought his land worth 4 dollar. Actually, right before the collapse, the net asset of the country was 6 dollar in paper. his net asset is still 2 dollar, his heart is palpitating.The net asset of the country = 3 dollar again.
9) B had no choice but to declare bankruptcy. C as to relinquish his 2 dollar bad debt to B but in return he acquired the land which is worth 1 dollar now. A owns the 2 coins, his net asset is 2 dollar. B is bankrupt, his net asset is 0 dollar. ( B lost everything ) C got no choice but end up with a land worth only 1 dollar (C lost one dollar)

The net asset of the country = 3 dollar.


 There is however a redistribution of wealth. A is the winner, B is the loser, C is lucky that he is spared. A few points worth noting –
1) When a bubble is building up, the debt of individual in a country to one another is also building up.
2) This story of the island is a close system whereby there is no other country and hence no foreign debt. The worth of the asset can only be calculated using the island's own currency. Hence, there is no net loss.
3) An over-damped system is assumed when the bubble burst, meaning the land's value did not go down to below 1 dollar.
4) When the bubble burst, the fellow with cash is the winner. The fellows having the land or extending loan to others are the loser. The asset could shrink or in worst case, they go bankrupt.
5) If there is another citizen D either holding a dollar or another piece of land but refrain to take part in the game. At the end of the day, he will neither win nor lose. But he will see the value of his money or land go up and down like a see saw.
6) When the bubble was in the growing phase, everybody made money.
7) If you are smart and know that you are living in a growing bubble, it is worthwhile to borrow money (like A ) and take part in the game. But you must know when you should change everything back to cash.
8) Instead of land, the above applies to stocks as well.
9) The actual worth of land or stocks depends largely on psychology.

Tuesday, March 19, 2013

Difference between OLTP and OLAP systems

Online Transaction Processing Systems Online Analytical Processing Systems
Operational Data and original source of data. The Data (integrated) comes from various OLTP systems
Application specific, Detailed and most currrent/recent data. Historical data collected from various systems to support Business decision, planning and reporting
Performance is predicted as per application architecture and design. Performance is not predicted or mandated.
Most recent data with several Insert/Update operations. Read only data.
Highly Normalized for performance. Minimal normalization with restructuring of data.
Not (least) used for reporting and analysis. High analysis for business decisions.
Many transactions. low (none) transactions.
Low to moderate space is required. Very large space is required to support volumes of data.
Backup and recovery is critical to organization. Backup is not very critical. Reloading the OLTP data is a recovery practice.