Java 类org.springframework.web.context.WebApplicationContext 实例源码

项目:dss-demonstrations    文件:AppInitializer.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8"));

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/*");

    CXFServlet cxf = new CXFServlet();
    BusFactory.setDefaultBus(cxf.getBus());
    ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf);
    cxfServlet.setLoadOnStartup(1);
    cxfServlet.addMapping("/services/*");

    servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false,
            "/*");

    servletContext.getSessionCookieConfig().setSecure(cookieSecure);
}
项目:e-identification-tupas-idp-public    文件:ShibbolethExtAuthnHandler.java   
public void init(ServletConfig config) throws ServletException {
    try {
        WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
        final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
        beanFactory.autowireBean(this);
    }
    catch (Exception e) {
        logger.error("Error initializing ShibbolethExtAuthnHandler", e);
    }
}
项目:lams    文件:SpringBeanAutowiringSupport.java   
/**
 * Process {@code @Autowired} injection for the given target object,
 * based on the current web application context.
 * <p>Intended for use as a delegate.
 * @param target the target object to process
 * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
 */
public static void processInjectionBasedOnCurrentContext(Object target) {
    Assert.notNull(target, "Target object must not be null");
    WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
    if (cc != null) {
        AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
        bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
        bpp.processInjection(target);
    }
    else {
        if (logger.isDebugEnabled()) {
            logger.debug("Current WebApplicationContext is not available for processing of " +
                    ClassUtils.getShortName(target.getClass()) + ": " +
                    "Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
        }
    }
}
项目:lams    文件:EventNotificationService.java   
/**
    * See {@link IEventNotificationService#trigger(String, String, Long, String, String)
    */
   private void trigger(Event event, String subject, String message) {
final String subjectToSend = subject == null ? event.getSubject() : subject;
final String messageToSend = message == null ? event.getMessage() : message;

// create a new thread to send the messages as it can take some time
new Thread(() -> {
    try {
    HibernateSessionManager.openSession();
    // use proxy bean instead of concrete implementation of service
    // otherwise there is no transaction for the new session
    WebApplicationContext ctx = WebApplicationContextUtils
        .getWebApplicationContext(SessionManager.getServletContext());
    IEventNotificationService eventNotificationService = (IEventNotificationService) ctx
        .getBean("eventNotificationService");
    eventNotificationService.triggerInternal(event, subjectToSend, messageToSend);
    } finally {
    HibernateSessionManager.closeSession();
    }
}).start();
   }
项目:lams    文件:DelegatingFilterProxy.java   
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {

    // Lazily initialize the delegate if necessary.
    Filter delegateToUse = this.delegate;
    if (delegateToUse == null) {
        synchronized (this.delegateMonitor) {
            if (this.delegate == null) {
                WebApplicationContext wac = findWebApplicationContext();
                if (wac == null) {
                    throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
                }
                this.delegate = initDelegate(wac);
            }
            delegateToUse = this.delegate;
        }
    }

    // Let the delegate perform the actual doFilter operation.
    invokeDelegate(delegateToUse, request, response, filterChain);
}
项目:spring-cloud-skipper    文件:LocalSkipperResource.java   
@Override
protected void before() throws Throwable {

    final SpringApplicationBuilder builder = new SpringApplicationBuilder(LocalTestSkipperServer.class);

    if (this.configLocations  != null && this.configLocations.length > 0) {
        builder.properties(
            String.format("spring.config.location:%s", StringUtils.arrayToCommaDelimitedString(this.configLocations))
        );
    }

    if (this.configNames  != null && this.configNames.length > 0) {
        builder.properties(
            String.format("spring.config.name:%s", StringUtils.arrayToCommaDelimitedString(this.configNames))
        );
    }

    this.app = builder.build();



    configurableApplicationContext = app.run(
        new String[] { "--server.port=0" });

    Collection<Filter> filters = configurableApplicationContext.getBeansOfType(Filter.class).values();
    mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) configurableApplicationContext)
            .addFilters(filters.toArray(new Filter[filters.size()])).build();
    skipperPort = configurableApplicationContext.getEnvironment().resolvePlaceholders("${server.port}");
}
项目:lams    文件:AuthoringAction.java   
private IForumService getForumManager() {
if (forumService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    forumService = (IForumService) wac.getBean(ForumConstants.FORUM_SERVICE);
}
return forumService;
   }
项目:lams    文件:OrganisationGroupAction.java   
private ILessonService getLessonService() {
if (OrganisationGroupAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    OrganisationGroupAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return OrganisationGroupAction.lessonService;
   }
项目:lams    文件:LearningAction.java   
@Override
   public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);

