All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ijson.rest.proxy.codec.AbstractRestCodeC Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.ijson.rest.proxy.codec;


import com.ijson.rest.proxy.exception.RestProxyRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

/**
 * Created by cuiyongxu on 04/01/2017.
 */
@Slf4j
public abstract class AbstractRestCodeC {
    public abstract  byte[] encodeArg(T obj);

    public  T decodeResult(int statusCode, Map> headers, byte[] bytes, Class clazz) {
        switch (statusCode) {
            case HttpStatus.SC_OK:
                return null;
            default:
                String msg = null;
                if (bytes != null) {
                    try {
                        msg = new String(bytes, "utf-8");
                    } catch (UnsupportedEncodingException e) {
                        log.error("decodeResult:{}", e);
                    }
                }
                throw new RestProxyRuntimeException(statusCode, msg);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy