当前位置: 首页>>代码示例>>Java>>正文


Java GenericWebApplicationContext类代码示例

本文整理汇总了Java中org.springframework.web.context.support.GenericWebApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java GenericWebApplicationContext类的具体用法?Java GenericWebApplicationContext怎么用?Java GenericWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericWebApplicationContext类属于org.springframework.web.context.support包,在下文中一共展示了GenericWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pathVarsInModel

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
public void pathVarsInModel() throws Exception {
	final Map<String, Object> pathVars = new HashMap<String, Object>();
	pathVars.put("hotel", "42");
	pathVars.put("booking", 21);
	pathVars.put("other", "other");

	WebApplicationContext wac =
		initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
			@Override
			public void initialize(GenericWebApplicationContext context) {
				RootBeanDefinition beanDef = new RootBeanDefinition(ModelValidatingViewResolver.class);
				beanDef.getConstructorArgumentValues().addGenericArgumentValue(pathVars);
				context.registerBeanDefinition("viewResolver", beanDef);
			}
		}, ViewRenderingController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42;q=1,2/bookings/21-other;q=3;r=R");
	getServlet().service(request, new MockHttpServletResponse());

	ModelValidatingViewResolver resolver = wac.getBean(ModelValidatingViewResolver.class);
	assertEquals(3, resolver.validatedAttrCount);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:UriTemplateServletAnnotationControllerHandlerMethodTests.java

示例2: defaultExpressionParameters

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
public void defaultExpressionParameters() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext context) {
			RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
			ppc.getPropertyValues().add("properties", "myKey=foo");
			context.registerBeanDefinition("ppc", ppc);
		}
	}, DefaultExpressionValueParamController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
	request.setContextPath("/myApp");
	MockHttpServletResponse response = new MockHttpServletResponse();
	System.setProperty("myHeader", "bar");
	try {
		getServlet().service(request, response);
	}
	finally {
		System.clearProperty("myHeader");
	}
	assertEquals("foo-bar-/myApp", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ServletAnnotationControllerHandlerMethodTests.java

示例3: renderView

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
private Map<?, ?> renderView() throws Exception{
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    v.setServletContext(req.getServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            new GenericWebApplicationContext(req.getServletContext()));

    final Cas30ResponseView view = new Cas30ResponseView(v);
    view.setServicesManager(this.servicesManager);
    view.setCasAttributeEncoder(new DefaultCasAttributeEncoder(this.servicesManager));

    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:Cas30ResponseViewTests.java

示例4: verifyView

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
public void verifyView() throws Exception {
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    v.setServletContext(req.getServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            new GenericWebApplicationContext(req.getServletContext()));

    final Cas20ResponseView view = new Cas20ResponseView(v);
    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);

    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
    assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:Cas20ResponseViewTests.java

示例5: renderView

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
private Map<?, ?> renderView() throws Exception {
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));

    final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
    final View viewDelegated = new View() {
        @Override
        public String getContentType() {
            return MediaType.TEXT_HTML_VALUE;
        }

        @Override
        public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            map.forEach(request::setAttribute);
        }
    };

    final Cas30ResponseView view = new Cas30ResponseView(true, encoder, servicesManager,
            "attribute", viewDelegated, true);
    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:Cas30ResponseViewTests.java

示例6: getApplicationContext

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
/**
 * Provides a static, single instance of the application context.  This method can be
 * called repeatedly.
 * <p/>
 * If the configuration requested differs from one used previously, then the previously-created
 * context is shut down.
 * 
 * @return Returns an application context for the given configuration
 */
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, String[] configLocations)
{
	AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations);
	
	CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");
	
	DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
	GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
	servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
       servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
	gwac.setServletContext(servletContext);
	gwac.refresh();

	return gwac;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:25,代码来源:WebApplicationContextLoader.java

示例7: standardHandleMethod

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
public void standardHandleMethod() throws Exception {
	DispatcherPortlet portlet = new DispatcherPortlet() {
		@Override
		protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
			wac.refresh();
			return wac;
		}
	};
	portlet.init(new MockPortletConfig());

	MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
	MockRenderResponse response = new MockRenderResponse();
	portlet.render(request, response);
	assertEquals("test", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:Portlet20AnnotationControllerTests.java

示例8: mavResolver

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
public void mavResolver() throws Exception {
	DispatcherPortlet portlet = new DispatcherPortlet() {
		@Override
		protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller",
					new RootBeanDefinition(ModelAndViewResolverController.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues()
					.add("customModelAndViewResolver", new MyModelAndViewResolver());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	portlet.init(new MockPortletConfig());

	MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
	MockRenderResponse response = new MockRenderResponse();
	portlet.render(request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:PortletAnnotationControllerTests.java

示例9: configureExporterParametersWithEncodingFromPropertiesFile

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void configureExporterParametersWithEncodingFromPropertiesFile() throws Exception {
	GenericWebApplicationContext ac = new GenericWebApplicationContext();
	ac.setServletContext(new MockServletContext());
	BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(ac);
	reader.loadBeanDefinitions(new ClassPathResource("view.properties", getClass()));
	ac.refresh();

	AbstractJasperReportsView view = (AbstractJasperReportsView) ac.getBean("report");
	String encoding = (String) view.getConvertedExporterParameters().get(
		net.sf.jasperreports.engine.export.JRHtmlExporterParameter.CHARACTER_ENCODING);
	assertEquals("UTF-8", encoding);

	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
	view.render(getModel(), request, response);
	assertEquals("Response content type is incorrect", "text/html;charset=UTF-8", response.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:JasperReportsHtmlViewTests.java

示例10: initServlet

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setProxyTargetClass(true);
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CgLibProxyServletAnnotationTests.java

示例11: doubles

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void doubles() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(DoubleController.class));
			RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
			mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
			wac.registerBeanDefinition("handlerMapping", mappingDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/lat/1.2/long/3.4");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);

	assertEquals("latitude-1.2-longitude-3.4", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:UriTemplateServletAnnotationControllerTests.java

示例12: noDefaultSuffixPattern

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void noDefaultSuffixPattern() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(ImplicitSubPathController.class));
			RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
			mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
			wac.registerBeanDefinition("handlerMapping", mappingDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/hotel.with.dot");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("test-hotel.with.dot", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:UriTemplateServletAnnotationControllerTests.java

示例13: suppressDefaultSuffixPattern

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void suppressDefaultSuffixPattern() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(VariableNamesController.class));
			RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
			mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
			wac.registerBeanDefinition("handlerMapping", mappingDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/[email protected]");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("[email protected]", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:UriTemplateServletAnnotationControllerTests.java

示例14: initServlet

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:JdkProxyServletAnnotationTests.java

示例15: emptyRequestMapping

import org.springframework.web.context.support.GenericWebApplicationContext; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void emptyRequestMapping() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(ControllerWithEmptyMapping.class));
			RootBeanDefinition mbd = new RootBeanDefinition(ControllerClassNameHandlerMapping.class);
			mbd.getPropertyValues().add("excludedPackages", null);
			mbd.getPropertyValues().add("order", 0);
			wac.registerBeanDefinition("mapping", mbd);
			wac.registerBeanDefinition("mapping2", new RootBeanDefinition(DefaultAnnotationHandlerMapping.class));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/servletannotationcontrollertests.controllerwithemptymapping");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("test", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ServletAnnotationControllerTests.java


注:本文中的org.springframework.web.context.support.GenericWebApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。