// Path: common/dataobjects/src/main/java/com/sastix/cms/common/dataobjects/RestErrorDTO.java
// @Getter @Setter @NoArgsConstructor @ToString
// public class RestErrorDTO {
//     
//     private String exception;
//     
//     private String path;
// 
//     private String error;
//     
//     private String message;
//     
//     private String timestamp;
//     
//     private String status;
// 
// }
// 
// Path: common/dataobjects/src/main/java/com/sastix/cms/common/exception/BusinessException.java
// public class BusinessException extends CommonException {
// 
//     /**
//      * Serial Version UID.
//      */
//     private static final long serialVersionUID = -4503174570809593447L;
// 
//     /**
//      * Constructor that allows a specific error message to be specified.
//      *
//      * @param message detail message.
//      */
//     public BusinessException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Creates a {@code BusinessException} with the specified
//      * detail message and cause.
//      *
//      * @param message the detail message
//      * @param cause   the cause
//      */
//     public BusinessException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sastix.cms.common.dataobjects.RestErrorDTO;
import com.sastix.cms.common.exception.BusinessException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.*;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
/*
 * Copyright(c) 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sastix.cms.common.client.exception;




/**
 * RestTemplate Custom Exception Handler.
 */
@Slf4j
public class CommonExceptionHandler implements ResponseErrorHandler {

    /**
     * Json factory instance.
     */
    private final JsonFactory factory = new JsonFactory();

    /**
     * Object Mapper used to covert JSON object to Java object.
     */
    private final ObjectMapper objectMapper = new ObjectMapper(factory);

    /**
     * HashMap which holds the supported exception classes.
     */
    private final ConcurrentHashMap<String, ExceptionHandler> exceptionClasses = new ConcurrentHashMap<>();

    public CommonExceptionHandler() {
// Path: common/dataobjects/src/main/java/com/sastix/cms/common/dataobjects/RestErrorDTO.java
// @Getter @Setter @NoArgsConstructor @ToString
// public class RestErrorDTO {
//     
//     private String exception;
//     
//     private String path;
// 
//     private String error;
//     
//     private String message;
//     
//     private String timestamp;
//     
//     private String status;
// 
// }
// 
// Path: common/dataobjects/src/main/java/com/sastix/cms/common/exception/BusinessException.java
// public class BusinessException extends CommonException {
// 
//     /**
//      * Serial Version UID.
//      */
//     private static final long serialVersionUID = -4503174570809593447L;
// 
//     /**
//      * Constructor that allows a specific error message to be specified.
//      *
//      * @param message detail message.
//      */
//     public BusinessException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Creates a {@code BusinessException} with the specified
//      * detail message and cause.
//      *
//      * @param message the detail message
//      * @param cause   the cause
//      */
//     public BusinessException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


// Path: common/client/src/main/java/com/sastix/cms/common/client/exception/CommonExceptionHandler.java
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sastix.cms.common.dataobjects.RestErrorDTO;
import com.sastix.cms.common.exception.BusinessException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.*;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;

/*
 * Copyright(c) 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sastix.cms.common.client.exception;




/**
 * RestTemplate Custom Exception Handler.
 */
@Slf4j
public class CommonExceptionHandler implements ResponseErrorHandler {

    /**
     * Json factory instance.
     */
    private final JsonFactory factory = new JsonFactory();

    /**
     * Object Mapper used to covert JSON object to Java object.
     */
    private final ObjectMapper objectMapper = new ObjectMapper(factory);

    /**
     * HashMap which holds the supported exception classes.
     */
    private final ConcurrentHashMap<String, ExceptionHandler> exceptionClasses = new ConcurrentHashMap<>();

    public CommonExceptionHandler() {
        exceptionClasses.put(BusinessException.class.getName(), BusinessException::new);