当前位置: 首页>>代码示例>>Java>>正文


Java ServletRequestEvent类代码示例

本文整理汇总了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();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:RequestContextListener.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:RequestContextListenerTests.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:RequestContextListenerTests.java

示例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) {
    }
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:17,代码来源:ServletRequestListener.java

示例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);
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:17,代码来源:WebApplicationListener.java

示例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);
}
 
开发者ID:bboypscmylife,项目名称:opengse,代码行数:19,代码来源:WebAppImpl.java

示例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..
}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:24,代码来源:DefaultServletEnvironmentTest.java

示例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);
			
		}
	});
	

}
 
开发者ID:shihuihzh,项目名称:BookStore,代码行数:21,代码来源:StoreRequestListener.java

示例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");
}
 
开发者ID:iss-deweloper,项目名称:iss,代码行数:21,代码来源:DBInitializer.java

示例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");
}
 
开发者ID:iss-deweloper,项目名称:iss,代码行数:20,代码来源:DBInitializer.java

示例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();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:RequestContextListener.java

示例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());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:RequestContextListenerTests.java

示例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());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:RequestContextListenerTests.java

示例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 ) );
}
 
开发者ID:lutece-platform,项目名称:lutece-core,代码行数:26,代码来源:SearchAppTest.java

示例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);
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:17,代码来源:DispatcherServlet.java


注:本文中的javax.servlet.ServletRequestEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。