use of javax.servlet.ServletRequest in project ddf by codice.
the class DelegateServletFilterTest method testDoFilterWithFilters.
/**
* Tests the main logic of performing the filter with adding filters.
*
* @throws ServletException
* @throws IOException
* @throws InvalidSyntaxException
*/
@Test
public void testDoFilterWithFilters() throws IOException, ServletException, InvalidSyntaxException {
ServletRequest request = mock(HttpServletRequest.class);
ServletResponse response = mock(HttpServletResponse.class);
final BundleContext context = createMockContext(true);
DelegateServletFilter filter = new DelegateServletFilter() {
@Override
protected BundleContext getContext() {
return context;
}
};
filter.doFilter(request, response, initialChain);
verifyFiltersCalled(request, response, initialChain);
}
use of javax.servlet.ServletRequest in project ddf by codice.
the class ProxyFilterChainTest method testDoFilter.
/**
* Tests that all of the filters are properly called.
*
* @throws ServletException
* @throws IOException
*/
@Test
public void testDoFilter() throws IOException, ServletException {
FilterChain initialChain = mock(FilterChain.class);
ProxyFilterChain proxyChain = new ProxyFilterChain(initialChain);
Filter filter1 = createMockFilter("filter1");
Filter filter2 = createMockFilter("filter2");
Filter filter3 = createMockFilter("filter3");
ServletRequest request = mock(ServletRequest.class);
ServletResponse response = mock(ServletResponse.class);
proxyChain.addFilter(filter1);
proxyChain.addFilters(Arrays.asList(filter2, filter3));
proxyChain.doFilter(request, response);
// Verify that all of the filters were called once.
verify(filter1).doFilter(request, response, proxyChain);
verify(filter2).doFilter(request, response, proxyChain);
verify(filter3).doFilter(request, response, proxyChain);
// the initial chain should have also been called once (at the end).
verify(initialChain).doFilter(request, response);
}
use of javax.servlet.ServletRequest in project ddf by codice.
the class ProxyFilterChainTest method createMockFilter.
private Filter createMockFilter(final String name) throws IOException, ServletException {
Filter mockFilter = mock(Filter.class);
Mockito.when(mockFilter.toString()).thenReturn(name);
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LOGGER.debug("{} was called.", name);
((FilterChain) args[2]).doFilter(((ServletRequest) args[0]), ((ServletResponse) args[1]));
return null;
}
}).when(mockFilter).doFilter(any(ServletRequest.class), any(ServletResponse.class), any(FilterChain.class));
return mockFilter;
}
use of javax.servlet.ServletRequest in project processdash by dtuma.
the class DashboardUriPrefixFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String prefix = getPrefix(request);
if (prefix == null) {
chain.doFilter(request, response);
} else {
Request req = Request.getRequest((HttpServletRequest) request);
String origRequestURI = req.getRequestURI();
String origContextPath = req.getContextPath();
String fullRequestURI = prefix + origRequestURI;
String fullContextPath = prefix + origContextPath;
try {
req.setRequestURI(fullRequestURI);
req.setContextPath(fullContextPath);
chain.doFilter(request, response);
} finally {
req.setRequestURI(origRequestURI);
req.setContextPath(origContextPath);
}
}
}
use of javax.servlet.ServletRequest in project hadoop by apache.
the class AmIpFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
ProxyUtils.rejectNonHttpRequests(req);
HttpServletRequest httpReq = (HttpServletRequest) req;
HttpServletResponse httpResp = (HttpServletResponse) resp;
if (LOG.isDebugEnabled()) {
LOG.debug("Remote address for request is: {}", httpReq.getRemoteAddr());
}
if (!getProxyAddresses().contains(httpReq.getRemoteAddr())) {
StringBuilder redirect = new StringBuilder(findRedirectUrl());
redirect.append(httpReq.getRequestURI());
int insertPoint = redirect.indexOf(PROXY_PATH);
if (insertPoint >= 0) {
// Add /redirect as the second component of the path so that the RM web
// proxy knows that this request was a redirect.
insertPoint += PROXY_PATH.length();
redirect.insert(insertPoint, "/redirect");
}
ProxyUtils.sendRedirect(httpReq, httpResp, redirect.toString());
} else {
String user = null;
if (httpReq.getCookies() != null) {
for (Cookie c : httpReq.getCookies()) {
if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) {
user = c.getValue();
break;
}
}
}
if (user == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME + " cookie, so user will not be set");
}
chain.doFilter(req, resp);
} else {
AmIpPrincipal principal = new AmIpPrincipal(user);
ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, principal);
chain.doFilter(requestWrapper, resp);
}
}
}
Aggregations