List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:com.kesdip.license.web.listener.SchemaUpdateContextListener.java
/** * Access Spring context, get <code>schemaUpdater</code> and call it. * /* w w w . ja v a 2 s .com*/ * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) */ public void contextInitialized(ServletContextEvent contextEvent) { logger.info("Getting Spring ApplicationContext"); ApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(contextEvent.getServletContext()); logger.info("Init SchemaUpdater"); SchemaUpdater schemaUpdater = new SchemaUpdater(SQL_PKG, getClass().getClassLoader(), VERSIONS); logger.info("Update schema"); schemaUpdater.updateSchema((HibernateTemplate) context.getBean("hibernateTemplate")); }
From source file:com.usefullc.platform.common.filter.WebCommonFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { ServletContext servletContext = filterConfig.getServletContext(); ServeltContextManager.setServletContext(servletContext); WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(servletContext); try {/*from w w w. j av a 2 s . c o m*/ actionHandlerInvoke = wc.getBean("actionHandlerInvoke", ActionHandlerInvoke.class); } catch (Exception e) { actionHandlerInvoke = null; } if (actionHandlerInvoke != null) { interceptorList = actionHandlerInvoke.getInterceptorList(); canExcute = CollectionUtils.isNotEmpty(interceptorList); } }
From source file:com.taobao.ad.easyschedule.servlet.ScheduleJobServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { JobData jobdata = HttpJobUtils.createJobData(request); JobResult result = null;/*from www . ja v a 2 s .c o m*/ String beanId = jobdata.getData().get(JobData.JOBDATA_DATA_BEANID); if (StringUtils.isEmpty(beanId)) { result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "???"); } else { try { WebApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); JobExecutor executor = (JobExecutor) context.getBean(beanId); result = HttpJobExecutor.getInstance().execute(jobdata, executor); } catch (BeansException e) { result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "beanid???" + e.getMessage()); logger.warn("beanid???", e); } } JSONObject json = (JSONObject) JSONObject.toJSON(result); response.setContentType("application/json;charset=utf-8"); PrintWriter out = response.getWriter(); out.print(json.toString()); }
From source file:org.openmeetings.servlet.outputhandler.BackupExportFacade.java
private BackupExport getBackupExport() { try {/*from w ww . j av a 2 s. c om*/ if (!ScopeApplicationAdapter.initComplete) { return null; } ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); return (BackupExport) context.getBean("backupExport"); } catch (Exception err) { log.error("[getBackupExport]", err); } return null; }
From source file:coyote.commons.web.AuthFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { context = filterConfig.getServletContext(); LOG.info("Servlet Context:" + context); applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); LOG.info("Spring Context:" + applicationContext); @SuppressWarnings("rawtypes") Enumeration initNames = context.getInitParameterNames(); if (initNames != null) { while (initNames.hasMoreElements()) { String name = (String) initNames.nextElement(); String value = filterConfig.getInitParameter(name); LOG.trace("Init:" + name + ":" + value); }/* ww w. j a v a2 s . com*/ } @SuppressWarnings("rawtypes") Enumeration attrNames = context.getAttributeNames(); if (attrNames != null) { while (attrNames.hasMoreElements()) { String name = (String) attrNames.nextElement(); String value = filterConfig.getInitParameter(name); LOG.trace("Attr:" + name + ":" + value); } } @SuppressWarnings("rawtypes") Enumeration initParams = filterConfig.getInitParameterNames(); if (initParams != null) { while (initParams.hasMoreElements()) { String name = (String) initParams.nextElement(); String value = filterConfig.getInitParameter(name); LOG.trace(name + ":" + value); } } if (applicationContext != null && applicationContext.containsBean("securityContext")) { securityContext = (SecurityContext) applicationContext.getBean("securityContext"); } if (securityContext != null) { LOG.trace("Security Context Initialized"); } else { LOG.fatal("Could not obtain a reference to the security context); application is unsecured!"); } LOG.trace("Authentication Filter initialized"); }
From source file:org.debux.webmotion.spring.SpringInstanceCreatorHandler.java
@Override public void handle(Mapping mapping, Call call) { // Get Spring context HttpContext context = call.getContext(); ServletContext servletContext = context.getServletContext(); ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); // Search bean in Spring context Executor executor = call.getCurrent(); Class<? extends WebMotionController> actionClass = executor.getClazz(); WebMotionController instance = applicationContext.getBean(actionClass); executor.setInstance(instance);// w ww .ja v a2s.c o m }
From source file:com.krawler.formbuilder.servlet.FileDownloadServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w. ja va 2s .co m WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); ModuleBuilderService moduleBuilderService = (ModuleBuilderService) applicationContext .getBean("moduleBuilderService"); mb_docs docsObj = (mb_docs) moduleBuilderService.getMBDocById(mb_docs.class, request.getParameter("docid")); String src = PropsValues.STORE_PATH + request.getParameter("url"); File fp = new File(src); byte[] buff = new byte[(int) fp.length()]; FileInputStream fis = new FileInputStream(fp); int read = fis.read(buff); javax.activation.FileTypeMap mmap = new javax.activation.MimetypesFileTypeMap(); String fileName = docsObj.getDocname(); response.setContentType(mmap.getContentType(fp)); response.setContentLength((int) fp.length()); String contentDisposition = ""; if (request.getParameter("attachment") != null) { contentDisposition = "attachment"; } else { contentDisposition = "inline"; } response.setHeader("Content-Disposition", contentDisposition + "; filename=\"" + fileName + "\";"); response.getOutputStream().write(buff, 0, buff.length); response.getOutputStream().flush(); } catch (Exception ex) { logger.warn("Unable To Download File :" + ex.toString(), ex); } }
From source file:org.openmeetings.axis.services.JabberWebServiceFacade.java
private JabberWebService getJabberServiceProxy() { try {//from w w w.j a v a 2 s . c o m ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); return ((JabberWebService) context.getBean("jabberWebService")); } catch (Exception err) { log.error("[getJabberServiceProxy]", err); } return null; }
From source file:com.tecapro.inventory.common.tag.MSButtonTag.java
@Override public int doStartTag() throws JspException { try {/*from w ww .j av a 2s .c om*/ String nameSpace = ""; if (this.nameSpace != null) { nameSpace = this.nameSpace; } MessageUtil msgUtil = (MessageUtil) WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()).getBean(BEAN_NAME_MSG_UTIL); StringUtil strUtil = (StringUtil) WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()).getBean(BEAN_NAME_STR_UTIL); TilesInfoValue value = (TilesInfoValue) pageContext .getAttribute(nameSpace + TilesInfoValue.class.getSimpleName(), PageContext.REQUEST_SCOPE); BaseForm form = (BaseForm) pageContext.getRequest().getAttribute(BaseForm.class.getSimpleName()); InfoValue info = form.getValue().getInfo(); value.setInfo(info); List<ButtonInfoValue> list = value.getButtonList(); ButtonInfoValue buttonInfo = list.get(index); if (buttonInfo == null || buttonInfo.getButtonName() == null) { this.setStyleClass("display_none"); MSTagUtil.addStyleClass(this, "disabled"); return super.doStartTag(); } if (buttonInfo.getInvisible() != null) { String flag = BeanUtils.getProperty(form, buttonInfo.getInvisible()); if (Constants.ONE.equals(flag)) { this.setStyleClass("display_hidden"); return super.doStartTag(); } } if (buttonInfo.getDisable() != null) { String flag = BeanUtils.getProperty(form, buttonInfo.getDisable()); if (Constants.ONE.equals(flag)) { this.setDisabled(true); MSTagUtil.addStyleClass(this, "disabled"); } } if (this.getDisabled()) { MSTagUtil.addStyleClass(this, "disabled"); } StringBuffer onclick = new StringBuffer(); if (getOnclick() != null && !"".equals(getOnclick())) { onclick.append(getOnclick() + ";"); } if (buttonInfo.getMessageId() != null) { String[] params = null; if (buttonInfo.getMessageParam() != null) { StringTokenizer token = new StringTokenizer(buttonInfo.getMessageParam(), ","); List<String> tokenList = new ArrayList<String>(); while (token.hasMoreTokens()) { tokenList.add(token.nextToken()); } params = tokenList.toArray(new String[tokenList.size()]); } onclick.append("if (!windowConfirm('").append(msgUtil.getMessage(buttonInfo.getMessageId(), params)) .append("')){return;};"); } // dirty check msg default String msgId = "MSG078C"; if (buttonInfo.isDirtyCheck() || Constants.BACK.equals(buttonInfo.getButtonName()) || Constants.MENU_MODORU.equals(buttonInfo.getButtonName())) { if (!strUtil.isNull(buttonInfo.getDirtyMsgId()) && !"".equals(buttonInfo.getDirtyMsgId())) { msgId = buttonInfo.getDirtyMsgId(); } onclick.append("if (!lossMessage('").append(msgUtil.getMessage(msgId, null)) .append("')){return;};"); } if (buttonInfo.getOnClick() != null && !"".equals(buttonInfo.getOnClick())) { onclick.append(buttonInfo.getOnClick() + ";"); } if (buttonInfo.getAction() != null && !"".equals(buttonInfo.getAction())) { onclick.append("send('").append(buttonInfo.getAction()).append("');"); } if (!"".equals(onclick.toString())) { this.setOnclick(onclick.toString()); } this.setValue(buttonInfo.getButtonName()); return super.doStartTag(); } catch (Exception e) { throw new JspException(e); } catch (Throwable e) { throw new JspException(e); } }
From source file:cz.muni.fi.dndtroopsweb.security.ProtectFilter2.java
/** * Provides authentication for hero part of project - as specified in class * annotation Checks whether the user exists, if the password is matching * /*w w w.j a va 2 s . co m*/ */ @Override public void doFilter(ServletRequest r, ServletResponse s, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) r; HttpServletResponse response = (HttpServletResponse) s; String auth = request.getHeader("Authorization"); if (auth == null) { response401(response); return; } String[] creds = parseAuthHeader(auth); String logname = creds[0]; String password = creds[1]; //get Spring context and UserFacade from it UserFacade userFacade = WebApplicationContextUtils.getWebApplicationContext(r.getServletContext()) .getBean(UserFacade.class); UserDTO matchingUser = userFacade.findUserByName(logname); if (matchingUser == null) { log.warn("no user with name {}", logname); response401(response); return; } UserAuthDTO userAuthDTO = new UserAuthDTO(); userAuthDTO.setUserId(matchingUser.getId()); userAuthDTO.setPassword(password); if (!userFacade.authenticate(userAuthDTO)) { log.warn("wrong credentials: user={} password={}", creds[0], creds[1]); response401(response); return; } request.setAttribute("authenticatedUser", matchingUser); chain.doFilter(request, response); }