本文整理汇总了Java中javax.servlet.ServletRequestEvent类的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestEvent类的具体用法?Java ServletRequestEvent怎么用?Java ServletRequestEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletRequestEvent类属于javax.servlet包,在下文中一共展示了ServletRequestEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestDestroyed
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestDestroyed(ServletRequestEvent requestEvent) {
ServletRequestAttributes attributes = null;
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
if (reqAttr instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) reqAttr;
}
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
if (threadAttributes != null) {
// We're assumably within the original request thread...
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
if (attributes == null && threadAttributes instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) threadAttributes;
}
}
if (attributes != null) {
attributes.requestCompleted();
}
}
示例2: requestContextListenerWithSameThread
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Test
public void requestContextListenerWithSameThread() {
RequestContextListener listener = new RequestContextListener();
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
request.setAttribute("test", "value");
assertNull(RequestContextHolder.getRequestAttributes());
listener.requestInitialized(new ServletRequestEvent(context, request));
assertNotNull(RequestContextHolder.getRequestAttributes());
assertEquals("value",
RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
MockRunnable runnable = new MockRunnable();
RequestContextHolder.getRequestAttributes().registerDestructionCallback(
"test", runnable, RequestAttributes.SCOPE_REQUEST);
listener.requestDestroyed(new ServletRequestEvent(context, request));
assertNull(RequestContextHolder.getRequestAttributes());
assertTrue(runnable.wasExecuted());
}
示例3: requestContextListenerWithSameThreadAndAttributesGone
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Test
public void requestContextListenerWithSameThreadAndAttributesGone() {
RequestContextListener listener = new RequestContextListener();
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
request.setAttribute("test", "value");
assertNull(RequestContextHolder.getRequestAttributes());
listener.requestInitialized(new ServletRequestEvent(context, request));
assertNotNull(RequestContextHolder.getRequestAttributes());
assertEquals("value",
RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
MockRunnable runnable = new MockRunnable();
RequestContextHolder.getRequestAttributes().registerDestructionCallback(
"test", runnable, RequestAttributes.SCOPE_REQUEST);
request.clearAttributes();
listener.requestDestroyed(new ServletRequestEvent(context, request));
assertNull(RequestContextHolder.getRequestAttributes());
assertTrue(runnable.wasExecuted());
}
示例4: requestInitialized
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent sre) {
ServletContext servletContext = sre.getServletContext();
ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
GroovyClassLoader classLoader = applicationContext.getBean(GroovyClassLoader.class);
if (Thread.currentThread().getContextClassLoader() instanceof GroovyClassLoader) {
} else {
Thread.currentThread().setContextClassLoader(classLoader);
}
DataSource dataSource = applicationContext.getBean(DataSource.class);
try {
this.connection = dataSource.getConnection();
this.connection.setAutoCommit(true);
} catch (SQLException e) {
}
}
示例5: requestInitialized
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent e) {
LOG.debug("Request entered");
HttpServletRequest req = (HttpServletRequest) e.getServletRequest();
WebConfiguration wc = Iocular.getConfiguration(e.getServletContext());
Container sc = createSessionContainer(req.getSession(true));
if(sc == null)
throw new IllegalStateException("No session container found!?");
//-- Create a request container,
BasicContainer bc = new BasicContainer(wc.getRequestDefinition(), sc);
bc.start();
req.setAttribute(Keys.REQUEST_CONTAINER, bc);
Iocular._setRequest((HttpServletRequest) e.getServletRequest(), bc);
}
示例6: doFilter
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
// set our context classloader
Thread.currentThread().setContextClassLoader(classLoader);
// send a requestInititalized event
ServletRequestEvent sre = new ServletRequestEvent(context, request);
srListeners.requestInitialized(sre);
// if (!sraListeners.isEmpty()) {
// if we have at least one request attribute listener, wrap the
// request so we can intercept calls to setAttribute/removeAttribute
request = wrapRequestForServletRequestAttributeListeners(request);
// }
RegularExpressionRequestHandler handler = regexHandler.getRequestHandler();
handler.doFilter(request, response);
}
示例7: testRequest
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Test
public void testRequest() {
DefaultServletEnvironment o = new DefaultServletEnvironment();
assertFalse(o.request().isPresent());
ServletContext mockContext = mock(ServletContext.class);
ServletRequest mockRequest = mock(HttpServletRequest.class);
o.requestInitialized(new ServletRequestEvent(mockContext, mockRequest));
assertSame(mockRequest, o.request().get());
o.requestDestroyed(new ServletRequestEvent(mockContext, mockRequest));
assertFalse(o.request().isPresent());
ServletRequest mockRequest2 = mock(HttpServletRequest.class);
o.requestInitialized(new ServletRequestEvent(mockContext, mockRequest2));
assertSame(mockRequest2, o.request().get());
o.requestDestroyed(new ServletRequestEvent(mockContext, mockRequest2));
assertFalse(o.request().isPresent());
// TODO: test multithreaded scenario..
}
示例8: requestInitialized
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent sre) {
//System.out.println("Requset 初始化了:" + sre.getServletRequest());
ServletContext ctx = sre.getServletContext();
exector.execute(new Runnable() {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
Integer count = (Integer) ctx.getAttribute(BookStoreConstants.REQUEST_COUNT); // 获得list
if (count == null) {
count = 0;
}
ctx.setAttribute(BookStoreConstants.REQUEST_COUNT, count+1);
}
});
}
示例9: requestDestroyed
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestDestroyed(ServletRequestEvent arg0) {
logger.entering("DBInitializer","requestDestroyed");
ServletRequest req = arg0.getServletRequest();
req.removeAttribute(StringConstants.REQUEST_ATTR_USER_DAO);
req.removeAttribute(StringConstants.REQUEST_ATTR_TAG_DAO);
req.removeAttribute(StringConstants.REQUEST_ATTR_SCREEN_DAO );
req.removeAttribute(StringConstants.REQUEST_ATTR_CONTENT_DAO );
req.removeAttribute(StringConstants.REQUEST_ATTR_SETTING_DAO );
req.removeAttribute(StringConstants.REQUEST_ATTR_ENTITY_MANAGER);
EntityManager em = (EntityManager) req.getAttribute(StringConstants.REQUEST_ATTR_ENTITY_MANAGER);
if(em!=null && em.isOpen()){
em.close();
}
req.removeAttribute(StringConstants.REQUEST_ATTR_ENTITY_MANAGER);
logger.exiting("DBInitializer","requestDestroyed");
}
示例10: requestInitialized
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent arg0) {
logger.entering("DBInitializer","requestInitialized");
EntityManager em = DBConfig.getEntityManager();
UserDao userDAO = new UserDao(em);
TagDao tagDAO = new TagDao(em);
ScreenDao screenDAO = new ScreenDao(em);
ContentDao contentDAO = new ContentDao(em);
SettingDao settingDAO = new SettingDao(em);
ServletRequest req = arg0.getServletRequest();
req.setAttribute(StringConstants.REQUEST_ATTR_USER_DAO, userDAO);
req.setAttribute(StringConstants.REQUEST_ATTR_TAG_DAO, tagDAO);
req.setAttribute(StringConstants.REQUEST_ATTR_SCREEN_DAO, screenDAO);
req.setAttribute(StringConstants.REQUEST_ATTR_CONTENT_DAO, contentDAO);
req.setAttribute(StringConstants.REQUEST_ATTR_SETTING_DAO, settingDAO);
req.setAttribute(StringConstants.REQUEST_ATTR_ENTITY_MANAGER, em);
logger.exiting("DBInitializer","requestInitialized");
}
示例11: requestDestroyed
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
public void requestDestroyed(ServletRequestEvent requestEvent) {
ServletRequestAttributes attributes = null;
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
if (reqAttr instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) reqAttr;
}
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
if (threadAttributes != null) {
// We're assumably within the original request thread...
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
if (attributes == null && threadAttributes instanceof ServletRequestAttributes) {
attributes = (ServletRequestAttributes) threadAttributes;
}
}
if (attributes != null) {
attributes.requestCompleted();
}
}
示例12: testRequestContextListenerWithSameThread
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
public void testRequestContextListenerWithSameThread() {
RequestContextListener listener = new RequestContextListener();
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
request.setAttribute("test", "value");
assertNull(RequestContextHolder.getRequestAttributes());
listener.requestInitialized(new ServletRequestEvent(context, request));
assertNotNull(RequestContextHolder.getRequestAttributes());
assertEquals("value",
RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
MockRunnable runnable = new MockRunnable();
RequestContextHolder.getRequestAttributes().registerDestructionCallback(
"test", runnable, RequestAttributes.SCOPE_REQUEST);
listener.requestDestroyed(new ServletRequestEvent(context, request));
assertNull(RequestContextHolder.getRequestAttributes());
assertTrue(runnable.wasExecuted());
}
示例13: testRequestContextListenerWithSameThreadAndAttributesGone
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
public void testRequestContextListenerWithSameThreadAndAttributesGone() {
RequestContextListener listener = new RequestContextListener();
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
request.setAttribute("test", "value");
assertNull(RequestContextHolder.getRequestAttributes());
listener.requestInitialized(new ServletRequestEvent(context, request));
assertNotNull(RequestContextHolder.getRequestAttributes());
assertEquals("value",
RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
MockRunnable runnable = new MockRunnable();
RequestContextHolder.getRequestAttributes().registerDestructionCallback(
"test", runnable, RequestAttributes.SCOPE_REQUEST);
request.clearAttributes();
listener.requestDestroyed(new ServletRequestEvent(context, request));
assertNull(RequestContextHolder.getRequestAttributes());
assertTrue(runnable.wasExecuted());
}
示例14: testGetPage
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
/**
* Test of getPage method, of class fr.paris.lutece.portal.web.search.SearchApp.
*
* @throws SiteMessageException
*/
public void testGetPage( ) throws SiteMessageException
{
System.out.println( "getPage" );
MockHttpServletRequest request = new MockHttpServletRequest( );
request.addParameter( "query", "lutece" );
request.addParameter( "items_per_page", "5" );
RequestContextListener listener = new RequestContextListener( );
ServletContext context = new MockServletContext( );
listener.requestInitialized( new ServletRequestEvent( context, request ) );
int nMode = 0;
Plugin plugin = null;
SearchApp instance = SpringContextService.getBean( "core.xpage.search" );
XPage result = instance.getPage( request, nMode, plugin );
listener.requestDestroyed( new ServletRequestEvent( context, request ) );
}
示例15: service
import javax.servlet.ServletRequestEvent; //导入依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
final ServletRequestEvent sre = new ServletRequestEvent(getServletContext(), req);
this.controller.getRequestListener().requestInitialized(sre);
try
{
req = new AttributeEventRequest(getServletContext(), this.controller.getRequestAttributeListener(), req);
this.controller.getDispatcher().dispatch(req, res, new NotFoundFilterChain());
}
finally
{
this.controller.getRequestListener().requestDestroyed(sre);
}
}