Sunday, October 11, 2015

Increase request timeout Inginx

make following changes to /etc/nginx/nginx.conf - 

location / {

proxy_connect_timeout  600s;
proxy_send_timeout  600s;
proxy_read_timeout  600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;


Tuesday, September 22, 2015

Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

When you try to send mail from code and you find the error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required", than the error might occur due to following cases.
case 1: when the password is wrong
case 2: when you try to login from some App
case 3: when you try to login from the domain other than your time zone/domain/computer (This is the case in most of scenarios when sending mail from code)

There is a solution for each 

Solution for case 1: Enter the correct password.

solution for case 2: go to security settings at the followig link and enable less secure apps . So that you will be able to login from all apps.

solution 1 for case 3: (This might be helpful) you need to review the activity. but reviewing the activity will not be helpful due to latest security standards the link will not be useful. So try the below case.

solution 2 for case 3: If you have hosted your code somewhere on production server and if you have access to the production server, than take remote desktop connection to the production server and try to login once from the browser of the production server. This will add excpetioon for login to google and you will be allowed to login from code.

But what if you don't have access to the production server. try the solution

3 solution 3 for case 3: You have to enable login from other timezone / IP for your google account. to do this follow the link and allow access by clicking the continue button.

And that's it. Here you go. Now you will be able to login from any of the computer and by any means of app to your google account.

Sunday, September 6, 2015

How to redirect to specific tomcat port from nginx configuration

1: Create a file

2: sudo chmod +x /etc/nginx/conf.d/example.conf

3: Copy this content and change the domain name according to you domain.

server {
    rewrite ^(.*)$1 permanent;

server {
  listen          80 default_server;
  listen [::]:80 default_server ipv6only=on;
  root            /opt/apache-tomcat-8.0.24/webapps/ROOT;

  location / {
proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;

Saturday, August 22, 2015

Porxy for apache to tomcat redirect

1: Open file /etc/apache2/sites-enabled/000-default.conf
2: Change content
3: Restart apache2

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.

ServerAdmin webmaster@localhost
ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    ProxyPreserveHost on
    ProxyPass / http://localhost:8080/
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Monday, December 9, 2013

Is the JVM a compiler or an interpreter?

First, let's have a clear idea of the following terms
Javac is Java Compiler -- Compiles your Java code into Bytecode
JVM is Java Virtual Machine -- Runs/ Interprets/ translates Bytecode into Native Machine Code
JIT is Just In Time Compiler -- Compiles the given bytecode instruction sequence to machine code at run-time before executing it natively. It's main purpose is to do heavy optimizations in performance.
So now, Let's find answers to your questions..
1)JVM: is it a compiler or an interpreter? -- Ans: Interpreter
2)what about JIT compiler that exist inside the JVM? -- Ans: If you read this reply completely, you probably know it now
3)what exactly is the JVM? -- Ans:
  • JVM is a virtual platform that resides on your RAM
  • Its component, Class loader loads the .class file into the RAM
  • The Byte code Verifier component in JVM checks if there are any access restriction violations in your code. (This is one of the principle reasons why java is secure)
  • Next, the Execution Engine component converts the Bytecode into executable machine code

Tuesday, February 5, 2013

Example AES technology

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Test {

     * @param args
    public static void main(String[] args) {
          System.out.println("Listing all table name in Database!");
          Connection con = null;
          String url = "jdbc:mysql://localhost:3306/";
          String db = "test";
          String driver = "com.mysql.jdbc.Driver";
          String user = "root";
          String pass = "root";
          String name="";
          String address="";
              con = DriverManager.getConnection(url+db, user, pass);
                  System.out.println("Table name:");
                  Statement st = con.createStatement();
                  ResultSet rs = st.executeQuery("select AES_DECRYPT(name, 'usa2010'), AES_DECRYPT(address, 'usa2010') FROM test.table1");
                  while ({
                          name = IOUtils.toString(rs.getBinaryStream(1), "UTF-8"); ;
                          address = IOUtils.toString(rs.getBinaryStream(2), "UTF-8");
                          System.out.println("name: "+name);
                          System.out.println("address: "+address);
              catch (SQLException s){
          catch(Exception e){

Monday, February 4, 2013

Heap size for JVM

Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size. Here are some common mistakes made by developers while using them:
  1. Missing m, M, g or G at the end (they are case insensitive). For example,

    java -Xmx128 BigApp
    java.lang.OutOfMemoryError: Java heap space
    The correct command should be: java -Xmx128m BigApp. To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean -Xmx128m

  2. Extra space in JVM options, or incorrectly use =. For example,

    java -Xmx 128m BigApp
    Invalid maximum heap size: -Xmx
    Could not create the Java virtual machine.
    java -Xmx=512m HelloWorld
    Invalid maximum heap size: -Xmx=512m
    Could not create the Java virtual machine.
    The correct command should be java -Xmx128m BigApp, with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used.

  3. Only setting -Xms JVM option and its value is greater than the default maximum heap size, which is 64m. The default minimum heap size seems to be 0. For example,

    java -Xms128m BigApp
    Error occurred during initialization of VM
    Incompatible initial and maximum heap sizes specified
    The correct command should be java -Xms128m -Xmx128m BigApp. Its a good idea to set the minimum and maximum heap size to the same value. In any case, dont let the minimum heap size exceed the maximum heap size.

  4. Heap size is larger than your computers physical memory. For example,

    java -Xmx2g BigApp
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Could not create the Java virtual machine.
    The fix is to make it lower than the physical memory: java -Xmx1g BigApp

  5. Incorrectly use mb as the unit, where m or M should be used instead.

    java -Xms256mb -Xmx256mb BigApp
    Invalid initial heap size: -Xms256mb
    Could not create the Java virtual machine.