當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。