Spring Framework ServletRequestAttributes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ServletRequestAttributes class.

This code example shows how to use the following methods:requestCompleted
	@Override 
	protected void doFilterInternal( 
			HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 
			throws ServletException, IOException { 
 
		ServletRequestAttributes attributes = new ServletRequestAttributes(request, response); 
		initContextHolders(request, attributes); 
 
		try { 
			filterChain.doFilter(request, response); 
		} 
		finally { 
			resetContextHolders(); 
			if (logger.isDebugEnabled()) { 
				logger.debug("Cleared thread-bound request context: " + request); 
			} 
			attributes.requestCompleted(); 
		} 
	} 
 

6
CodeRank
This code example shows how to use the following methods:
		resolver.resolveArgument(tokenParameter, request); 
	} 
 
	@Test 
	public void resolveArgument_noCookies_unrequired() throws Exception { 
		NativeWebRequest request = new ServletWebRequest(new MockHttpServletRequest()); 
		Method method = FacebookArgumentResolverTest.class.getDeclaredMethod("unrequiredAnnotatedMethod", String.class, 
				String.class, String.class); 
 
		MethodParameter idParameter = new MethodParameter(method, 0); 
		assertEquals(null, resolver.resolveArgument(idParameter, request)); 
 
		MethodParameter tokenParameter = new MethodParameter(method, 1); 
		assertEquals(null, resolver.resolveArgument(tokenParameter, request)); 
	} 
 
	@Test(expected = IllegalStateException.class) 
	public void resolveFacebookUserIdArgument_noFacebookCookie_required() throws Exception { 
		MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 
		httpServletRequest.setCookies(new Cookie("not_a_facebook_cookie", "doesn't matter")); 
6
CodeRank
This code example shows how to use the following methods:getRequest
	@Override 
	protected NativeWebRequest getWebRequest() { 
		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); 
		if (requestAttributes instanceof ServletRequestAttributes) { 
			ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes; 
			return new ServletWebRequest(servletRequestAttributes.getRequest()); 
		} 
		return null; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:
	 
	@Test 
	public void resolveArgument_dauthorizationRequest_object() throws Exception { 
		MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 
		httpServletRequest.setParameter("signed_request", DEAUTH_CALLBACK); 
		NativeWebRequest request = new ServletWebRequest(httpServletRequest);  
		Method method = SignedRequestArgumentResolverTest.class.getDeclaredMethod("annotatedMethod", DeauthorizationRequest.class, Map.class, MultiValueMap.class, String.class); 
		MethodParameter deauthParameter = new MethodParameter(method, 0); 
		DeauthorizationRequest resolved = (DeauthorizationRequest) resolver.resolveArgument(deauthParameter, null, request, null); 
		assertEquals("HMAC-SHA256", resolved.getAlgorithm()); 
		assertEquals(1335894796, resolved.getIssuedAt()); 
		assertEquals("738140579", resolved.getUserId()); 
		assertEquals("us", resolved.getUser().getCountry()); 
		assertEquals("en_US", resolved.getUser().getLocale()); 
	} 
	 
	@Test 
	@SuppressWarnings({ "unused", "unchecked" }) 
	public void resolveArgument_dauthorizationRequest_map() throws Exception { 
		MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 
6
CodeRank
This code example shows how to use the following methods:
 */ 
public abstract class AbstractHttpInboundTests { 
 
	@Before 
	public void setupHttpInbound() { 
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest())); 
	} 
 
	@After 
	public void tearDownHttpInbound() { 
		RequestContextHolder.resetRequestAttributes(); 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 
	@Test 
	public void fromCurrentRequest() { 
		request.setRequestURI("/mvc-showcase/data/param"); 
		request.setQueryString("foo=123"); 
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request)); 
		try { 
			String result = ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString(); 
			assertEquals("http://localhost/mvc-showcase/data/param?foo=123", result); 
		} 
		finally { 
			RequestContextHolder.resetRequestAttributes(); 
		} 
	} 
 
	// SPR-10272 
 
	@Test 
	public void pathExtension() { 
		this.request.setRequestURI("/rest/books/6.json"); 
5
CodeRank
This code example shows how to use the following methods:
	 * Initializes web tests. Will register a {@link MockHttpServletRequest} for the current thread. 
	 */ 
	public static void initWebTest() { 
 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); 
		RequestContextHolder.setRequestAttributes(requestAttributes); 
	} 
 
	/** 
	 * Creates a {@link WebApplicationContext} from the given configuration classes. 
	 *  
	 * @param configClasses 
	 * @return 
	 */ 
	public static WebApplicationContext createApplicationContext(Class<?>... configClasses) { 
 
		AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
		context.setServletContext(new MockServletContext()); 
 
5
CodeRank
This code example shows how to use the following methods:getRequest
	public String removePathExtension() { 
		String extension = null; 
		if (this.servletRequestURI != null) { 
			String filename = WebUtils.extractFullFilenameFromUrlPath(this.servletRequestURI); 
			extension = StringUtils.getFilenameExtension(filename); 
			if (!StringUtils.isEmpty(extension)) { 
				int end = this.servletRequestURI.length() - (extension.length() + 1); 
				replacePath(this.servletRequestURI.substring(0, end)); 
			} 
			this.servletRequestURI = null; 
		} 
		return extension; 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 * @author Oliver Gierke 
 */ 
class TestUtils { 
 
	public static NativeWebRequest getWebRequest() { 
		return new ServletWebRequest(new MockHttpServletRequest()); 
	} 
 
	public static MethodParameter getParameterOfMethod(Class<?> controller, String name, Class<?>... argumentTypes) { 
 
		Method method = getMethod(controller, name, argumentTypes); 
		return new MethodParameter(method, 0); 
	} 
 
	public static Method getMethod(Class<?> controller, String name, Class<?>... argumentTypes) { 
 
		try { 
			return controller.getMethod(name, argumentTypes); 
		} catch (Exception e) { 
			throw new RuntimeException(e); 
5
CodeRank
This code example shows how to use the following methods:
	public void returnsNullIfFallbackIsNullAndNoParametersGiven() throws Exception { 
 
		PageableHandlerMethodArgumentResolver resolver = getResolver(); 
		resolver.setFallbackPageable(null); 
 
		assertSupportedAndResult(supportedMethodParameter, null, new ServletWebRequest(new MockHttpServletRequest()), 
				resolver); 
	} 
 
	/** 
	 * @see DATACMNS-477 
	 */ 
	@Test 
	public void returnsNullIfFallbackIsNullAndOnlyPageIsGiven() throws Exception { 
 
		PageableHandlerMethodArgumentResolver resolver = getResolver(); 
		resolver.setFallbackPageable(null); 
 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		request.addParameter("page", "20"); 
5
CodeRank
See Code Examples for Spring Framework ServletRequestAttributes Methods: