Java Code Examples for org.springframework.web.context.WebApplicationContext#getBean()
The following examples show how to use
org.springframework.web.context.WebApplicationContext#getBean() .
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: TemporaryGroupIndexSessionCleaner.java From archiva with Apache License 2.0 | 6 votes |
@Override public void sessionCreated( HttpSessionEvent httpSessionEvent ) { // ensure the map is here to avoid NPE if ( httpSessionEvent.getSession().getAttribute( TEMPORARY_INDEX_SESSION_KEY ) == null ) { httpSessionEvent.getSession().setAttribute( TEMPORARY_INDEX_SESSION_KEY, new HashMap<>() ); } if ( indexMerger == null ) { WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext( httpSessionEvent.getSession().getServletContext() ); indexMerger = webApplicationContext.getBean( IndexMerger.class ); } }
Example 2
Source File: ReasonableSakaiServlet.java From sakai with Educational Community License v2.0 | 6 votes |
public void init(ServletConfig config) { try { super.init(config); ServletContext context = getServletContext(); Logger.log.info("ReasonableSakaiServlet starting up for context " + context.getRealPath("")); WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(context); if (wac == null) { throw new IllegalStateException( "Error acquiring web application context " + "- servlet context not configured correctly"); } rsacbl = (RSACBeanLocator) wac.getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME); } catch (Throwable t) { Logger.log.warn("Error initialising SakaiRSF servlet: ", t); } }
Example 3
Source File: RedirectView.java From java-technology-stack with MIT License | 6 votes |
/** * Find the registered {@link RequestDataValueProcessor}, if any, and allow * it to update the redirect target URL. * @param targetUrl the given redirect URL * @return the updated URL or the same as URL as the one passed in */ protected String updateTargetUrl(String targetUrl, Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { WebApplicationContext wac = getWebApplicationContext(); if (wac == null) { wac = RequestContextUtils.findWebApplicationContext(request, getServletContext()); } if (wac != null && wac.containsBean(RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) { RequestDataValueProcessor processor = wac.getBean( RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class); return processor.processUrl(request, targetUrl); } return targetUrl; }
Example 4
Source File: DispatchController.java From TrackRay with GNU General Public License v3.0 | 6 votes |
@Deprecated public void attack(Task task, ExecutorService exec) { WebApplicationContext context = getAppContext(); Map<String, AbstractPOC> beans = context.getBeansOfType(AbstractPOC.class); AbstractPlugin simpleVul = (AbstractPlugin) context.getBean("simpleVulRule"); SysLog.info("开始漏洞检测"); for (String targeturl : task.getTargets()) { simpleVul.setParam(new HashMap<String,Object>(){{put("target",targeturl);put("task",task);}}); exec.submit(simpleVul); for (Map.Entry<String, AbstractPOC> entry : beans.entrySet()) { AbstractPOC exp = entry.getValue(); exp.setTask(task); exp.setTarget(targeturl); String bean = entry.getKey(); SysLog.info(bean+" exploit executeing..."); exec.execute(exp); } } }
Example 5
Source File: PortletApplicationContextScopeTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testSessionScope() { WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_SESSION); MockRenderRequest request = new MockRenderRequest(); PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); try { assertNull(request.getPortletSession().getAttribute(NAME)); DerivedTestBean bean = ac.getBean(NAME, DerivedTestBean.class); assertSame(bean, request.getPortletSession().getAttribute(NAME)); assertSame(bean, ac.getBean(NAME)); request.getPortletSession().invalidate(); assertTrue(bean.wasDestroyed()); } finally { RequestContextHolder.setRequestAttributes(null); } }
Example 6
Source File: OpenEntityManagerInViewFilter.java From java-technology-stack with MIT License | 6 votes |
/** * Look up the EntityManagerFactory that this filter should use. * <p>The default implementation looks for a bean with the specified name * in Spring's root application context. * @return the EntityManagerFactory to use * @see #getEntityManagerFactoryBeanName */ protected EntityManagerFactory lookupEntityManagerFactory() { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); String emfBeanName = getEntityManagerFactoryBeanName(); String puName = getPersistenceUnitName(); if (StringUtils.hasLength(emfBeanName)) { return wac.getBean(emfBeanName, EntityManagerFactory.class); } else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) { return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class); } else { // Includes fallback search for single EntityManagerFactory bean by type. return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName); } }
Example 7
Source File: OpenSessionInViewFilter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Look up the SessionFactory that this filter should use. * <p>The default implementation looks for a bean with the specified name * in Spring's root application context. * @return the SessionFactory to use * @see #getSessionFactoryBeanName */ protected SessionFactory lookupSessionFactory() { if (logger.isDebugEnabled()) { logger.debug("Using SessionFactory '" + getSessionFactoryBeanName() + "' for OpenSessionInViewFilter"); } WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); return wac.getBean(getSessionFactoryBeanName(), SessionFactory.class); }
Example 8
Source File: ConfigServlet.java From diamond with Apache License 2.0 | 5 votes |
@Override public void init() throws ServletException { super.init(); WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); configService = (ConfigService) webApplicationContext.getBean("configService"); this.diskService = (DiskService) webApplicationContext.getBean("diskService"); configController = new ConfigController(); this.configController.setConfigService(configService); this.configController.setDiskService(diskService); }
Example 9
Source File: ConfigPropertiesExposerListener.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent sce) { // TODO add ability to configure non default values via serveltContexParams ServletContext servletContext = sce.getServletContext(); WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); ExposablePropertyPlaceholderConfigurer configurer = (ExposablePropertyPlaceholderConfigurer) context.getBean(propertiesBeanName); sce.getServletContext().setAttribute(contextProperty, configurer.getResolvedProps()); }
Example 10
Source File: AlfrescoX509ServletFilter.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected boolean checkEnforce(ServletContext servletContext) throws IOException { /* * Get the secureComms setting from the global properties bean. */ WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); Properties globalProperties = (Properties) wc.getBean(BEAN_GLOBAL_PROPERTIES); String prop = globalProperties.getProperty(SECURE_COMMS); if(logger.isDebugEnabled()) { logger.debug("secureComms:"+prop); } /* * Return true or false based on the property. This will switch on/off X509 enforcement in the X509ServletFilterBase. */ if (prop == null || "none".equals(prop)) { return false; } else { return true; } }
Example 11
Source File: CacheAdminServlet.java From smart-cache with Apache License 2.0 | 4 votes |
protected String process(String url, HttpServletRequest request) { Map<String, String> parameters = getParameters(url); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext()); CacheTemplate cacheTemplate = context.getBean(CacheTemplate.class); String name = parameters.get("name"); String key = parameters.get("key"); url = Strings.subString(url, null, ".json"); if (url.equals("/get")) { if ((null != name && name.length() > 0) && (null != key && key.length() > 0)) { return returnJSONResultSuccess(RESULT_CODE_SUCCESS, cacheTemplate.get(name, key)); } } // else if (url.equals("/del")) { if ((null != name && name.length() > 0) && (null != key && key.length() > 0)) { cacheTemplate.del(name, key); return returnJSONResultSuccess(RESULT_CODE_SUCCESS, null); } } // else if (url.equals("/rem")) { if (null != name && name.length() > 0) { cacheTemplate.rem(name); return returnJSONResultSuccess(RESULT_CODE_SUCCESS, null); } } // else if (url.equals("/names")) { return returnJSONResultSuccess(RESULT_CODE_SUCCESS, cacheTemplate.names()); } // else if (url.equals("/keys")) { if (null != name && name.length() > 0) { return returnJSONResultSuccess(RESULT_CODE_SUCCESS, cacheTemplate.getKeysData(name)); } } // else if (url.equals("/fetch")) { if ((null != name && name.length() > 0) && (null != key && key.length() > 0)) { return returnJSONResultSuccess(RESULT_CODE_SUCCESS, cacheTemplate.fetch(name, key)); } } // else if (url.equals("/cls")) { cacheTemplate.cls(); return returnJSONResultSuccess(RESULT_CODE_SUCCESS, null); } // return returnJSONResultFailure(RESULT_CODE_FALIURE, "Do not support this request, please contact with administrator."); }
Example 12
Source File: PolitenessOptions.java From webcurator with Apache License 2.0 | 4 votes |
public static PolitenessOptions getAggressivePolitenessOptions() { WebApplicationContext ctx = ApplicationContextFactory.getWebApplicationContext(); return (PolitenessOptions) ctx.getBean("aggressivePolitenessOptions"); }
Example 13
Source File: GwtRpcServlet.java From unitime with Apache License 2.0 | 4 votes |
protected PermissionCheck getPermissionCheck() { WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); return (PermissionCheck)applicationContext.getBean("unitimePermissionCheck"); }
Example 14
Source File: SpringBeanPreparerFactory.java From lams with GNU General Public License v2.0 | 4 votes |
@Override protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException { return context.getBean(name, ViewPreparer.class); }
Example 15
Source File: ToolDownload.java From lams with GNU General Public License v2.0 | 4 votes |
protected IToolContentFullHandler getToolContentHandler(String toolContentHandlerName) { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); return (IToolContentFullHandler) wac.getBean(toolContentHandlerName); }
Example 16
Source File: HttpRequestHandlerServlet.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void init() throws ServletException { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); this.target = wac.getBean(getServletName(), HttpRequestHandler.class); }
Example 17
Source File: WebDAVServlet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param storeValue String * @param rootPath String * @param context WebApplicationContext * @param nodeService NodeService * @param searchService SearchService * @param namespaceService NamespaceService * @param tenantService TenantService * @param m_transactionService TransactionService */ private void initializeRootNode(String storeValue, String rootPath, WebApplicationContext context, NodeService nodeService, SearchService searchService, NamespaceService namespaceService, TenantService tenantService, TransactionService m_transactionService) { // Use the system user as the authenticated context for the filesystem initialization AuthenticationContext authComponent = (AuthenticationContext) context.getBean("authenticationContext"); authComponent.setSystemUserAsCurrentUser(); // Wrap the initialization in a transaction UserTransaction tx = m_transactionService.getUserTransaction(true); try { // Start the transaction if (tx != null) tx.begin(); StoreRef storeRef = new StoreRef(storeValue); if (nodeService.exists(storeRef) == false) { throw new RuntimeException("No store for path: " + storeRef); } NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false); if (nodeRefs.size() > 1) { throw new RuntimeException("Multiple possible children for : \n" + " path: " + rootPath + "\n" + " results: " + nodeRefs); } else if (nodeRefs.size() == 0) { throw new RuntimeException("Node is not found for : \n" + " root path: " + rootPath); } defaultRootNode = nodeRefs.get(0); // Commit the transaction if (tx != null) tx.commit(); } catch (Exception ex) { logger.error(ex); } finally { // Clear the current system user authComponent.clearCurrentSecurityContext(); } }
Example 18
Source File: PolitenessOptions.java From webcurator with Apache License 2.0 | 4 votes |
public static PolitenessOptions getPolitePolitenessOptions() { WebApplicationContext ctx = ApplicationContextFactory.getWebApplicationContext(); return (PolitenessOptions) ctx.getBean("politePolitenessOptions"); }
Example 19
Source File: DbListener.java From cosmo with Apache License 2.0 | 4 votes |
private <T> T beanForName(String beanName, WebApplicationContext wac, Class<T> clazz) { return (T) wac.getBean(beanName, clazz); }
Example 20
Source File: ApsWebApplicationUtils.java From entando-core with GNU Lesser General Public License v3.0 | 2 votes |
/** * Restituisce un bean di sistema. * Il seguente metodo è in uso ai tag jsp del sistema. * @param beanName Il nome del servizio richiesto. * @param request La request. * @return Il servizio richiesto. */ public static Object getBean(String beanName, HttpServletRequest request) { WebApplicationContext wac = getWebApplicationContext(request); return wac.getBean(beanName); }