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

core.dynamic.resources.DynamicRequest Maven / Gradle / Ivy

Go to download

Epikos is a Rest Serivce framework which can be extend to develop any other Rest API/Services. For more detail please checkout github (https://github.com/epikosrest/epikos.git)

There is a newer version: 0.0.7.8.1
Show newest version
package core.dynamic.resources;

import com.fasterxml.jackson.databind.ObjectMapper;
import core.exception.EpikosException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by nitina on 5/17/16.
 */
public final class DynamicRequest implements IDynamicRequest{

    ContainerRequestContext requestContext;
    InputStream requestStream;
    MultivaluedMap pathParams;

    public DynamicRequest(ContainerRequestContext requestContext, MultivaluedMap pathParams){
        this.requestContext = requestContext;
        this.requestStream = requestContext.getEntityStream();
        this.pathParams = pathParams;
    }

    @Override
    public  T getRequest(final Class typeOfRequest) throws EpikosException {
        ObjectMapper mapper = new ObjectMapper();
        try {
            //Note: by this time the inputstream has been decoded by one of filter (PostRequestFilter/PreReqeustFilter)
            return (T) mapper.readValue(requestStream, typeOfRequest.newInstance().getClass());
        }catch (IOException ioExp){
            throw new EpikosException(ioExp.getMessage());

        }catch (InstantiationException instExp){
            throw new EpikosException(instExp.getMessage());

        }catch (IllegalAccessException illExp){
            throw new EpikosException(illExp.getMessage());
        }
    }

    @Override
    public MultivaluedMap getPathParams() {
        return pathParams;
    }

    @Override
    public ContainerRequestContext getRequestContext() {
        return requestContext;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy