List of usage examples for org.springframework.web.context WebApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.LexGrid.LexBIG.caCore.web.util.LexEVSHTTPUtils.java
public LexEVSHTTPUtils(ServletContext context) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context); this.classCache = (LexEVSClassCache) ctx.getBean("ClassCache"); this.applicationService = (LexEVSApplicationService) ctx.getBean("ApplicationServiceImpl"); Properties systemProperties = (Properties) ctx.getBean("WebSystemProperties"); try {/*from ww w. j a v a2 s . c o m*/ String rowCounter = systemProperties.getProperty("rowCounter"); log.debug("rowCounter: " + rowCounter); if (rowCounter != null) { this.pageSize = rowCounter; } } catch (Exception ex) { log.error("Exception: ", ex); } }
From source file:com.hgsoft.example.hello.web.HelloServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPost"); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // String[] beanNames = context.getBeanDefinitionNames(); // if(beanNames != null) // {// w ww . j a va 2s. co m // for(String beanName:beanNames) // { // System.out.println("bean name >> "+beanName); // } // } // HelloWorldBusiness helloWorldBusiness = context.getBean("helloWorldBusiness",HelloWorldBusiness.class); // helloWorldBusiness.hello(); // BlueprintContainer container = (BlueprintContainer) getServletContext().getAttribute(BlueprintContextListener.CONTAINER_ATTRIBUTE); // // System.out.println("BlueprintContainer "+container); // // Set<String> componentIds = container.getComponentIds(); // if(componentIds != null) // { // for(String componentId:componentIds) // { // System.out.println("componentId >> "+componentId); // } // } //jndi? HelloWorldService helloWorldService = (HelloWorldService) JNDIHelper.getHelloWorldService(); helloWorldService.hello(); EntityManagerFactory emf = (EntityManagerFactory) context.getBean("entityManagerFactory"); Metamodel model = emf.getMetamodel(); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is the result of test: "); if (null != model) { if (null != model.getEntities()) { for (EntityType type : model.getEntities()) { out.print(type.getName()); } } } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }
From source file:no.kantega.publishing.admin.content.InputScreenRenderer.java
public InputScreenRenderer(PageContext pageContext, Content content, AttributeDataType attributeDataType) { this.pageContext = pageContext; this.content = content; this.attributeType = attributeDataType; WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); contentTemplateAO = context.getBean(ContentTemplateAO.class); }
From source file:no.kantega.publishing.api.taglibs.util.GetUrlTag.java
private void initUrlPlaceholderResolverIfNull() { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); urlPlaceholderResolver = context.getBean(UrlPlaceholderResolver.class); }
From source file:org.alfresco.repo.webdav.auth.HTTPRequestAuthenticationFilter.java
/** * Initialize the filter/*from w ww .jav a2 s . c o m*/ * * @param config * FitlerConfig * @exception ServletException */ public void init(FilterConfig config) throws ServletException { // Save the context m_context = config.getServletContext(); // Setup the authentication context WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(m_context); ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); setNodeService(serviceRegistry.getNodeService()); setAuthenticationService(serviceRegistry.getAuthenticationService()); setTransactionService(serviceRegistry.getTransactionService()); setPersonService((PersonService) ctx.getBean("PersonService")); // transactional and permission-checked m_authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName"); if (httpServletRequestAuthHeaderName == null) { httpServletRequestAuthHeaderName = "x-user"; } this.m_authPatternString = config.getInitParameter("authPatternString"); if (this.m_authPatternString != null) { try { m_authPattern = Pattern.compile(this.m_authPatternString); } catch (PatternSyntaxException e) { logger.warn("Invalid pattern: " + this.m_authPatternString, e); m_authPattern = null; } } }
From source file:org.alfresco.repo.webdav.WebDAVServlet.java
/** * Initialize the servlet/*from w w w . java 2s. com*/ * * @param config ServletConfig * @exception ServletException */ @SuppressWarnings("unchecked") public void init(ServletConfig config) throws ServletException { super.init(config); // Get service registry WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // If no context has been initialised, exit silently so config changes can be made if (context == null) { return; } // Get global configuration properties WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); initParams = (WebDAVInitParameters) wc.getBean(BEAN_INIT_PARAMS); // Render this servlet permanently unavailable if its enablement property is not set if (!initParams.getEnabled()) { logger.info("Marking servlet WebDAV as unavailable!"); return; } // Get root paths String storeValue = initParams.getStoreName(); rootPath = initParams.getRootPath(); // Get beans serviceRegistry = (ServiceRegistry) context.getBean(ServiceRegistry.SERVICE_REGISTRY); transactionService = serviceRegistry.getTransactionService(); tenantService = (TenantService) context.getBean("tenantService"); nodeService = (NodeService) context.getBean("NodeService"); searchService = (SearchService) context.getBean("SearchService"); namespaceService = (NamespaceService) context.getBean("NamespaceService"); ActivityPoster poster = (ActivityPoster) context.getBean("activitiesPoster"); singletonCache = (SimpleCache<String, NodeRef>) context.getBean("immutableSingletonCache"); // Collaborator used by WebDAV methods to create activity posts. activityPoster = new ActivityPosterImpl("WebDAV", poster); // Create the WebDAV helper m_davHelper = (WebDAVHelper) context.getBean("webDAVHelper"); // Initialize the root node initializeRootNode(storeValue, rootPath, context, nodeService, searchService, namespaceService, tenantService, transactionService); // Create the WebDAV methods table m_davMethods = new Hashtable<String, Class<? extends WebDAVMethod>>(); m_davMethods.put(WebDAV.METHOD_PROPFIND, PropFindMethod.class); m_davMethods.put(WebDAV.METHOD_PROPPATCH, PropPatchMethod.class); m_davMethods.put(WebDAV.METHOD_COPY, CopyMethod.class); m_davMethods.put(WebDAV.METHOD_DELETE, DeleteMethod.class); m_davMethods.put(WebDAV.METHOD_GET, GetMethod.class); m_davMethods.put(WebDAV.METHOD_HEAD, HeadMethod.class); m_davMethods.put(WebDAV.METHOD_LOCK, LockMethod.class); m_davMethods.put(WebDAV.METHOD_MKCOL, MkcolMethod.class); m_davMethods.put(WebDAV.METHOD_MOVE, MoveMethod.class); m_davMethods.put(WebDAV.METHOD_OPTIONS, OptionsMethod.class); m_davMethods.put(WebDAV.METHOD_POST, PostMethod.class); m_davMethods.put(WebDAV.METHOD_PUT, PutMethod.class); m_davMethods.put(WebDAV.METHOD_UNLOCK, UnlockMethod.class); }
From source file:org.alfresco.repo.webdav.WebDAVServlet.java
/** * @param storeValue String/*from w w w . j a v a 2 s .c o m*/ * @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(); } }
From source file:org.alfresco.web.app.Application.java
/** * Invalidate Alfresco ticket and Web/Portlet session and clear the Security context for this thread. * @param context// w w w . j av a 2 s .co m */ public static void logOut(FacesContext context) { String ticket = null; if (Application.inPortalServer()) { ticket = AlfrescoFacesPortlet.onLogOut(context.getExternalContext().getRequest()); } else { SessionUser user = getCurrentUser(context); if (user != null) { ticket = user.getTicket(); } HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); HttpSession session = request.getSession(false); if (session != null) { session.invalidate(); } } // Explicitly invalidate the Alfresco ticket. This no longer happens on session expiry to allow for ticket // 'sharing' WebApplicationContext wc = FacesContextUtils.getRequiredWebApplicationContext(context); AuthenticationService unprotAuthService = (AuthenticationService) wc.getBean(BEAN_UNPROTECTED_AUTH_SERVICE); if (ticket != null) { unprotAuthService.invalidateTicket(ticket); } unprotAuthService.clearCurrentSecurityContext(); }
From source file:org.alfresco.web.app.Application.java
/** * Returns the repository store URL//from w w w . j a v a2s . c om * * @param context The spring context * @return The repository store URL to use */ private static StoreRef getRepositoryStoreRef(WebApplicationContext context) { if (repoStoreRef == null) { ImporterBootstrap bootstrap = (ImporterBootstrap) context.getBean(BEAN_IMPORTER_BOOTSTRAP); repoStoreRef = bootstrap.getStoreRef(); } return repoStoreRef; }