當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletWebRequest類代碼示例

本文整理匯總了Java中org.springframework.web.context.request.ServletWebRequest的典型用法代碼示例。如果您正苦於以下問題:Java ServletWebRequest類的具體用法?Java ServletWebRequest怎麽用?Java ServletWebRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServletWebRequest類屬於org.springframework.web.context.request包,在下文中一共展示了ServletWebRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: signIn

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Override
public String signIn(String userId, Connection<?> connection, NativeWebRequest request){
    try {
        UserDetails user = userDetailsService.loadUserByUsername(userId);
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
            user,
            null,
            user.getAuthorities());

        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
        String jwt = tokenProvider.createToken(authenticationToken, false);
        ServletWebRequest servletWebRequest = (ServletWebRequest) request;
        servletWebRequest.getResponse().addCookie(getSocialAuthenticationCookie(jwt));
    } catch (AuthenticationException exception) {
        log.error("Social authentication error");
    }
    return jHipsterProperties.getSocial().getRedirectAfterSignIn();
}
 
開發者ID:AppertaFoundation,項目名稱:Code4Health-Platform,代碼行數:19,代碼來源:CustomSignInAdapter.java

示例2: signIn

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Override
public String signIn(String userId, Connection<?> connection, NativeWebRequest request){
    try {
        UserDetails user = userDetailsService.loadUserByUsername(userId);
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
            user,
            null,
            user.getAuthorities());

        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
        String jwt = tokenProvider.createToken(authenticationToken, false);
        ServletWebRequest servletWebRequest = (ServletWebRequest) request;
        servletWebRequest.getResponse().addCookie(getSocialAuthenticationCookie(jwt));
    } catch (AuthenticationException ae) {
        log.error("Social authentication error");
        log.trace("Authentication exception trace: {}", ae);
    }
    return jHipsterProperties.getSocial().getRedirectAfterSignIn();
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:CustomSignInAdapter.java

示例3: handleHttpEntityResponse

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
public void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
    if (responseEntity == null) {
        return;
    }

    HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
    HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
    if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
        ((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
    }

    HttpHeaders entityHeaders = responseEntity.getHeaders();
    if (!entityHeaders.isEmpty()) {
        outputMessage.getHeaders().putAll(entityHeaders);
    }

    Object body = responseEntity.getBody();
    if (body != null) {
        writeWithMessageConverters(body, inputMessage, outputMessage);
    }
    else {
        outputMessage.getBody();
    }
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:25,代碼來源:RestExceptionRenderer.java

示例4: doResolveException

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Override
protected ModelAndView doResolveException(
		HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

	if (handler != null) {
		Method handlerMethod = findBestExceptionHandlerMethod(handler, ex);
		if (handlerMethod != null) {
			ServletWebRequest webRequest = new ServletWebRequest(request, response);
			try {
				Object[] args = resolveHandlerArguments(handlerMethod, handler, webRequest, ex);
				if (logger.isDebugEnabled()) {
					logger.debug("Invoking request handler method: " + handlerMethod);
				}
				Object retVal = doInvokeMethod(handlerMethod, handler, args);
				return getModelAndView(handlerMethod, retVal, webRequest);
			}
			catch (Exception invocationEx) {
				logger.error("Invoking request method resulted in exception : " + handlerMethod, invocationEx);
			}
		}
	}
	return null;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:AnnotationMethodHandlerExceptionResolver.java

示例5: handleCustomException

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
protected ModelAndView handleCustomException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
	ServletWebRequest webRequest = new ServletWebRequest(request, response);

	RestError error = errorResolver.resolveError(ex);
	if (error == null) {
		return null;
	}
	applyStatusIfPossible(webRequest, error.getHttpStatus());

	try {
		return handleResponseBody(error.getErrorRS(), webRequest);
	} catch (IOException e) {
		if (logger.isWarnEnabled()) {
			logger.warn("Unable to write error message", e);
		}
		return null;
	}
}
 
開發者ID:reportportal,項目名稱:commons-rules,代碼行數:19,代碼來源:RestExceptionHandler.java

示例6: setUp

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
	this.resolver = new MatrixVariableMethodArgumentResolver();

	Method method = getClass().getMethod("handle", String.class, List.class, int.class);
	this.paramString = new MethodParameter(method, 0);
	this.paramColors = new MethodParameter(method, 1);
	this.paramYear = new MethodParameter(method, 2);

	this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());

	this.mavContainer = new ModelAndViewContainer();
	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse());

	Map<String, MultiValueMap<String, String>> params = new LinkedHashMap<String, MultiValueMap<String, String>>();
	this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:MatrixVariablesMethodArgumentResolverTests.java

