Package org.springframework.context.support

Examples of org.springframework.context.support.GenericApplicationContext


     */
    public Object getServiceObject(AxisService axisService) throws AxisFault {
        try {
            // Get the Spring Context based on service, the context is set as parameter to the
            // spring service in SpringServiceDeployer when service deployed.
            GenericApplicationContext aCtx = ApplicationContextUtil.
                    getSpringApplicationContext(axisService);

            // Name of spring aware bean to be injected, taken from services.xml
            // via 'SERVICE_SPRING_BEANNAME ' . The Bean and its properties are pre-configured
            // as normally done in a spring type of way and subsequently loaded by Spring.
            // Axis2 just assumes that the bean is configured and is in the classloader.
            Parameter implBeanParam = axisService.getParameter(SERVICE_SPRING_BEANNAME);
            if (implBeanParam != null) {
                String beanName = ((String) implBeanParam.getValue()).trim();
                if (aCtx == null) {
                    throw new AxisFault("Axis2 Can't find Spring's ApplicationContext");
                } else if (aCtx.getBean(beanName) == null) {
                    throw new AxisFault("Axis2 Can't find Spring Bean: " + beanName);
                }
                return aCtx.getBean(beanName);
            } else {
                throw new AxisFault(
                        Messages.getMessage("paramIsNotSpecified", SERVICE_SPRING_BEANNAME));
            }
        } catch (Exception e) {
View Full Code Here


     */

    public static GenericApplicationContext getSpringApplicationContext(AxisService axisService)
            throws AxisFault {

        GenericApplicationContext appContext;
        Parameter appContextParameter = axisService.getParameter(SPRING_APPLICATION_CONTEXT);
        Parameter contextLocationParam = axisService
                .getParameter(SPRING_APPLICATION_CONTEXT_LOCATION);

        // return the application context
        if (appContextParameter != null) {
            appContext = (GenericApplicationContext) appContextParameter.getValue();
            // if the context is not found initialize a new one
        } else {
            appContext = new GenericApplicationContext();
            ClassLoader serviceCL = axisService.getClassLoader();
            appContext.setClassLoader(serviceCL);
            ClassLoader currentCL = Thread.currentThread().getContextClassLoader();

            try {
                Thread.currentThread().setContextClassLoader(serviceCL);
                XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);

                // load the bean context file from the parameter
                if (contextLocationParam != null) {
                    xbdr.loadBeanDefinitions(new ClassPathResource((String) contextLocationParam
                            .getValue()));
                    appContext.refresh();
                    AxisServiceGroup axisServiceGroup = axisService.getAxisServiceGroup();
                    Parameter springGroupCtxLocation = axisServiceGroup
                            .getParameter(SPRING_APPLICATION_CONTEXT_LOCATION);
                    // add the context to the service group or add it to the
                    // service
                    if (springGroupCtxLocation != null) {
                        axisServiceGroup.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT,
                                appContext));
                    } else {
                        axisService.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT,
                                appContext));
                    }
                    return appContext;
                }

                InputStream ctxFileInputStream = serviceCL
                        .getResourceAsStream(DeploymentConstants.META_INF + File.separator
                                + axisService.getName() + "-application-context.xml");
                // try for meta-inf
                if (ctxFileInputStream == null) {
                    ctxFileInputStream = serviceCL.getResourceAsStream(DeploymentConstants.META_INF
                            .toLowerCase()
                            + File.separator
                            + axisService.getName()
                            + "-application-context.xml");
                }
                // load the context file from meta-inf
                if (ctxFileInputStream != null) {
                    xbdr.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
                    xbdr.loadBeanDefinitions(new InputStreamResource(ctxFileInputStream));
                    appContext.refresh();
                    axisService.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT, appContext));
                    return appContext;
                } else {
                    throw new AxisFault("Spring context file cannot be located for AxisService");
                }
