com.atlassian.router.internal.HttpServletRequestWithContextImpl Maven / Gradle / Ivy
The newest version!
package com.atlassian.router.internal;
import com.atlassian.router.HttpServletRequestWithContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.Hashtable;
import java.util.Map;
import java.util.Optional;
public class HttpServletRequestWithContextImpl
extends HttpServletRequestWrapper
implements HttpServletRequestWithContext {
Map, Object> contexts;
public HttpServletRequestWithContextImpl(HttpServletRequest request) {
super(request);
this.contexts = new Hashtable<>();
}
public void addContext(T context) {
contexts.put(context.getClass(), context);
}
public Optional getContext(Class klass) {
if (!contexts.containsKey(klass)) {
return Optional.empty();
}
return Optional.of((T) contexts.get(klass));
}
}