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

play.api.rest.converter.thrift.ThriftResponseBodyConverter Maven / Gradle / Ivy

The newest version!
package play.api.rest.converter.thrift;

import org.apache.http.HttpResponse;
import org.apache.thrift.TBase;
import play.api.rest.Converter;
import play.api.rest.Rest;
import play.libs.transport.http.HTTPUtils;
import play.libs.transport.thrift.Thrifts;

import java.io.IOException;

public class ThriftResponseBodyConverter implements Converter {
    private Class clazz;

    public ThriftResponseBodyConverter(Class clazz){
        this.clazz = clazz;
    }

    @Override
    public T convert(HttpResponse value) throws IOException {
        try {
            T instance = clazz.newInstance();
            instance = Thrifts.parseForm(instance,value.getEntity().getContent());
            if(Rest.LOGGER.isDebugEnabled()){
                Rest.LOGGER.debug(instance.toString());
            }
            return instance;
        }catch (Exception e){
            throw new RuntimeException(e);
        }finally {
            HTTPUtils.closeQuietly(value);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy