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


Java RequestContext类代码示例

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


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

示例1: renderView

import org.springframework.web.servlet.support.RequestContext; //导入依赖的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

示例2: verifyView

import org.springframework.web.servlet.support.RequestContext; //导入依赖的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

示例3: renderView

import org.springframework.web.servlet.support.RequestContext; //导入依赖的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

示例4: exposeSpringMacroHelpers

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Test
public void exposeSpringMacroHelpers() throws Exception {
	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
			assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
			RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
			BindStatus status = rc.getBindStatus("tb.name");
			assertEquals("name", status.getExpression());
			assertEquals("juergen", status.getValue());
		}
	};
	vv.setUrl(TEMPLATE_FILE);
	vv.setApplicationContext(wac);
	vv.setExposeSpringMacroHelpers(true);

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("tb", new TestBean("juergen", 99));
	vv.render(model, request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:VelocityMacroTests.java

示例5: requestContext

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MessageTagTests.java

示例6: requestContext

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ThemeTagTests.java

示例7: renderMergedOutputModel

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

	ServletContext servletContext = getServletContext();
	TilesContainer container = ServletUtil.getContainer(servletContext);
	if (container == null) {
		throw new ServletException("Tiles container is not initialized. " +
				"Have you added a TilesConfigurer to your web application context?");
	}

	exposeModelAsRequestAttributes(model, request);
	JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));
	if (this.alwaysInclude) {
		ServletUtil.setForceInclude(request, true);
	}
	container.render(getUrl(), request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:TilesView.java

示例8: createLayoutFromConfigClass

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Test
public void createLayoutFromConfigClass() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	MockServletContext servletContext = new MockServletContext();
	context.setServletContext(servletContext);
	context.refresh();
	ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class)
			.resolveViewName("view", Locale.UK);
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	view.render(Collections.singletonMap("foo", "bar"), request, response);
	String result = response.getContentAsString();
	assertThat(result).contains("<title>Content</title>");
	assertThat(result).contains("<span>bar</span>");
	context.close();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ThymeleafAutoConfigurationTests.java

示例9: renderMergedOutputModel

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
    Resource templateFile = getApplicationContext().getResource(getUrl());

    String rcKey = getRequestContextAttribute();
    RequestContext rc = (RequestContext)model.get(rcKey);

    Theme theme = getTheme(templateFile.getFile().getParent());
    Chunk chunk = theme.makeChunk(getBeanName());
    chunk.setLocale(rc.getLocale());
    chunk.setMultiple(model);
    chunk.set(rcKey, mapifyRequestContext(rc, request));

    PrintWriter writer = response.getWriter();
    chunk.render(writer);
    writer.flush();
    writer.close();
}
 
开发者ID:tomj74,项目名称:chunk-springmvc,代码行数:21,代码来源:ChunkTemplateView.java

示例10: mapifyRequestContext

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
private Map<String,String> mapifyRequestContext(RequestContext rc, HttpServletRequest request)
{
    Map<String,String> rcMap = new HashMap<String,String>();

    // expose some potentially useful info to the template via the {$rc} tag
    rcMap.put("uri", rc.getRequestUri());
    rcMap.put("context_path", rc.getContextPath());
    rcMap.put("servlet_path", rc.getPathToServlet());
    rcMap.put("scheme", request.getScheme());
    rcMap.put("method", request.getMethod());
    rcMap.put("server_name", request.getServerName());
    rcMap.put("remote_addr", request.getRemoteAddr());
    rcMap.put("remote_host", request.getRemoteHost());
    rcMap.put("remote_user", request.getRemoteUser());

    return rcMap;
}
 
开发者ID:tomj74,项目名称:chunk-springmvc,代码行数:18,代码来源:ChunkTemplateView.java

示例11: createLayoutFromConfigClass

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@Test
public void createLayoutFromConfigClass() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	MockServletContext servletContext = new MockServletContext();
	context.setServletContext(servletContext);
	context.refresh();
	ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class)
			.resolveViewName("view", Locale.UK);
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	view.render(Collections.singletonMap("foo", "bar"), request, response);
	String result = response.getContentAsString();
	assertTrue("Wrong result: " + result, result.contains("<title>Content</title>"));
	assertTrue("Wrong result: " + result, result.contains("<span>bar</span>"));
	context.close();
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:ThymeleafAutoConfigurationTests.java

示例12: testExposeSpringMacroHelpers

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
public void testExposeSpringMacroHelpers() throws Exception {
	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
			assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
			RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
			BindStatus status = rc.getBindStatus("tb.name");
			assertEquals("name", status.getExpression());
			assertEquals("juergen", status.getValue());
		}
	};
	vv.setUrl(TEMPLATE_FILE);
	vv.setApplicationContext(wac);
	vv.setExposeSpringMacroHelpers(true);

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("tb", new TestBean("juergen", 99));
	vv.render(model, request, response);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:VelocityMacroTests.java

示例13: testRequestContext

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
public void testRequestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:MessageTagTests.java

示例14: testRequestContext

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
public void testRequestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:ThemeTagTests.java

示例15: app

import org.springframework.web.servlet.support.RequestContext; //导入依赖的package包/类
@RequestMapping(value="/app/")
public String app(ModelMap model, HttpServletRequest request, 
		@RequestParam(value="_escaped_fragment_", required=false) String fragment) throws UnsupportedEncodingException {
	
	// render static html for crawlers
	if (fragment != null && !fragment.isEmpty() && fragment.startsWith("/show")) {
		String[] split = URLDecoder.decode(fragment, "UTF-8").split("/");
		return "forward:/doc/" + split[2] + ".html";
	}

	Arrays.sort(idTypes, String.CASE_INSENSITIVE_ORDER);

	model.addAttribute("baseUri",baseUri);
	Locale locale = new RequestContext(request).getLocale();
	model.addAttribute("language", locale.getLanguage());
	model.addAttribute("languages", langHelper.getLocalizedLanguages(locale));
	model.addAttribute("googleMapsApiKey", googleMapsApiKey);
	model.addAttribute("idTypes", idTypes);
	model.addAttribute("placeTypes", placeTypes);
	model.addAttribute("placeTypeGroups", placeTypeGroups);
	model.addAttribute("placeTypeGroupIds", placeTypeGroupIds);
	model.addAttribute("version", version);
	logger.info("accept: {}", request.getHeader("Accept"));
	return "app/index";
}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:26,代码来源:AppController.java


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