Friday, August 5, 2016

Installing MariaDB 10.1 on CentOS 6

Inorder to install MariaDB 10.1 you nned to have your MariaDB.repo entry. So create a file "/etc/yum.repos.d/MariaDB.repo" under "/etc/yum.repos.d/" directory.
Update the MariaDB.repo file with below text for 64bit OS

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Update the MariaDB.repo file with below text for 32bit OS
`
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Now run below command just to check if the repo is set correctly.

#sudo yum search Mariadb 

Now install MariaDB using below command

# yum install MariaDB-server MariaDB*engine MariaDB-client

Tuesday, June 21, 2016

Error : class_name is not mapped, Hibernate


You may get this error while using Hibernate with Java. There could be multiple reasons why this can happen

  1. You haven't really mapped the class name in config.
  2. The class name ( Entity) is case sensitive, meaning you should specify the entity name as is in the query. Your entity name may differ than table  name in DB, but still you will have to refer to exact case of entity name. 


Thursday, May 5, 2016

Exception handling with RestTemplate

Spring framework offers RestTemplate for consuming RESTful services. Recently I used RestTemplate for consuming one of the third party RESTful service.

RestTemplate offers 'ResponseErrorHandler'; which you can extend to decide which are errors for you and how to handle those error. You can override hasError and handleError methods of ResponseErrorHandler.
In handleError you can throw customException if you want, as outlined in below code.

import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;

import java.io.IOException;

public class RestTemplateErrorHandler implements ResponseErrorHandler {

    @Override
    public void handleError(ClientHttpResponse response) throws IOException
    {
        throw new MyCustomException(response.getStatusText(), response.getStatusCode());
    }

    @Override
    public boolean hasError(ClientHttpResponse response) throws IOException
    {
        if ( (response.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR)
                || (response.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR))
        {
            return true;
        }
        return false;
    }
}

But there is caveat with this error handler. If the server is down or not accessible, RestTemplate throws 'ResourceAccessException'. Internally RestTemplate encounters 'IOException' when server is not accessible. RestTemplate catches 'IOException' and throws 'ResourceAccessException'. In this process error handler doesn't  get invoked hence the custom exception will not be thrown.

So to avoid this situation I handled 'RestClientException' in code where RestTemplate was being invoked, and returned proper error message.

Related Posts:
Exception handeling for RESTful service