View Full Code Here

     * @return
     */
    public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames) {
        BusApplicationContext busApplicationContext = BusFactory.getDefaultBus()
            .getExtension(BusApplicationContext.class);
        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        List<URL> urls = ClassLoaderUtils.getResources("META-INF/cxf/java2wsbeans.xml",
                                                       SpringServiceBuilderFactory.class);
        for (URL url : urls) {
            reader.loadBeanDefinitions(new UrlResource(url));
        }
       
        for (String pathname : additionalFilePathnames) {
            try {
                reader.loadBeanDefinitions(new FileSystemResource(pathname));
            } catch (BeanDefinitionStoreException bdse) {
                throw new ToolException("Unable to open bean definition file " + pathname, bdse.getCause());
            }
        }
        appContext.refresh();
        return appContext;
    }
View Full Code Here

*/
public class SpringYarnAnnotationPostProcessorTests {

  @Test
  public void testSimpleOnContainerStart() {
    @SuppressWarnings("resource")
    GenericApplicationContext context = new GenericApplicationContext();
    SpringYarnAnnotationPostProcessor postProcessor = new SpringYarnAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    TestBean testBean = new TestBean();
    postProcessor.postProcessAfterInitialization(testBean, "testBean");
    context.refresh();
    assertTrue(context.containsBean("testBean.test.onContainerStart"));
    Object endpoint = context.getBean("testBean.test.onContainerStart");
    assertTrue(endpoint instanceof ContainerHandler);
    context.stop();
  }
View Full Code Here

  @Test
  public void testNullCfg() throws Exception {
    ScriptSource script = new StaticScriptSource("null");
   
    HdfsScriptRunner hsfb = new HdfsScriptRunner();
    GenericApplicationContext gac = new GenericApplicationContext();
    gac.refresh();
    hsfb.setApplicationContext(gac);
    hsfb.setScriptSource(script);
    hsfb.setLanguage("javascript");
    hsfb.afterPropertiesSet();
   
View Full Code Here

     * @param bus
     * @return
     */
    public static ApplicationContext getApplicationContext(Bus bus, List<String> additionalFilePathnames) {
        BusApplicationContext busApplicationContext = bus.getExtension(BusApplicationContext.class);
        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        reader.loadBeanDefinitions(new ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
        for (String pathname : additionalFilePathnames) {
            try {
                reader.loadBeanDefinitions(new FileSystemResource(pathname));
View Full Code Here

     * @param bus
     * @return
     */
    public static ApplicationContext getApplicationContext(Bus bus, List<String> additionalFilePathnames) {
        BusApplicationContext busApplicationContext = bus.getExtension(BusApplicationContext.class);
        GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
        reader.loadBeanDefinitions(new ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
        for (String pathname : additionalFilePathnames) {
            try {
                reader.loadBeanDefinitions(new FileSystemResource(pathname));
View Full Code Here

     * @see org.apache.camel.spring.config.scan.SpringComponentScanTest for an example.
     * @return ApplicationContext a parent {@link ApplicationContext} configured
     *         to exclude certain classes from package scanning
     */
    protected ApplicationContext getRouteExcludingApplicationContext() {
        GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
        routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
        routeExcludingContext.refresh();

        ExcludingPackageScanClassResolver excludingResolver = (ExcludingPackageScanClassResolver)routeExcludingContext.getBean("excludingResolver");
        List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludeRoutes()));
        excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));

        return routeExcludingContext;
    }
View Full Code Here

     *
     * @return ApplicationContext a parent {@link ApplicationContext} configured
     *         to exclude certain classes from package scanning
     */
    protected ApplicationContext getRouteExcludingApplicationContext() {
        GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
        routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
        routeExcludingContext.refresh();

        ExcludingPackageScanClassResolver excludingResolver = (ExcludingPackageScanClassResolver)routeExcludingContext.getBean("excludingResolver");
        List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludeRoutes()));
        excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));

        return routeExcludingContext;
    }
View Full Code Here

        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.support.GenericApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.