use of javax.servlet.ServletRequestEvent in project opennms by OpenNMS.
the class DispatcherFilter method doFilter.
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final ServletRequestEvent sre = new ServletRequestEvent(m_filterConfig.getServletContext(), request);
m_controller.getRequestListener().requestInitialized(sre);
try {
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
final HttpServletRequest req = new AttributeEventRequest(m_filterConfig.getServletContext(), m_controller.getRequestAttributeListener(), (HttpServletRequest) request);
m_controller.getDispatcher().dispatch(req, (HttpServletResponse) response, chain);
} else {
chain.doFilter(request, response);
}
} finally {
m_controller.getRequestListener().requestDestroyed(sre);
}
}
use of javax.servlet.ServletRequestEvent in project wildfly by wildfly.
the class UndertowContextTestCase method addRequestListener.
@Test
public void addRequestListener() throws ServletException {
ServletRequestListener listener = mock(ServletRequestListener.class);
ServletContext context = mock(ServletContext.class);
ServletRequest request = mock(ServletRequest.class);
ApplicationListeners listeners = new ApplicationListeners(Collections.<ManagedListener>emptyList(), context);
ArgumentCaptor<ServletRequestEvent> event = ArgumentCaptor.forClass(ServletRequestEvent.class);
when(this.deployment.getApplicationListeners()).thenReturn(listeners);
this.context.addRequestListener(listener);
listeners.start();
listeners.requestInitialized(request);
verify(listener).requestInitialized(event.capture());
assertSame(request, event.getValue().getServletRequest());
assertSame(context, event.getValue().getServletContext());
event = ArgumentCaptor.forClass(ServletRequestEvent.class);
listeners.requestDestroyed(request);
verify(listener).requestDestroyed(event.capture());
assertSame(request, event.getValue().getServletRequest());
assertSame(context, event.getValue().getServletContext());
}
use of javax.servlet.ServletRequestEvent in project tomee by apache.
the class HttpRequestImpl method destroy.
public void destroy() {
final boolean openejbRequestDestroyed = getAttribute("openejb_requestDestroyed") == null;
if (listeners != null && !listeners.isEmpty()) {
if (begin != null && end != null && openejbRequestDestroyed) {
end.requestDestroyed(new ServletRequestEvent(getServletContext(), this));
}
final ServletRequestEvent event = new ServletRequestEvent(getServletContext(), this);
for (final ServletRequestListener listener : listeners) {
listener.requestDestroyed(event);
}
}
if (begin != null && openejbRequestDestroyed) {
setAttribute("openejb_requestDestroyed", "ok");
begin.requestDestroyed(new ServletRequestEvent(getServletContext(), this));
}
}
use of javax.servlet.ServletRequestEvent in project tomcat by apache.
the class StandardContext method fireRequestDestroyEvent.
@Override
public boolean fireRequestDestroyEvent(ServletRequest request) {
Object[] instances = getApplicationEventListeners();
if ((instances != null) && (instances.length > 0)) {
ServletRequestEvent event = new ServletRequestEvent(getServletContext(), request);
for (int i = 0; i < instances.length; i++) {
int j = (instances.length - 1) - i;
if (instances[j] == null)
continue;
if (!(instances[j] instanceof ServletRequestListener))
continue;
ServletRequestListener listener = (ServletRequestListener) instances[j];
try {
listener.requestDestroyed(event);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
getLogger().error(sm.getString("standardContext.requestListener.requestInit", instances[j].getClass().getName()), t);
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
return false;
}
}
}
return true;
}
use of javax.servlet.ServletRequestEvent in project jetty.project by eclipse.
the class RequestTest method testBadMultiPart.
@Test
public void testBadMultiPart() throws Exception {
//a bad multipart where one of the fields has no name
final File testTmpDir = File.createTempFile("badmptest", null);
if (testTmpDir.exists())
testTmpDir.delete();
testTmpDir.mkdir();
testTmpDir.deleteOnExit();
assertTrue(testTmpDir.list().length == 0);
ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/foo");
contextHandler.setResourceBase(".");
contextHandler.setHandler(new BadMultiPartRequestHandler(testTmpDir));
contextHandler.addEventListener(new MultiPartCleanerListener() {
@Override
public void requestDestroyed(ServletRequestEvent sre) {
MultiPartInputStreamParser m = (MultiPartInputStreamParser) sre.getServletRequest().getAttribute(Request.__MULTIPART_INPUT_STREAM);
ContextHandler.Context c = (ContextHandler.Context) sre.getServletRequest().getAttribute(Request.__MULTIPART_CONTEXT);
assertNotNull(m);
assertNotNull(c);
assertTrue(c == sre.getServletContext());
super.requestDestroyed(sre);
String[] files = testTmpDir.list();
assertTrue(files.length == 0);
}
});
_server.stop();
_server.setHandler(contextHandler);
_server.start();
String multipart = "--AaB03x\r\n" + "content-disposition: form-data; name=\"xxx\"\r\n" + "\r\n" + "Joe Blow\r\n" + "--AaB03x\r\n" + "content-disposition: form-data; filename=\"foo.upload\"\r\n" + "Content-Type: text/plain;charset=ISO-8859-1\r\n" + "\r\n" + "000000000000000000000000000000000000000000000000000\r\n" + "--AaB03x--\r\n";
String request = "GET /foo/x.html HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: multipart/form-data; boundary=\"AaB03x\"\r\n" + "Content-Length: " + multipart.getBytes().length + "\r\n" + "Connection: close\r\n" + "\r\n" + multipart;
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
String responses = _connector.getResponse(request);
//System.err.println(responses);
assertTrue(responses.startsWith("HTTP/1.1 500"));
}
}
Aggregations