示例7: setup

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Before
public void setup() throws Exception {
	ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
	bindingInitializer.setValidator(new StubValidator());

	List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>();
	customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));

	GenericWebApplicationContext context = new GenericWebApplicationContext();
	context.refresh();

	handlerAdapter = new RequestMappingHandlerAdapter();
	handlerAdapter.setWebBindingInitializer(bindingInitializer);
	handlerAdapter.setCustomArgumentResolvers(customResolvers);
	handlerAdapter.setApplicationContext(context);
	handlerAdapter.setBeanFactory(context.getBeanFactory());
	handlerAdapter.afterPropertiesSet();

	request = new MockHttpServletRequest();
	response = new MockHttpServletResponse();

	request.setMethod("POST");

	// Expose request to the current thread (for SpEL expressions)
	RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:RequestMappingHandlerAdapterIntegrationTests.java

示例8: setUp

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

	List<HttpMessageConverter<?>> converters = Arrays.asList(
			new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter());

	this.handler = new ResponseBodyEmitterReturnValueHandler(converters);
	this.mavContainer = new ModelAndViewContainer();

	this.request = new MockHttpServletRequest();
	this.response = new MockHttpServletResponse();
	this.webRequest = new ServletWebRequest(this.request, this.response);

	AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
	WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest);
	this.request.setAsyncSupported(true);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ResponseBodyEmitterReturnValueHandlerTests.java

示例9: setUp

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
	messageConverter = mock(HttpMessageConverter.class);
	given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));

	processor = new RequestResponseBodyMethodProcessor(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));

	Method methodHandle1 = getClass().getMethod("handle1", String.class, Integer.TYPE);
	paramRequestBodyString = new MethodParameter(methodHandle1, 0);
	paramInt = new MethodParameter(methodHandle1, 1);
	returnTypeString = new MethodParameter(methodHandle1, -1);
	returnTypeInt = new MethodParameter(getClass().getMethod("handle2"), -1);
	returnTypeStringProduces = new MethodParameter(getClass().getMethod("handle3"), -1);
	paramValidBean = new MethodParameter(getClass().getMethod("handle4", SimpleBean.class), 0);
	paramStringNotRequired = new MethodParameter(getClass().getMethod("handle5", String.class), 0);

	mavContainer = new ModelAndViewContainer();

	servletRequest = new MockHttpServletRequest();
	servletRequest.setMethod("POST");
	webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:RequestResponseBodyMethodProcessorMockTests.java

示例10: setUp

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Before
public void setUp() {
	ServletContext servletContext = new MockServletContext();
	MockHttpServletRequest mockRequest = new MockHttpServletRequest(servletContext);
	mockRequest.setAttribute(FROM_CUSTOM_MOCK, FROM_CUSTOM_MOCK);
	RequestContextHolder.setRequestAttributes(new ServletWebRequest(mockRequest, new MockHttpServletResponse()));

	this.wac.setServletContext(servletContext);
	new AnnotatedBeanDefinitionReader(this.wac).register(WebConfig.class);
	this.wac.refresh();

	this.mockMvc = webAppContextSetup(this.wac)
			.defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT))
			.alwaysExpect(status().isOk())
			.build();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:CustomRequestAttributesRequestContextHolderTests.java

示例11: authenticate

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Override
public RedirectView authenticate(final WebRequest request) {
    try {
        final Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);

        final User user = socialUserService.create(connection);

        final String jwt = tokenService.getToken(user.getUsername(), user.getPassword());

        final ServletWebRequest servletWebRequest = (ServletWebRequest) request;

        servletWebRequest.getResponse().addCookie(getSocialAuthenticationCookie(jwt));

        return new RedirectView(URIBuilder.fromUri(redirectUrl)
                .build().toString(), true);
    } catch (Exception e) {
        return new RedirectView(URIBuilder.fromUri(redirectUrl)
                .queryParam("success", "false")
                .build().toString(), true);
    }
}
 
