Friday, May 24, 2013

How to get remote ip address when data get post through LB (Load Balancer)

In tomcat under conf/server.xml. Update below code




           prefix="localhost_access_log." suffix=".txt"
           pattern="%{X-Forwarded-For}i %h %l %u %t "%r" %s %b"    
resolveHosts="false" />

         

Java Code

The following Java code extracts the originating IP address of an HttpServletRequest object.

public final class HTTPUtils {

    private static final String HEADER_X_FORWARDED_FOR =
        "X-FORWARDED-FOR";

    public static String remoteAddr(HttpServletRequest request) {
        String remoteAddr = request.getRemoteAddr();
        String x;
        if ((x = request.getHeader(HEADER_X_FORWARDED_FOR)) != null) {
            remoteAddr = x;
            int idx = remoteAddr.indexOf(',');
            if (idx > -1) {
                remoteAddr = remoteAddr.substring(0, idx);
            }
        }
        return remoteAddr;
    }

}

Tuesday, April 23, 2013

Squirrel - Java SQL Client

Why Squirrel ?

SQuirreL SQL is an open-source Java SQL Client program for any JDBC compliant database. Easy configurable by loading jars and can connect to various SQL Servers (MSSQL, MySQL, Sybase...)

You can learn more about Squirrel.

Explore Squirrel

1) Download squirrel-sql-3.4.0-install.jar

2) Run / Execute the jar from console : java -jar squirrel-sql-3.4.0-install.jar

3) Squirrel will get install in your desktop as squirrel plugin under $HOME directory. You  have uninstall script under the same directory to do so.

4) Open the Squirrel client go to Drivers and select the driver, Click modify and load the (Jars for Mysql or MsSQL)  under External class path. 

For MySQL :
mysql-connector.jar - class name : com.mysql.jdbc.Driver

For SQL Server 
sqljdbc4.jar - class name : com.microsoft.sqlserver.jdbc.SQLServerDriver

5) Go to alias and add your 'new alias' with and show your driver. You will be connected to the server and enjoy playing with your squirrel client on connecting to different database servers.

Friday, March 15, 2013

How to change your browser User Agent ?

user Agent switcher for chrome

What's user agent ?

Your browser sends its user agent to every website you connect to. Based on the browser and platform some websites serves the content. Always user agent information will send to web servers to notify.

Thursday, March 14, 2013

Cloudera Manager (SCM - Service and Configuration Management for BigData)


How to change the ips in cloudera manager

1) stop all the cloudera manager agents in all the clusters
2) stop the cloudera manager server and server db service in the scm server (namenode server)
3) Modify /etc/cloudera-scm-agent/config.ini to point to the new scm server ip (namenode server ip)
4) In /etc/hosts file add your new ip address and hostnames
5) Start all the services 1 by 1 from server-db, server, agent and you can see the ips got changed in the Host on cloudera

Adding a new role instances to your cloudera manager or adding a new host into your existing cluster.

https://ccp.cloudera.com/display/ENT/Adding+Role+Instances

Monday, March 4, 2013

Tools to be installed in windows

MobaxTerm - MobaxTerm is the excellent tool to connect to linux as SSH.

Wednesday, February 20, 2013

Web Services

Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP)

Web services can be combined in a loosely coupled way to achieve complex operations. Programs providing simple services can interact with each other to deliver sophisticated added-value services.

Types of Web Services
"Big" Web Services
"RESTful" Web services

Tuesday, February 19, 2013

Couple of design patterns or architectural pattern most people know already


“Design patterns are recurring solutions to design problems.”

Patterns: According to commonly known practices, there are 23 design patterns in Java. These patterns are grouped under three heads:
1. Creational Patterns
2. Structural Patterns
3. Behavioral Patterns



Intercepting Filter : Facilitates preprocessing and post-processing of a request.

View Helper : Encapsulates logic that is not related to presentation formatting into Helper components. 

Business Delegate :Reduces coupling between presentation-tier clients and business services. It hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture.

Data Access Object : Abstracts and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.

Factory Pattern : The factory method pattern is an object-oriented creational design pattern to implement the concept of factories and deals with the problem of creating objects (products) without specifying the exact class of object that will be created. Inheritance also a factory pattern.

The factory pattern can be used when:
  • The creation of an object precludes its reuse without significant duplication of code.
  • The creation of an object requires access to information or resources that should not be contained within the composing class.
  • The lifetime management of the generated objects must be centralized to ensure a consistent behavior within the application.


Model–view–controller (MVC) is a software architecture pattern that separates the representation of information from the user's interaction with it.[1][2] The model consists of application data, business rules, logic, and functions. A view can be any output representation of data, such as a chart or a diagram. Multiple views of the same data are possible, such as a pie chart for management and a tabular view for accountants. The controller mediates input, converting it to commands for the model or view.[3] The central ideas behind MVC are code reusability and separation of concerns.[4]

Reference : http://www.allappforum.com/j2ee_design_patterns/j2ee_design_patterns.htm
// Below script tag for SyntaxHighLighter