WebApplicationContext wac = WebApplicationContextUtils
    .getRequiredWebApplicationContext(getServlet().getServletContext());
ILearnerService learnerService = (ILearnerService) wac.getBean("learnerService");
String finishURL = learnerService.completeToolSession(toolSessionId, user.getUserID().longValue());
return new RedirectingActionForward(finishURL);
   }
项目:lams    文件:HomeAction.java   
private IUserManagementService getUserManagementService() {
if (HomeAction.userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.userManagementService = (IUserManagementService) ctx.getBean("userManagementService");
}
return HomeAction.userManagementService;
   }
项目:lams    文件:HomeAction.java   
private ILearningDesignService getLearningDesignService() {
if (HomeAction.learningDesignService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService");
}
return HomeAction.learningDesignService;
   }
项目:lams    文件:AuthoringAction.java   
private IUserManagementService getUserManagementService() {
if (AuthoringAction.userManagementService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    AuthoringAction.userManagementService = (IUserManagementService) wac
        .getBean(CentralConstants.USER_MANAGEMENT_SERVICE_BEAN_NAME);
}
return AuthoringAction.userManagementService;
   }
项目:parabuild-ci    文件:JettySpringLauncher.java   
/**
 * Sets up and runs server.
 * @param args
 */
public static void main(String[] args)
{
    final Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    Context htmlContext = new Context(server, "/", Context.SESSIONS);

    ResourceHandler htmlHandler = new ResourceHandler();
    htmlHandler.setResourceBase("web");
    htmlContext.setHandler(htmlHandler);

    Context servletContext = new Context(server, "/", Context.SESSIONS);

    GenericWebApplicationContext springContext = new GenericWebApplicationContext();
    springContext.setParent(new ClassPathXmlApplicationContext("org/getahead/dwrdemo/cli/spring.xml"));
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext);

    ServletHolder holder = new ServletHolder(new DwrSpringServlet());
    holder.setInitParameter("pollAndCometEnabled", "true");
    holder.setInitParameter("debug", "true");
    servletContext.addServlet(holder, "/dwr/*");

    try
    {
        JettyShutdown.addShutdownHook(server);
        server.start();
        server.join();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
项目:lams    文件:LearningWebUtil.java   
/**
    * Finds activity position within Learning Design and stores it as request attribute.
    */
   public static ActivityPositionDTO putActivityPositionInRequestByToolSessionId(Long toolSessionId,
    HttpServletRequest request, ServletContext context) {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
ILearnerService learnerService = (ILearnerService) wac.getBean("learnerService");
if (learnerService == null) {
    LearningWebUtil.log.warn("Can not set activity position, no Learner service in servlet context.");
    return null;
}
ActivityPositionDTO positionDTO = learnerService.getActivityPositionByToolSessionId(toolSessionId);
if (positionDTO != null) {
    request.setAttribute(AttributeNames.ATTR_ACTIVITY_POSITION, positionDTO);
}
return positionDTO;
   }
项目:lams    文件:OpenSessionInViewFilter.java   
/**
 * 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);
}
项目:holon-vaadin7    文件:AbstractVaadinSpringTest.java   
public TestSpringVaadinServletService(VaadinServlet servlet, WebApplicationContext applicationContext)
        throws ServiceException {
    super(servlet, new DefaultDeploymentConfiguration(TestSpringVaadinServletService.class, new Properties()),
            "");
    this.appContext = applicationContext;
    init();
}
项目:brkr    文件:EmbeddedJetty.java   
private void startJetty(int port) throws Exception {
    Server server = new Server(port);
    WebApplicationContext webApplicationContext = createWebApplicationContext();
    ServletContextHandler handler = createHandlerWith(webApplicationContext);
    server.setHandler(handler);
    server.start();
    server.join();
}
项目:brkr    文件:EmbeddedJetty.java   
private ServletContextHandler createHandlerWith(WebApplicationContext webApplicationContext) {
    ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.setContextPath(CONTEXT_PATH_RESPOND_TO_ALL_REQUESTS);
    ServletHolder dispatcherServletHolder = new ServletHolder(new DispatcherServlet(webApplicationContext));
    servletContextHandler.addServlet(dispatcherServletHolder, CONTEXT_PATH_RESPOND_TO_ALL_REQUESTS);
    return servletContextHandler;
}
项目:xproject    文件:ApplicationInitializeListener.java   
public void afterPropertiesSet() throws Exception {
    String mode = applicationContext instanceof WebApplicationContext ? "Java Servlet Mode" : "Java Application Mode";
       logger.info(String.format("application initializing start in %s", mode));
       logger.info("application initializing begin ...");
       if (!CollectionUtils.isEmpty(applicationInitializers)) {
           for (ApplicationInitializer applicationInitializer : applicationInitializers) {
            applicationInitializer.initialize(applicationContext);
           }
       }
       logger.info("application initializing end ...");
}
项目:lams    文件:FindUserLessonsAction.java   
private IUserManagementService getUserManagementService() {
if (FindUserLessonsAction.userManagementService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    FindUserLessonsAction.userManagementService = (IUserManagementService) wac
        .getBean(CentralConstants.USER_MANAGEMENT_SERVICE_BEAN_NAME);
}
return FindUserLessonsAction.userManagementService;
   }
项目:lams    文件:LoginAsAction.java   
@Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

WebApplicationContext ctx = WebApplicationContextUtils
    .getRequiredWebApplicationContext(getServlet().getServletContext());
IUserManagementService service = (IUserManagementService) ctx.getBean("userManagementService");
MessageService messageService = (MessageService) ctx.getBean("centralMessageService");
String login = WebUtil.readStrParam(request, "login", false);

if (service.isUserSysAdmin()) {
    if ((login != null) && (login.trim().length() > 0)) {
    User user = service.getUserByLogin(login);
    if (user != null) {
        // audit log when loginas
        UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
        IAuditService auditService = (IAuditService) ctx.getBean("auditService");
        String[] args = new String[] { sysadmin.getLogin() + "(" + sysadmin.getUserID() + ")", login };
        String message = messageService.getMessage("audit.admin.loginas", args);
        auditService.log(CentralConstants.MODULE_NAME, message);

        // login.jsp knows what to do with these
        request.setAttribute("login", login);
        String token = "#LAMS" + RandomPasswordGenerator.nextPassword(10);
        request.setAttribute("password", token);
        // notify the login module that the user has been authenticated correctly
        UniversalLoginModule.setAuthenticationToken(token);
        // redirect to login page
        return (new ActionForward("/login.jsp?redirectURL=/lams/index.jsp"));
    }
    }
} else {
    request.setAttribute("errorName", "LoginAsAction");
    request.setAttribute("errorMessage", messageService.getMessage("error.authorisation"));
    return mapping.findForward("error");
}

return mapping.findForward("usersearch");
   }
项目:keti    文件:TestUtils.java   
public MockMvcContext createWACWithCustomGETRequestBuilder(final WebApplicationContext wac, final String subdomain,
        final String resourceURI) throws URISyntaxException {
    MockMvcContext result = new MockMvcContext();
    result.setBuilder(MockMvcRequestBuilders.get(new URI("http://" + subdomain + ".localhost/" + resourceURI))
            .accept(MediaType.APPLICATION_JSON));
    result.setMockMvc(MockMvcBuilders.webAppContextSetup(wac).defaultRequest(result.getBuilder()).build());
    return result;
}
项目:JSiter    文件:HTTPBasicAuthorizeAttribute.java   
@Override
public void init(FilterConfig fConfig) throws ServletException {
    ServletContext sc = fConfig.getServletContext();
    WebApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(sc);

    if (cxt != null) {
        cookieUtil = cxt.getBean(CookieUtil.class);
        sessionUtil = cxt.getBean(SessionUtil.class);
    }
    System.out.println("init finished");

}
项目:lams    文件:EditLessonIntroAction.java   
private ILessonService getLessonService() {
if (lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    lessonService = (ILessonService) ctx.getBean("lessonService");
}
return lessonService;
   }
项目:lams    文件:EmailUserAction.java   
private MessageService getMessageService() {
if (EmailUserAction.messageService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    EmailUserAction.messageService = (MessageService) ctx
        .getBean(CentralConstants.CENTRAL_MESSAGE_SERVICE_BEAN_NAME);

}
return EmailUserAction.messageService;
   }
项目:lams    文件:RepopulateProgressMarksServlet.java   
@Override
   public void init() throws ServletException {
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
RepopulateProgressMarksServlet.auditService = (IAuditService) ctx.getBean("auditService");
RepopulateProgressMarksServlet.lessonService = (ILessonService) ctx.getBean("lessonService");
RepopulateProgressMarksServlet.learnerService = (ICoreLearnerService) ctx.getBean("learnerService");
   }
项目:lams    文件:PedagogicalPlannerAction.java   
private IUserManagementService getUserManagementService() {
if (userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    userManagementService = (IUserManagementService) ctx
        .getBean(CentralConstants.USER_MANAGEMENT_SERVICE_BEAN_NAME);
}
return userManagementService;
   }
项目:lams    文件:LanguageUtil.java   
private static IUserManagementService getService() {
if (LanguageUtil.service == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getWebApplicationContext(SessionManager.getServletContext());
    LanguageUtil.service = (IUserManagementService) ctx.getBean("userManagementService");
}
return LanguageUtil.service;
   }
项目:lams    文件:RecalculateTotalMarksForLessonServlet.java   
@Override
   public void init() throws ServletException {
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
auditService = (IAuditService) ctx.getBean("auditService");
lessonService = (ILessonService) ctx.getBean("lessonService");
gradebookService = (IGradebookService) ctx.getBean("gradebookService");
   }
项目:lams    文件:GradebookLearningAction.java   
private IUserManagementService getUserService() {
if (GradebookLearningAction.userService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookLearningAction.userService = (IUserManagementService) ctx.getBean("userManagementService");
}
return GradebookLearningAction.userService;
   }
项目:lams    文件:GradebookLearningAction.java   
private ISecurityService getSecurityService() {
if (GradebookLearningAction.securityService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookLearningAction.securityService = (ISecurityService) ctx.getBean("securityService");
}
return GradebookLearningAction.securityService;
   }
项目:lams    文件:HomeAction.java   
private ILessonService getLessonService() {
if (HomeAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return HomeAction.lessonService;
   }
项目:lams    文件:PedagogicalPlannerAction.java   
private IMonitoringService getMonitoringService() {
if (monitoringService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    monitoringService = (IMonitoringService) ctx.getBean(CentralConstants.MONITORING_SERVICE_BEAN_NAME);
}
return monitoringService;
   }
项目:JSiter    文件:InitialFilter.java   
@Override
public void init(FilterConfig fConfig) throws ServletException {
    ServletContext sc = fConfig.getServletContext();
    WebApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(sc);
    if (cxt != null) {

    }
    System.out.println("init finished");
}
项目:lams    文件:GradebookAction.java   
private ILessonService getLessonService() {
if (GradebookAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    GradebookAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return GradebookAction.lessonService;
   }
项目:lams    文件:RestServlet.java   
protected IToolDAO getToolDAO() {
if (RestServlet.toolDAO == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServletContext());
    RestServlet.toolDAO = (IToolDAO) ctx.getBean("toolDAO");
}
return RestServlet.toolDAO;
   }
项目:lams    文件:OrganisationGroupAction.java   
private IUserManagementService getUserManagementService() {
if (OrganisationGroupAction.userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServlet().getServletContext());
    OrganisationGroupAction.userManagementService = (IUserManagementService) ctx
        .getBean("userManagementService");
}
return OrganisationGroupAction.userManagementService;
   }
项目:lams    文件:ContextExposingHttpServletRequest.java   
/**
 * Create a new ContextExposingHttpServletRequest for the given request.
 * @param originalRequest the original HttpServletRequest
 * @param context the WebApplicationContext that this request runs in
 * @param exposedContextBeanNames the names of beans in the context which
 * are supposed to be exposed (if this is non-null, only the beans in this
 * Set are eligible for exposure as attributes)
 */
public ContextExposingHttpServletRequest(
        HttpServletRequest originalRequest, WebApplicationContext context, Set<String> exposedContextBeanNames) {

    super(originalRequest);
    Assert.notNull(context, "WebApplicationContext must not be null");
    this.webApplicationContext = context;
    this.exposedContextBeanNames = exposedContextBeanNames;
}
项目:Spring-web-shop-project    文件:SessionActionsListener.java   
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    if (ApplicationProperties.FALSE_WHILE_RUNNING_DB_TESTS) {
        if (applicationContext instanceof WebApplicationContext)
            ((WebApplicationContext) applicationContext).getServletContext().addListener(this);
        else
            throw new RuntimeException("Must be inside a web application context");
    }
}
项目:backbone    文件:ApplicationInitializer.java   
@Override
protected WebApplicationContext createServletApplicationContext() {
    AnnotationConfigWebApplicationContext applicationContext = (AnnotationConfigWebApplicationContext) super.createServletApplicationContext();
    if (applicationContext != null)
        applicationContext.setDisplayName("DispatcherServlet WebMvcApplicationConfig");
    return applicationContext;
}