開發者ID:vlsidlyarevich,項目名稱:unity,代碼行數:22,代碼來源:DefaultSocialAuthenticationService.java

示例12: assertContentDisposition

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
private void assertContentDisposition(RequestResponseBodyMethodProcessor processor,
		boolean expectContentDisposition, String requestURI, String comment) throws Exception {

	this.servletRequest.setRequestURI(requestURI);
	processor.handleReturnValue("body", this.returnTypeString, this.mavContainer, this.webRequest);

	String header = servletResponse.getHeader("Content-Disposition");
	if (expectContentDisposition) {
		assertEquals("Expected 'Content-Disposition' header. Use case: '" + comment + "'",
				"inline;filename=f.txt", header);
	}
	else {
		assertNull("Did not expect 'Content-Disposition' header. Use case: '" + comment + "'", header);
	}

	this.servletRequest = new MockHttpServletRequest();
	this.servletResponse = new MockHttpServletResponse();
	this.webRequest = new ServletWebRequest(servletRequest, servletResponse);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:RequestResponseBodyMethodProcessorTests.java

示例13: getInputStream

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Override
public ServletInputStream getInputStream() throws IOException {
	Object body = body();
	MethodParameter output = new MethodParameter(
			ClassUtils.getMethod(BodySender.class, "body"), -1);
	ServletOutputToInputConverter response = new ServletOutputToInputConverter(
			this.response);
	ServletWebRequest webRequest = new ServletWebRequest(this.request, response);
	try {
		delegate.handleReturnValue(body, output, mavContainer, webRequest);
	}
	catch (HttpMessageNotWritableException
			| HttpMediaTypeNotAcceptableException e) {
		throw new IllegalStateException("Cannot convert body", e);
	}
	return response.getInputStream();
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-gateway,代碼行數:18,代碼來源:ProxyExchange.java

示例14: testContentNegotiationManager

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Test
public void testContentNegotiationManager() throws Exception {
	loadBeanDefinitions("mvc-config-content-negotiation-manager.xml", 15);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	ContentNegotiationManager manager = mapping.getContentNegotiationManager();

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
	NativeWebRequest webRequest = new ServletWebRequest(request);
	assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));

	ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
	assertNotNull(compositeResolver);
	assertEquals("Actual: " + compositeResolver.getViewResolvers(), 1, compositeResolver.getViewResolvers().size());

	ViewResolver resolver = compositeResolver.getViewResolvers().get(0);
	assertEquals(ContentNegotiatingViewResolver.class, resolver.getClass());
	ContentNegotiatingViewResolver cnvr = (ContentNegotiatingViewResolver) resolver;
	assertSame(manager, cnvr.getContentNegotiationManager());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:MvcNamespaceTests.java

示例15: setUp

import org.springframework.web.context.request.ServletWebRequest; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
	processor = new ModelAttributeMethodProcessor(false);

	Method method = ModelAttributeHandler.class.getDeclaredMethod("modelAttribute",
			TestBean.class, Errors.class, int.class, TestBean.class, TestBean.class);

	paramNamedValidModelAttr = new MethodParameter(method, 0);
	paramErrors = new MethodParameter(method, 1);
	paramInt = new MethodParameter(method, 2);
	paramModelAttr = new MethodParameter(method, 3);
	paramNonSimpleType = new MethodParameter(method, 4);

	returnParamNamedModelAttr = new MethodParameter(getClass().getDeclaredMethod("annotatedReturnValue"), -1);
	returnParamNonSimpleType = new MethodParameter(getClass().getDeclaredMethod("notAnnotatedReturnValue"), -1);

	mavContainer = new ModelAndViewContainer();

	webRequest = new ServletWebRequest(new MockHttpServletRequest());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ModelAttributeMethodProcessorTests.java


注:本文中的org.springframework.web.context.request.ServletWebRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。