Technologies

I will mostly write about following

Java, J2EE, GWT(Google Web Toolkit), HTML, Javascript, Linux, MacOS, Queue, Docker, Cloud hosting, Auto Scaling, Web, Ad Serving etc.

Configure nginx to server multiple domains / subdomains

With nginx it is quite easy to configure multiple domains or subdomains to be served from single server. Refer following configuration for the same.

        server {
            server_name first.pandurangpatil.com;
            root /var/www/first;
        }

        server {
            server_name second.pandurangpatil.com;
            root /var/www/second;
        }

        server {
            server_name someother.com;
            root /var/www/other;
        }

Compare more than two war files and repackage them excluding common jars

Some times you need to deploy more than one war files under same servlet container. In those war files there might have some common jars across them, which you want to deploy directly to servlet containers class path. So that container won’t load those jars separately in the context of each war application. Which in turn will reduce the utilisation of permgen memory space. Following code snippet will help you to compare more than two war files, extract common shared libraries inside separate folder and repackage those wars excluding common jar files. [Read More]
java  war 

nginx proxypass configuration with X-Forwarded-Host header

I have used and configured apache for proxy pass and proxy pass reverse multiple times with X-Forwarded-Host. I tried configuring same with nginx and it works out to be more customisable and easy one.

        server {
            listen       80;
            server_name  pandurangpatil.com;
            location /myapp {
                proxy_set_header X-Forwarded-Host $host;
                proxy_pass http://localhost:8080/myapp;
            }
            .
            .
            .
        }

MySql JPA toplink Auto increment id generation.

To configure JPA entity to make use of auto increment feature of MySql for primary key generation you can make use of IDENTITY strategy ref below code. @Entity public class Customer { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private long id; . . . public long getId() { return id; } } But problem with this way of generating ids with MySql and JPA combination is when you persist new entity and try to retrieve id assigned to newly persisted entity using getId() method. [Read More]
jpa  mysql  ORM  Java 

Java java.lang.OutOfMemoryError: PermGen space

java.lang.OutOfMemoryError: PermGen space You get this error that means your JVM is running out of allocated memory for storing class metadata information (class properties, methods annotations etc). This space is not cleaned by Garbage collector. It could happen because of multiple reasons. One you are dynamically generating classes and those are getting loaded in JVM. Second your application is so big and it has more number of dependencies on other third party libraries. [Read More]

Tomcat 7 onwards set additional JAVA_OPTS options

To set JAVA_OPTS options which you want to set additionally while running the tomcat should be set inside <tomcat home>/bin/setenv.sh if this file is not present then create one and set variable JAVA_OPTS="-Dsomething $JAVA_OPTS". If you have to set some variables while only starting the tomcat then you need to set those variables to CATALINA_OPTS rather than JAVA_OPTS.

Jersey REST retrieve List of custom object

It took me while to understand how one require to retrieve generic object from ClientResponse. I had an array of objects in Json format as a response of an REST api, which I was trying to deserialize it into List<CustomObject> refer below sample. ClientResponse rsp = webresource.path(id.toString()).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); List<CustomObject> list = rsp.getEntity(new GenericType<List<CustomObject>>(CustomObject.class)); But I kept on getting following Error: Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of test.CustomObject out of START_ARRAY token at [Source: sun. [Read More]

Install nginx on OS-X

One need to have gcc installed for that you need to install xcode along with command line tools. To install the same one can refer to this link for xcode 5.0.1. Nginx requires PCRE – Perl Compatible Regular Expressions to build, I used PCRE version 8.33 Install PCRE $ mkdir source $ cd source $ curl -OL ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz $ tar -zxvf pcre-8.33.tar.gz $ cd pcre-8.33/ $ ./configure $ make $ sudo make install Install nginx [Read More]

Set default submit button on a page with GWT

I found few ways to set default submit button on page with GWT. Add key press handler for all form fields check for Enter button press and take action. You can add common key press handler for all form fields. This way you are not adding multiple handler for each form field. (I am assuming you understand what is ui handler and how it works.) @UiHandler({ "txtCompanyName", "txtcontactName", "txtEmail" }) public void onKeyPress(KeyPressEvent event) { if (event. [Read More]

Set environment variable which is inherited inside eclipse workspace

Ubuntu : Set required environment variable inside /etc/environment and restart the machine. This will set environment variable which can be inherited inside eclipse workspace. Above method will set the environment variable for all the users. To set environment variable for individual user set the required variable inside <user home>/.profile file. While doing so please make sure you use export keyword before variable. Alterante option to use .bashrc to set those environment variable, here as well you need to prefix export keyword. [Read More]