List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:org.sakaiproject.roster.tool.RosterTool.java
public void init(ServletConfig config) throws ServletException { super.init(config); try {/*from ww w. j a v a2 s. c o m*/ ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); sakaiProxy = (SakaiProxy) context.getBean("org.sakaiproject.roster.api.SakaiProxy"); } catch (Throwable t) { throw new ServletException("Failed to initialise RosterTool servlet.", t); } }
From source file:org.sakaiproject.search.tool.ControllerServlet.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (wac == null) { wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); if (wac == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Cannot get WebApplicationContext"); return; }//from www .j a va 2s . c o m } request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); if (searchBeanFactory == null) { searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory"); ServletContext context = getServletContext(); searchBeanFactory.setContext(context); } if (sessionManager == null) { sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName()); } addLocalHeaders(request); String targetURL = persistState(request); if (targetURL != null && targetURL.trim().length() > 0) { response.sendRedirect(targetURL); return; } if (TITLE_PANEL.equals(request.getParameter(PANEL))) { String targetPage = "/WEB-INF/pages/title.jsp"; RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } else { String path = request.getPathInfo(); if (path == null || path.length() == 0) { path = "/index"; } if (!path.startsWith("/")) { path = "/" + path; } String targetPage = "/WEB-INF/pages" + path + ".jsp"; request.setAttribute(SearchBeanFactory.SEARCH_BEAN_FACTORY_ATTR, searchBeanFactory); RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } request.removeAttribute(Tool.NATIVE_URL); }
From source file:org.sakaiproject.tool.assessment.ui.servlet.StoreApplicationContext.java
public void init(ServletConfig config) throws ServletException { super.init(config); if (ctx == null) { ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext()); //log.log("***context="+ctx); SpringBeanLocator.setApplicationContext(ctx); ContextUtil.setServletContext(config.getServletContext()); }/*from ww w .j a v a 2 s . c o m*/ }
From source file:org.sipfoundry.sipxconfig.cmcprov.ProvisioningServlet.java
@Override public void init() { if (s_context == null) { ServletContext ctx = getServletContext(); ServletContext sipxconfigCtx = ctx.getContext(SIPXCONFIG_SERVLET_PATH); WebApplicationContext webContext = WebApplicationContextUtils .getRequiredWebApplicationContext(sipxconfigCtx); CoreContext sipxCoreContext = ((CoreContext) (webContext.getBean(CORE_CONTEXT_BEAN_NAME))); PhoneContext sipxPhoneContext = ((PhoneContext) (webContext.getBean(PHONE_CONTEXT_BEAN_NAME))); Upload sipxUpload = ((Upload) (webContext.getBean(UPLOAD_BEAN_NAME))); s_context = new ProvisioningContextImpl(); s_context.setSipxCoreContext(sipxCoreContext); s_context.setSipxPhoneContext(sipxPhoneContext); s_context.setSipxUpload(sipxUpload); }//w ww . ja v a 2 s . c o m }
From source file:org.sipfoundry.sipxconfig.site.skin.SkinServlet.java
public void init(ServletConfig config) throws ServletException { ApplicationContext app = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); m_skin = (SkinControl) app.getBean(SkinControl.CONTEXT_BEAN_NAME); }
From source file:org.sipfoundry.sipxconfig.site.user.PinTokenChangeServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException { String body = IOUtils.toString(req.getInputStream(), "UTF-8"); try {//from w w w. j a v a2s .com ApplicationContext app = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); CoreContext core = (CoreContext) app.getBean(CoreContext.CONTEXT_BEAN_NAME); changePin(core, body); resp.setContentType("application/text"); } catch (ChangePinException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } }
From source file:org.springframework.extensions.webscripts.servlet.EndPointProxyServlet.java
@Override public void init() throws ServletException { super.init(); ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); ConfigService configService = (ConfigService) context.getBean("web.config"); // retrieve the remote configuration this.config = (RemoteConfigElement) configService.getConfig("Remote").getConfigElement("remote"); // retrieve the connector service this.connectorService = (ConnectorService) context.getBean("connector.service"); }
From source file:org.springframework.extensions.webscripts.servlet.WebScriptServlet.java
@Override public void init() throws ServletException { super.init(); ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); configService = (ConfigService) context.getBean("web.config"); String containerName = getServletConfig().getInitParameter("container"); if (containerName == null) { containerName = "webscripts.container"; }//from w w w. j a v a 2s . c o m container = (RuntimeContainer) context.getBean(containerName); // retrieve authenticator factory String authenticatorId = getInitParameter("authenticator"); if (authenticatorId != null && authenticatorId.length() > 0) { Object bean = context.getBean(authenticatorId); if (bean == null || !(bean instanceof ServletAuthenticatorFactory)) { throw new ServletException( "Initialisation parameter 'authenticator' does not refer to a servlet authenticator factory (" + authenticatorId + ")"); } authenticatorFactory = (ServletAuthenticatorFactory) bean; } // retrieve host server configuration Config config = configService.getConfig("Server"); serverProperties = (ServerConfigElement) config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID); // servlet specific initialisation initServlet(context); if (logger.isDebugEnabled()) logger.debug("Initialised Web Script Servlet (authenticator='" + authenticatorId + "')"); }
From source file:org.springframework.remoting.jaxrpc.ServletEndpointSupport.java
/** * Initialize this JAX-RPC servlet endpoint. * Calls onInit after successful context initialization. * @param context ServletEndpointContext * @throws ServiceException if the context is not a ServletEndpointContext * @see #onInit//from w ww.jav a2 s. c o m */ public final void init(Object context) throws ServiceException { if (!(context instanceof ServletEndpointContext)) { throw new ServiceException( "ServletEndpointSupport needs ServletEndpointContext, not [" + context + "]"); } this.servletEndpointContext = (ServletEndpointContext) context; ServletContext servletContext = this.servletEndpointContext.getServletContext(); this.webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); onInit(); }
From source file:org.springframework.web.context.support.SpringBeanAutowiringSupport.java
/** * Process {@code @Autowired} injection for the given target object, * based on the current root web application context as stored in the ServletContext. * <p>Intended for use as a delegate. * @param target the target object to process * @param servletContext the ServletContext to find the Spring web application context in * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext) *//*from w w w. j a v a 2 s.c o m*/ public static void processInjectionBasedOnServletContext(Object target, ServletContext servletContext) { Assert.notNull(target, "Target object must not be null"); WebApplicationContext cc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(cc.getAutowireCapableBeanFactory()); bpp.processInjection(target); }