
io.katharsis.servlet.internal.ServletParametersProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of katharsis-servlet Show documentation
Show all versions of katharsis-servlet Show documentation
Generic Servlet Adapter of Katharsis JSON:API middleware library
The newest version!
package io.katharsis.servlet.internal;
import java.lang.reflect.Method;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.katharsis.legacy.internal.RepositoryMethodParameterProvider;
public class ServletParametersProvider implements RepositoryMethodParameterProvider {
private ServletContext servletContext;
private HttpServletRequest httpServletRequest;
private HttpServletResponse httpServletResponse;
public ServletParametersProvider(ServletContext servletContext, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
this.servletContext = servletContext;
this.httpServletRequest = httpServletRequest;
this.httpServletResponse = httpServletResponse;
}
@Override
@SuppressWarnings("unchecked")
public T provide(Method method, int parameterIndex) {
Class> parameterType = method.getParameterTypes()[parameterIndex];
Object returnValue = null;
if (ServletContext.class.isAssignableFrom(parameterType)) {
returnValue = servletContext;
} else if (HttpServletRequest.class.isAssignableFrom(parameterType)) {
returnValue = httpServletRequest;
} else if (HttpServletResponse.class.isAssignableFrom(parameterType)) {
returnValue = httpServletResponse;
}
return (T) returnValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy