List of usage examples for org.springframework.web.context WebApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:grails.plugin.errorpagesfix.PatchedErrorHandlingServlet.java
private UrlMappingsHolder lookupUrlMappings() { WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); return (UrlMappingsHolder) wac.getBean(UrlMappingsHolder.BEAN_ID); }
From source file:net.naijatek.myalumni.util.taglib.DisplayClassNewsTag.java
/** * Includes the body of the tag if the page attribute equals the value set * in the 'match' attribute.//w w w . j a va 2s.c o m * * @return SKIP_BODY if equalsAttribute body content does not equal the * value of the match attribute, EVAL_BODY_include if it does * @throws JspException */ @Override public final int doStartTag() throws JspException { request = (HttpServletRequest) pageContext.getRequest(); session = request.getSession(); container = (MyAlumniUserContainer) session.getAttribute(BaseConstants.USER_CONTAINER); WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()); classNewsService = (IClassNewsService) wac.getBean(BaseConstants.SERVICE_CLASSNEWS_LOOKUP); return EVAL_BODY_BUFFERED; }
From source file:com.taobao.ad.easyschedule.server.JobHttpServer.java
@Override public void run() { try {/*from ww w.j a va 2 s . co m*/ HttpServer httpServer = HttpServer.create(new InetSocketAddress(Integer.parseInt(Const.SERVER_PORT)), 0); httpServer.createContext(Const.SERVER_CONTEXT, new HttpHandler() { @Override public void handle(final HttpExchange exchange) throws IOException { JobResult result = JobResult.succcessResult(); String queryPath = exchange.getRequestURI().getPath(); String queryStr = exchange.getRequestURI().getQuery(); if (StringUtils.isEmpty(queryStr) || StringUtils.isEmpty(queryPath)) { result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "??"); } else { try { queryPath = queryPath.replaceAll(Const.SERVER_CONTEXT, ""); JobData jobData = HttpJobUtils.createJobData(queryStr); String beanId = jobData.getData().get(JobData.JOBDATA_DATA_BEANID); if (StringUtils.isEmpty(beanId)) { result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "???"); } else { if (Const.DEPLOY_MODE.equals("dev")) { Long signTime = System.currentTimeMillis() / 1000; String token = TokenUtils.generateToken(signTime.toString()); jobData.setSignTime(signTime.toString()); jobData.setToken(token); } result = HttpJobUtils.checkJobData(jobData); if (result.isSuccess()) { if (queryPath.equals(Const.QUERYPATH_DOSTDJOB)) { WebApplicationContext context = ContextLoader .getCurrentWebApplicationContext(); JobExecutor executor = (JobExecutor) context.getBean(beanId); result = HttpJobExecutor.getInstance().execute(jobData, executor); } else { result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "" + queryPath); } } } } catch (Exception e) { result = JobResult.errorResult(JobResult.RESULTCODE_OTHER_ERR, ""); logger.info("|" + queryStr); } } JSONObject json = (JSONObject) JSONObject.toJSON(result); exchange.getResponseHeaders().set("Content-type", "application/json;charset=utf-8"); exchange.sendResponseHeaders(200, 0L); OutputStream os = exchange.getResponseBody(); os.write(json.toString().getBytes("utf-8")); os.close(); } }); httpServer.start(); } catch (Throwable e) { logger.error("JobHttpServer.run is fail:" + e.getMessage(), e); } }
From source file:net.mindengine.oculus.frontend.web.controllers.admin.user.UserEditController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { verifyPermissions(request);//from w w w . j av a 2 s. co m Long id = new Long(request.getParameter("id")); if (id.intValue() == 1) throw new Exception("Admin account cannot be changed"); User user = (User) command; WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(request.getSession().getServletContext()); List<Permission> permissions = ((PermissionList) wac.getBean("permissionList")).getPermissions(); // Getting state of permission checkboxes List<Integer> newPermissionCodes = new ArrayList<Integer>(); for (Permission p : permissions) { int code = p.getCode(); String state = request.getParameter("p_" + code); if ("on".equals(state)) { newPermissionCodes.add(code); } user.getClass(); } BitCrypter bitCrypter = new BitCrypter(); String encryptedPermissions = bitCrypter.encrypt(newPermissionCodes); user.setPermissions(encryptedPermissions); if (user != null) { userDAO.updateUser(id, user); } return new ModelAndView(new RedirectView("../admin/edit-user?id=" + id)); }
From source file:org.cometd.server.SpringFrameworkConfigurationTest.java
@Test public void testXMLSpringConfiguration() throws Exception { int port = this.port; server.stop();// w w w . ja v a 2 s .c om // Add Spring listener context.addEventListener(new ContextLoaderListener()); context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml"); connector.setPort(port); server.start(); WebApplicationContext applicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(context.getServletContext()); assertNotNull(applicationContext); int sweepPeriod = (Integer) applicationContext.getBean("sweepPeriod"); BayeuxServerImpl bayeuxServer = (BayeuxServerImpl) applicationContext.getBean("bayeux"); assertNotNull(bayeuxServer); assertTrue(bayeuxServer.isStarted()); assertEquals(sweepPeriod, bayeuxServer.getOption("sweepPeriod")); assertSame(bayeuxServer, cometdServlet.getBayeux()); Request handshake = newBayeuxRequest("" + "[{" + "\"channel\": \"/meta/handshake\"," + "\"version\": \"1.0\"," + "\"minimumVersion\": \"1.0\"," + "\"supportedConnectionTypes\": [\"long-polling\"]" + "}]"); ContentResponse response = handshake.send(); assertEquals(200, response.getStatus()); }
From source file:com.trailmagic.image.ui.ImageGroupLinkTag.java
public int doStartTag() throws JspException { StringBuffer html = new StringBuffer(); try {/*from ww w.j a v a2 s .c o m*/ html.append("<a "); if (m_styleClass != null) { html.append("class=\"" + m_styleClass + "\" "); } html.append("href=\""); //XXX: yeek? WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); LinkHelper helper = ctx.getBean(LinkHelper.class); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (m_image != null) { html.append(helper.getImageGroupFrameUrl(request, m_imageGroup, m_image)); } else if (m_imageGroup != null) { html.append(helper.getImageGroupUrl(request, m_imageGroup)); } else if (m_owner != null) { html.append(helper.getImageGroupsUrl(request, m_groupType, m_owner)); } else { html.append(helper.getImageGroupsRootUrl(request, m_groupType)); } html.append("\">"); pageContext.getOut().write(html.toString()); return EVAL_BODY_INCLUDE; } catch (IOException e) { throw new JspException(e); } }
From source file:io.seldon.servlet.ResourceManagerListener.java
public void contextInitialized(ServletContextEvent sce) { logger.info("********************** STARTING API-SERVER INITIALISATION **********************"); JDOFactory jdoFactory = null;//ww w. j a v a 2s .c om try { final WebApplicationContext springContext = WebApplicationContextUtils .getWebApplicationContext(sce.getServletContext()); jdoFactory = (JDOFactory) springContext.getBean("JDOFactory"); zkClientConfigHandler = (ZkClientConfigHandler) springContext.getBean("zkClientConfigHandler"); //InputStream propStream = sce.getServletContext().getResourceAsStream("/WEB-INF/labs.properties"); InputStream propStream = getClass().getClassLoader().getResourceAsStream("/labs.properties"); SecurityHashPeer.initialise(); Properties props = new Properties(); props.load(propStream); // Set the default client name from properties if it exists String defClientName = props.getProperty("io.seldon.labs.default.client"); if (defClientName != null && defClientName.length() > 0) { Constants.DEFAULT_CLIENT = defClientName; } MemCachePeer.initialise(props); StatsdPeer.initialise(props); ZkCuratorHandler curatorHandler = ZkCuratorHandler.getPeer(); if (curatorHandler != null) { ZkAlgorithmUpdaterFactory.initialise(props, curatorHandler); } zkClientConfigHandler.contextIntialised(); logger.info("********************** ENDING API-SERVER INITIALISATION **********************"); } catch (IOException ex) { logger.error("IO Exception", ex); } catch (Exception ex) { logger.error("Exception at resource initialization", ex); } catch (Throwable e) { logger.error("Throwable during initialization ", e); } finally { if (jdoFactory != null) jdoFactory.cleanupPM(); } }
From source file:cn.buk.qms.listener.QuartzContextListener.java
@Override public void contextDestroyed(ServletContextEvent arg0) { WebApplicationContext webApplicationContext = (WebApplicationContext) arg0.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); Object obj = webApplicationContext.getBean("ctripHotelService"); //System.out.println(obj); cn.buk.api.service.CtripHotelServiceImpl ctripHotelService = (cn.buk.api.service.CtripHotelServiceImpl) obj; if (ctripHotelService != null) { ctripHotelService.stopService(); System.out.println("ctripHotelService.stopService();"); try {//from www . jav a 2 s .c om Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } obj = null; System.out.println("Obj: " + obj); obj = webApplicationContext.getBean("hotelService"); System.out.println("Obj: " + obj); //if(obj != null) { //cn.buk.hotel.service.HotelServiceImpl hotelService = ; //System.out.println("hotelService: " + hotelService); System.out.println("hotelService.stopService();"); ((cn.buk.hotel.service.HotelServiceImpl) obj).stopService(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } //} obj = webApplicationContext.getBean("startQuartz"); //System.out.println(obj.getClass().getName()); org.quartz.impl.StdScheduler startQuartz = (org.quartz.impl.StdScheduler) obj; if (startQuartz != null) { //System.out.println("startQuertz.shutdown();"); startQuartz.shutdown(); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.wikipy.security.AuthenticationFilter.java
@Override public void init(FilterConfig config) throws ServletException { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); userService = (BasicUserService) ctx.getBean("userService"); cacheService = (EhCacheService) ctx.getBean("cacheService"); }
From source file:org.lamsfoundation.lams.admin.web.CacheAction.java
private ICacheManager getCacheManager() { if (cacheManager == null) { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); cacheManager = (CacheManager) ctx.getBean("cacheManager"); }//from w w w .j av a 2 s.c o m return cacheManager; }