Java Code Examples for javax.servlet.ServletContext#setAttribute()
The following examples show how to use
javax.servlet.ServletContext#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelController.java From PedestrianDetectionSystem with Apache License 2.0 | 6 votes |
@RequestMapping(value = "get_channel", method = RequestMethod.GET) public @ResponseBody ModelAndView getChannel(HttpSession session, HttpServletRequest request){ ServletContext context = session.getServletContext(); Integer subFlag = (Integer)request.getSession().getAttribute("sub_flag"); if(subFlag == null){ session.setAttribute("sub_flag", 1); context.setAttribute("onlineCount", (Integer)context.getAttribute("onlineCount") - 1); } Map<String, Object> result = new HashMap(); result.put("msg", "success"); result.put("rst", 0); Integer channel = (Integer) context.getAttribute("use_channel"); if (channel == null){ channel = 0; } result.put("data", channel); return new ModelAndView(new MappingJackson2JsonView(), result); }
Example 2
Source File: TomcatPlusIT.java From uavstack with Apache License 2.0 | 6 votes |
/** * * onServletRegist * * @param args * @return */ public ServletContext onServletRegist(Object... args) { ServletContext servletContext = (ServletContext) args[0]; //uav's inner app doesn't need Profiling,just return origin servletContext here. if("/com.creditease.uav".equals(servletContext.getContextPath())) { return servletContext; } ServletContext scProxy = (ServletContext) servletContext .getAttribute("com.creditease.uav.mof.tomcat.servletcontext"); if (scProxy == null) { scProxy = JDKProxyInvokeUtil.newProxyInstance(ServletContext.class.getClassLoader(), new Class<?>[] { ServletContext.class }, new JDKProxyInvokeHandler<ServletContext>(servletContext, new DynamicServletContextProcessor())); servletContext.setAttribute("com.creditease.uav.mof.tomcat.servletcontext", scProxy); } return scProxy; }
Example 3
Source File: ScriptingServlet.java From document-management-system with GNU General Public License v2.0 | 6 votes |
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); updateSessionManager(request); try { String genCsrft = SecureStore.md5Encode(UUID.randomUUID().toString().getBytes()); request.getSession().setAttribute("csrft", genCsrft); ServletContext sc = getServletContext(); sc.setAttribute("script", null); sc.setAttribute("csrft", genCsrft); sc.setAttribute("scriptResult", null); sc.setAttribute("scriptError", null); sc.setAttribute("scriptOutput", null); sc.setAttribute("time", null); sc.getRequestDispatcher("/admin/scripting.jsp").forward(request, response); } catch (Exception e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
Example 4
Source File: OmrServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * edit type record */ private void edit(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, ParseException, AccessDeniedException, RepositoryException { log.debug("edit({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); long omId = WebUtils.getLong(request, "om_id"); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("om", OmrDAO.getInstance().findByPk(omId)); sc.setAttribute("pgprops", PropertyGroupUtils.getAllGroupsProperties()); sc.getRequestDispatcher("/admin/omr_edit.jsp").forward(request, response); log.debug("edit: void"); }
Example 5
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyNotInjectedWithRootPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); sc.setAttribute("another", wac); StaticWebApplicationContext wacToUse = new StaticWebApplicationContext(); wacToUse.setServletContext(sc); String beanName = "targetFilter"; wacToUse.registerSingleton(beanName, MockFilter.class); wacToUse.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wacToUse); MockFilter targetFilter = (MockFilter) wacToUse.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName); filterProxy.setServletContext(sc); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 6
Source File: PluginServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * Plugin list */ @SuppressWarnings("unchecked") private void pluginList(HttpServletRequest request, HttpServletResponse response, String pluginSelected) throws ServletException, IOException, DatabaseException, URISyntaxException { log.debug("pluginList({})", pluginSelected); ServletContext sc = getServletContext(); List<Plugin> pluginsLoaded; List<Plugin> plugins; if (null == pluginSelected || pluginSelected.isEmpty()) { pluginSelected = Action.class.getCanonicalName(); } if (Validation.class.getCanonicalName().equalsIgnoreCase(pluginSelected)) { plugins = (List<Plugin>) (List<?>) PluginUtils.getAllPlugins(new URI(AutomationDAO.PLUGIN_URI), Validation.class); pluginsLoaded = (List<Plugin>) (List<?>) AutomationDAO.getInstance().findValidations(false); Collections.sort(plugins, OrderByClassName.getInstance()); } else { plugins = (List<Plugin>) (List<?>) PluginUtils.getAllPlugins(new URI(AutomationDAO.PLUGIN_URI), Action.class); pluginsLoaded = (List<Plugin>) (List<?>) AutomationDAO.getInstance().findActions(false); Collections.sort(plugins, OrderByClassName.getInstance()); } List<LoadedPlugin> loadedPlugins = calculateLoadedPlugins(plugins, pluginsLoaded); sc.setAttribute("showReloadButton", showReloadButton(loadedPlugins)); sc.setAttribute("plugins", loadedPlugins); sc.setAttribute("pluginStatus", PluginDAO.getInstance().findAll()); sc.setAttribute("pluginList", pluginList); sc.setAttribute("pluginSelected", pluginSelected); sc.getRequestDispatcher("/admin/plugin_list.jsp").forward(request, response); log.debug("registeredList: void"); }
Example 7
Source File: LoggedUsersServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
public void messageList(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = getServletContext(); sc.setAttribute("messages", UINotificationServlet.getAll()); sc.getRequestDispatcher("/admin/message_list.jsp").forward(request, response); // Activity log UserActivity.log(userId, "ADMIN_GET_MESSAGES", null, null, null); }
Example 8
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxyWithLazyContextStartup() throws ServletException, IOException { ServletContext sc = new MockServletContext(); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 9
Source File: CssServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * Create CSS */ private void create(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("create({}, {}, {})", new Object[]{userId, request, response}); ServletContext sc = getServletContext(); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("css", null); sc.getRequestDispatcher("/admin/css_edit.jsp").forward(request, response); log.debug("create: void"); }
Example 10
Source File: MqConsumerController.java From RocketMqCurrencyBoot with Apache License 2.0 | 5 votes |
/** * * 开启一个 消费端 * 该方法会创建一个 消费端类 ,该类 将添加到servletContext 进行管理 * 重要提示 每次调用改方法都会 开启一个新的消费端 * * @param Topic Topic * @param Tags Tag 标签可以 定 未获取多个 具体请看MQ 文档 * @return 是否成功开启 */ @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Void> startMqConsumerTag(@RequestParam("Topic") String Topic, @RequestParam("Tags") String Tags) { MqConsumer consumer; String clientID; try { consumer = (MqConsumer) SpringContextUtils.getBeanByClass(MqConsumer.class); if (Tags == null || "".equals(Tags)) Tags = "*"; clientID = consumer.init(Topic, Tags); } catch (Exception e) { LOGGER.error("MqConsumerController 启动消费端异常 ", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } ServletContext servletContext = request.getServletContext(); if (servletContext.getAttribute(clientID) == null) { servletContext.setAttribute(clientID, consumer); } return ResponseEntity.status(HttpStatus.OK).build(); }
Example 11
Source File: TestPlatform.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void onStartup(Runnable startupHook) { startupHook.run(); KeycloakApplication keycloakApplication = Resteasy.getContextData(KeycloakApplication.class); ServletContext context = Resteasy.getContextData(ServletContext.class); context.setAttribute(KeycloakSessionFactory.class.getName(), keycloakApplication.getSessionFactory()); }
Example 12
Source File: InterfaceSController.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ServletContext context = servletConfig.getServletContext(); String controllerClassName = context.getInitParameter("InterfaceS_Service"); try { Class controllerClass = Class.forName(controllerClassName); _controller = (InterfaceS_Service) controllerClass.newInstance(); context.setAttribute("controller", _controller); } catch (Exception e) { e.printStackTrace(); } }
Example 13
Source File: CheckEmailServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * Send email */ private void send(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("send({}, {})", request, response); String from = WebUtils.getString(request, "from"); String to = WebUtils.getString(request, "to"); String subject = WebUtils.getString(request, "subject"); String content = WebUtils.getString(request, "content"); ServletContext sc = getServletContext(); sc.setAttribute("from", from); sc.setAttribute("to", to); sc.setAttribute("subject", subject); sc.setAttribute("content", content); try { MailUtils.sendMessage(from, to, subject, content); sc.setAttribute("error", null); sc.setAttribute("success", "Ok"); } catch (Exception e) { sc.setAttribute("success", null); sc.setAttribute("error", e.getMessage()); } sc.getRequestDispatcher("/admin/check_email.jsp").forward(request, response); // Activity log UserActivity.log(request.getRemoteUser(), "ADMIN_CHECK_EMAIL", null, null, from + ", " + to + ", " + subject + ", " + content); log.debug("view: void"); }
Example 14
Source File: CheckTextExtractionServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); updateSessionManager(request); ServletContext sc = getServletContext(); sc.setAttribute("repoPath", "/" + Repository.ROOT); sc.setAttribute("docUuid", null); sc.setAttribute("text", null); sc.setAttribute("time", null); sc.setAttribute("mimeType", null); sc.setAttribute("extractor", null); sc.getRequestDispatcher("/admin/check_text_extraction.jsp").forward(request, response); }
Example 15
Source File: BookServiceBootstrap.java From everrest with Eclipse Public License 2.0 | 4 votes |
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); servletContext.setAttribute(BOOK_STORAGE_NAME, new BookStorage()); }
Example 16
Source File: AsyncStockContextListener.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void contextInitialized(ServletContextEvent sce) { Stockticker stockticker = new Stockticker(); ServletContext sc = sce.getServletContext(); sc.setAttribute(STOCK_TICKER_KEY, stockticker); }
Example 17
Source File: KeycloakConfigurationServletListener.java From keycloak with Apache License 2.0 | 4 votes |
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); String configResolverClass = servletContext.getInitParameter("keycloak.config.resolver"); SamlDeploymentContext deploymentContext = (SamlDeploymentContext) servletContext.getAttribute(SamlDeployment.class.getName()); if (deploymentContext == null) { if (configResolverClass != null) { try { SamlConfigResolver configResolver = (SamlConfigResolver) servletContext.getClassLoader().loadClass(configResolverClass).newInstance(); deploymentContext = new SamlDeploymentContext(configResolver); log.infov("Using {0} to resolve Keycloak configuration on a per-request basis.", configResolverClass); } catch (Exception ex) { log.errorv("The specified resolver {0} could NOT be loaded. Keycloak is unconfigured and will deny all requests. Reason: {1}", new Object[] { configResolverClass, ex.getMessage() }); deploymentContext = new SamlDeploymentContext(new DefaultSamlDeployment()); } } else { InputStream is = getConfigInputStream(servletContext); final SamlDeployment deployment; if (is == null) { log.warn("No adapter configuration. Keycloak is unconfigured and will deny all requests."); deployment = new DefaultSamlDeployment(); } else { try { ResourceLoader loader = new ResourceLoader() { @Override public InputStream getResourceAsStream(String resource) { return servletContext.getResourceAsStream(resource); } }; deployment = new DeploymentBuilder().build(is, loader); } catch (ParsingException e) { throw new RuntimeException(e); } } deploymentContext = new SamlDeploymentContext(deployment); log.debug("Keycloak is using a per-deployment configuration."); } } addTokenStoreUpdaters(servletContext); servletContext.setAttribute(ADAPTER_DEPLOYMENT_CONTEXT_ATTRIBUTE, deploymentContext); servletContext.setAttribute(ADAPTER_DEPLOYMENT_CONTEXT_ATTRIBUTE_ELYTRON, deploymentContext); servletContext.setAttribute(ADAPTER_SESSION_ID_MAPPER_ATTRIBUTE_ELYTRON, idMapper); servletContext.setAttribute(ADAPTER_SESSION_ID_MAPPER_UPDATER_ATTRIBUTE_ELYTRON, idMapperUpdater); }
Example 18
Source File: SpiracleInit.java From spiracle with Apache License 2.0 | 4 votes |
private void setDefaultConnection(ServletContext application, Properties props) { String defaultConnection = (String) props.get(Constants.DEFAULT_CONNECTION); application.setAttribute(Constants.DEFAULT_CONNECTION, defaultConnection); }
Example 19
Source File: ApplicationLifecycleListener.java From aliada-tool with GNU General Public License v3.0 | 3 votes |
/** * Override the ServletContextListener.contextInitializedReceives method. * It is called when the web application initialization process is starting. * This function gets the DDBB connection and saves it in a * Servlet context attribute. * * @param the ServletContextEvent containing the ServletContext * that is being initialized. * @since 2.0 */ @Override public void contextInitialized(final ServletContextEvent event) { LOGGER.info(MessageCatalog._00001_STARTING); final ServletContext servletC = event.getServletContext(); //Get DDBB connection final DBConnectionManager dbConn = new DBConnectionManager(); //Save DDBB connection in Servlet Context attribute servletC.setAttribute("db", dbConn); }
Example 20
Source File: ApplicationLifecycleListener.java From aliada-tool with GNU General Public License v3.0 | 3 votes |
/** * Override the ServletContextListener.contextInitializedReceives method. * It is called when the web application initialization process is starting. * This function gets the DDBB connection and saves it in a * Servlet context attribute. * * @param the ServletContextEvent containing the ServletContext * that is being initialized. * @since 1.0 */ @Override public void contextInitialized(final ServletContextEvent event) { LOGGER.info(MessageCatalog._00001_STARTING); final ServletContext servletC = event.getServletContext(); //Get DDBB connection final DBConnectionManager dbConn = new DBConnectionManager(); //Save DDBB connection in Servlet Context attribute servletC.setAttribute("db", dbConn); }