use of javax.servlet.ServletResponse in project jetty.project by eclipse.
the class ServletHandler method doHandle.
@Override
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
ServletHolder servlet_holder = (ServletHolder) baseRequest.getUserIdentityScope();
FilterChain chain = null;
// find the servlet
if (target.startsWith("/")) {
if (servlet_holder != null && _filterMappings != null && _filterMappings.length > 0)
chain = getFilterChain(baseRequest, target, servlet_holder);
} else {
if (servlet_holder != null) {
if (_filterMappings != null && _filterMappings.length > 0) {
chain = getFilterChain(baseRequest, null, servlet_holder);
}
}
}
if (LOG.isDebugEnabled())
LOG.debug("chain={}", chain);
try {
if (servlet_holder == null)
notFound(baseRequest, request, response);
else {
// unwrap any tunnelling of base Servlet request/responses
ServletRequest req = request;
if (req instanceof ServletRequestHttpWrapper)
req = ((ServletRequestHttpWrapper) req).getRequest();
ServletResponse res = response;
if (res instanceof ServletResponseHttpWrapper)
res = ((ServletResponseHttpWrapper) res).getResponse();
// Do the filter/handling thang
servlet_holder.prepare(baseRequest, req, res);
if (chain != null)
chain.doFilter(req, res);
else
servlet_holder.handle(baseRequest, req, res);
}
} finally {
if (servlet_holder != null)
baseRequest.setHandled(true);
}
}
use of javax.servlet.ServletResponse in project gitblit by gitblit.
the class ProxyFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse res, final FilterChain last) throws IOException, ServletException {
final Iterator<HttpRequestFilter> itr = filters.iterator();
new FilterChain() {
@Override
public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {
if (itr.hasNext()) {
itr.next().doFilter(req, res, this);
} else {
last.doFilter(req, res);
}
}
}.doFilter(req, res);
}
use of javax.servlet.ServletResponse in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldClearThreadContextInCaseOfExceptionAsWell.
@Test
public void shouldClearThreadContextInCaseOfExceptionAsWell() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
messageKey = service.add(new FlashMessageModel("my message", "error"));
flash = service.get(messageKey);
throw new RuntimeException("exception here");
}
};
try {
filter.doFilter(req, res, filterChain);
fail("exception gobbled");
} catch (Exception e) {
assertThat(e.getMessage(), is("exception here"));
}
assertThat(flash.toString(), is("my message"));
try {
service.get(messageKey);
fail("attempt to load flash message should fail, as no thread local is cleared out");
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("No flash context found, this call should only be made within a request."));
}
}
use of javax.servlet.ServletResponse in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldInitializeFlashIfNotPresent.
@Test
public void shouldInitializeFlashIfNotPresent() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
messageKey = service.add(new FlashMessageModel("my message", "error"));
flash = service.get(messageKey);
}
};
assertThat(messageKey, is(nullValue()));
filter.doFilter(req, res, filterChain);
assertThat(messageKey, not(nullValue()));
assertThat(flash.toString(), is("my message"));
assertThat(flash.getFlashClass(), is("error"));
}
use of javax.servlet.ServletResponse in project guice by google.
the class FilterDefinitionTest method testFilterCreateDispatchDestroy.
public final void testFilterCreateDispatchDestroy() throws ServletException, IOException {
Injector injector = createMock(Injector.class);
Binding binding = createMock(Binding.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
final MockFilter mockFilter = new MockFilter();
expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
expect(injector.getBinding(Key.get(Filter.class))).andReturn(binding);
expect(injector.getInstance(Key.get(Filter.class))).andReturn(mockFilter).anyTimes();
expect(request.getRequestURI()).andReturn("/index.html");
expect(request.getContextPath()).andReturn("").anyTimes();
replay(injector, binding, request);
String pattern = "/*";
final FilterDefinition filterDef = new FilterDefinition(Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
//should fire on mockfilter now
filterDef.init(createMock(ServletContext.class), injector, Sets.<Filter>newIdentityHashSet());
assertTrue(filterDef.getFilter() instanceof MockFilter);
assertTrue("Init did not fire", mockFilter.isInit());
Filter matchingFilter = filterDef.getFilterIfMatching(request);
assertSame(mockFilter, matchingFilter);
final boolean[] proceed = new boolean[1];
matchingFilter.doFilter(request, null, new FilterChainInvocation(null, null, null) {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) {
proceed[0] = true;
}
});
assertTrue("Filter did not proceed down chain", proceed[0]);
filterDef.destroy(Sets.<Filter>newIdentityHashSet());
assertTrue("Destroy did not fire", mockFilter.isDestroy());
verify(injector, request);
}
Aggregations