List of usage examples for javax.servlet ServletRequestEvent getServletRequest
public ServletRequest getServletRequest()
From source file:org.mayocat.context.RequestContextInitializer.java
private URI getBaseURI(ServletRequestEvent event) { HttpServletRequest request = (HttpServletRequest) event.getServletRequest(); if ((request.getServerPort() == 80) || (request.getServerPort() == 443)) { return URI .create(request.getScheme() + "://" + request.getServerName() + request.getContextPath() + '/'); } else {// w ww . j ava 2s . c om return URI.create(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + '/'); } }
From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java
public void requestInitialized(ServletRequestEvent event) { checkInit(event);//from w w w. j av a 2 s . co m if (adapters != null) { BehaviorEvent[] events = new BehaviorEvent[adapters.length]; ServletRequest request = event.getServletRequest(); request.setAttribute(ATT_EVENTS, events); for (int i = 0; i < adapters.length; ++i) try { events[i] = adapters[i].start(request); } catch (Exception e) { log.error("Error starting http event", e); } } }
From source file:io.mapzone.arena.tracker.GoogleAnalyticsTracker.java
private void extractParams(List<NameValuePair> params, ServletRequestEvent event) { params.add(new BasicNameValuePair("t", "event")); params.add(new BasicNameValuePair("ec", "externalRequest")); HttpServletRequest request = (HttpServletRequest) event.getServletRequest(); if (request != null) { try {/* w w w. j ava 2 s .c om*/ // TODO, add user or session or something else here authToken String clientId = "anonymous"; String authToken = request.getParameter("authToken"); if (!StringUtils.isBlank(authToken)) { clientId = authToken; } addEncoded(params, "cid", clientId); // request.get String context = request.getServletPath(); int index = context.lastIndexOf("/"); if (index != -1) { context = context.substring(index + 1); } addEncoded(params, "ea", context); if (!StringUtils.isBlank(request.getContentType())) { index = request.getContentType().toLowerCase().lastIndexOf("charset="); if (index != -1) { addEncoded(params, "de", request.getContentType().substring(index + 8)); } } addEncoded(params, "dl", request.getServletPath() + "?" + request.getQueryString()); addEncoded(params, "el", request.getQueryString()); addEncoded(params, "dr", request.getHeader("Referer")); addEncoded(params, "ua", request.getHeader("User-Agent")); addEncoded(params, "uip", request.getRemoteAddr()); } catch (UnsupportedEncodingException e) { // do nothing log.error(e); } } }
From source file:org.b3log.solo.SoloServletListener.java
@Override public void requestInitialized(final ServletRequestEvent servletRequestEvent) { final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest(); final String requestURI = httpServletRequest.getRequestURI(); Stopwatchs.start("Request Initialized[requestURI=" + requestURI + "]"); if (Requests.searchEngineBotRequest(httpServletRequest)) { LOGGER.log(Level.FINER, "Request made from a search engine[User-Agent={0}]", httpServletRequest.getHeader("User-Agent")); httpServletRequest.setAttribute(Keys.HttpRequest.IS_SEARCH_ENGINE_BOT, true); } else {/*from w w w .j a v a2 s .c o m*/ // Gets the session of this request final HttpSession session = httpServletRequest.getSession(); LOGGER.log(Level.FINE, "Gets a session[id={0}, remoteAddr={1}, User-Agent={2}, isNew={3}]", new Object[] { session.getId(), httpServletRequest.getRemoteAddr(), httpServletRequest.getHeader("User-Agent"), session.isNew() }); // Online visitor count Statistics.onlineVisitorCount(httpServletRequest); } resolveSkinDir(httpServletRequest); }
From source file:org.brutusin.rpc.RpcWebInitializer.java
public void onStartup(final ServletContext ctx) throws ServletException { final RpcServlet rpcServlet = registerRpcServlet(ctx); final WebsocketFilter websocketFilter = new WebsocketFilter(); FilterRegistration.Dynamic dynamic = ctx.addFilter(WebsocketFilter.class.getName(), websocketFilter); dynamic.addMappingForUrlPatterns(null, false, RpcConfig.getInstance().getPath() + "/wskt"); JsonCodec.getInstance().registerStringFormat(MetaDataInputStream.class, "inputstream"); final Bean<RpcSpringContext> rpcCtxBean = new Bean<RpcSpringContext>(); ctx.addListener(new ServletRequestListener() { public void requestDestroyed(ServletRequestEvent sre) { GlobalThreadLocal.clear();/*from w ww . j a va 2 s .c om*/ } public void requestInitialized(ServletRequestEvent sre) { GlobalThreadLocal.set(new GlobalThreadLocal((HttpServletRequest) sre.getServletRequest(), null)); } }); ctx.addListener(new ServletContextListener() { public void contextInitialized(ServletContextEvent sce) { RpcSpringContext rpcCtx = createRpcSpringContext(ctx); rpcCtxBean.setValue(rpcCtx); rpcServlet.setRpcCtx(rpcCtx); initWebsocketRpcRuntime(ctx, rpcCtx); ctx.setAttribute(RpcSpringContext.class.getName(), rpcCtx); } public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying RPC context"); if (rpcCtxBean.getValue() != null) { rpcCtxBean.getValue().destroy(); } } }); ctx.addListener(new ServletContextAttributeListener() { public void attributeAdded(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } public void attributeRemoved(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } public void attributeReplaced(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } private void updateRootContext() { WebApplicationContext rootCtx = WebApplicationContextUtils.getWebApplicationContext(ctx); if (rootCtx != null) { if (rpcCtxBean.getValue() != null) { rpcCtxBean.getValue().setParent(rootCtx); } if (rootCtx.containsBean("springSecurityFilterChain")) { LOGGER.info("Moving WebsocketFilter behind springSecurityFilterChain"); websocketFilter.disable(); FilterChainProxy fcp = (FilterChainProxy) rootCtx.getBean("springSecurityFilterChain"); fcp.getFilterChains().get(0).getFilters().add(new WebsocketFilter()); } } } }); }
From source file:org.hdiv.listener.InitListener.java
/** * End request associated objects.//from w w w . j a v a 2 s. co m * * @param sre * request destroyed event */ public void requestDestroyed(ServletRequestEvent sre) { HttpServletRequest request = (HttpServletRequest) sre.getServletRequest(); // End page in datacomposer boolean exist = HDIVUtil.isDataComposer(request); if (exist) { IDataComposer dataComposer = HDIVUtil.getDataComposer(request); dataComposer.endPage(); } // Erase request from threadlocal HDIVUtil.resetLocalData(); }
From source file:org.hdiv.listener.InitListener.java
/** * Initialize request associated objects. * //from w w w.j ava 2 s . c o m * @param sre * request created event */ public void requestInitialized(ServletRequestEvent sre) { HttpServletRequest request = (HttpServletRequest) sre.getServletRequest(); if (!this.servletContextInitialized) { ServletContext servletContext = request.getSession().getServletContext(); this.initServletContext(servletContext); } // Put the request in threadlocal HDIVUtil.setHttpServletRequest(request); // Store request original request uri HDIVUtil.setRequestURI(request.getRequestURI(), request); //Don`t create IDataComposer if it is not necessary boolean exclude = this.config.hasExtensionToExclude(request.getRequestURI()); if (!exclude) { // Init datacomposer IDataComposer dataComposer = this.dataComposerFactory.newInstance(); this.initDataComposer(dataComposer, request); HDIVUtil.setDataComposer(dataComposer, request); } }
From source file:org.b3log.symphony.SymphonyServletListener.java
@Override public void requestInitialized(final ServletRequestEvent servletRequestEvent) { final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest(); httpServletRequest.setAttribute(Keys.TEMAPLTE_DIR_NAME, Symphonys.get("skinDirName")); if (Requests.searchEngineBotRequest(httpServletRequest)) { LOGGER.log(Level.DEBUG, "Request made from a search engine[User-Agent={0}]", httpServletRequest.getHeader("User-Agent")); httpServletRequest.setAttribute(Keys.HttpRequest.IS_SEARCH_ENGINE_BOT, true); return;/*from w w w.j a va 2 s . co m*/ } httpServletRequest.setAttribute(Keys.HttpRequest.IS_SEARCH_ENGINE_BOT, false); if (StaticResources.isStatic(httpServletRequest)) { return; } // Gets the session of this request final HttpSession session = httpServletRequest.getSession(); LOGGER.log(Level.TRACE, "Gets a session[id={0}, remoteAddr={1}, User-Agent={2}, isNew={3}]", new Object[] { session.getId(), httpServletRequest.getRemoteAddr(), httpServletRequest.getHeader("User-Agent"), session.isNew() }); resolveSkinDir(httpServletRequest); }
From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java
@Override public void requestDestroyed(ServletRequestEvent sre) { requestTimes.remove(sre.getServletRequest()); if (isEventInterceptorActivated("interceptServletRequestListenerEvents")) { SpringContextSingleton.getInstance() .publishEvent(new ServletRequestDestroyedEvent(sre.getServletRequest())); }//from www.j a va 2s . c om }
From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java
@Override public void requestInitialized(ServletRequestEvent sre) { ServletRequest servletRequest = sre.getServletRequest(); if (servletRequest instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) servletRequest; if (HTTP_METHOD.matcher(req.getMethod().toUpperCase()).matches() && !StringUtils.contains(req.getQueryString(), "X-Atmosphere-Transport=")) { requestTimes.put(servletRequest, System.currentTimeMillis()); }/*from w ww.j av a 2 s .c o m*/ } if (isEventInterceptorActivated("interceptServletRequestListenerEvents")) { SpringContextSingleton.getInstance().publishEvent(new ServletRequestInitializedEvent(servletRequest)); } }