core.dynamic.resources.DynamicRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of EpikosRestService Show documentation
Show all versions of EpikosRestService Show documentation
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)
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;
}
}