Spring Framework HeaderContentNegotiationStrategy - 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 HeaderContentNegotiationStrategy class.

This code example shows how to use the following methods:
 
    private ContentNegotiationStrategy negotiationStrategy;
 
    @Before 
    public void setup() { 
        negotiationStrategy = new HeaderContentNegotiationStrategy();
        request = new MockHttpServletRequest();
    } 
 
    @Test
    public void mediaAllMatches() { 
        request.addHeader("Accept", MediaType.ALL_VALUE);
        matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
 
        assertThat(matcher.matches(request)).isTrue();
 
        matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_XHTML_XML);
        assertThat(matcher.matches(request)).isTrue();
    } 
 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
    @SuppressWarnings("unchecked") 
    private RequestMatcher createDefaultSavedRequestMatcher(H http) {
        ContentNegotiationStrategy contentNegotiationStrategy = http.getSharedObject(ContentNegotiationStrategy.class);
        if(contentNegotiationStrategy == null) {
            contentNegotiationStrategy = new HeaderContentNegotiationStrategy();
        } 
 
        RequestMatcher notFavIcon = new NegatedRequestMatcher(new AntPathRequestMatcher("/**/favicon.ico"));
 
        MediaTypeRequestMatcher jsonRequest = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.APPLICATION_JSON);
        jsonRequest.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
        RequestMatcher notJson = new NegatedRequestMatcher(jsonRequest);
 
        RequestMatcher notXRequestedWith = new NegatedRequestMatcher(new RequestHeaderRequestMatcher("X-Requested-With","XMLHttpRequest"));
 
        boolean isCsrfEnabled = http.getConfigurer(CsrfConfigurer.class) != null;
 
        List<RequestMatcher> matchers = new ArrayList<RequestMatcher>();
        if(isCsrfEnabled) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		if (exceptionHandling == null) {
			return; 
		} 
		ContentNegotiationStrategy contentNegotiationStrategy = http.getSharedObject(ContentNegotiationStrategy.class);
		if (contentNegotiationStrategy == null) {
			contentNegotiationStrategy = new HeaderContentNegotiationStrategy();
		} 
		MediaTypeRequestMatcher preferredMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy,
				MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON,
				MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_XML, MediaType.MULTIPART_FORM_DATA,
				MediaType.TEXT_XML);
		preferredMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
		exceptionHandling.defaultAuthenticationEntryPointFor(postProcess(authenticationEntryPoint), preferredMatcher);
	} 
 
	public ResourceServerSecurityConfigurer resourceId(String resourceId) {
		this.resourceId = resourceId;
		if (authenticationEntryPoint instanceof OAuth2AuthenticationEntryPoint) {
			((OAuth2AuthenticationEntryPoint) authenticationEntryPoint).setRealmName(resourceId);
		} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        if(exceptionHandling == null) {
            return; 
        } 
        ContentNegotiationStrategy contentNegotiationStrategy = http.getSharedObject(ContentNegotiationStrategy.class);
        if(contentNegotiationStrategy == null) {
            contentNegotiationStrategy = new HeaderContentNegotiationStrategy();
        } 
        MediaTypeRequestMatcher preferredMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.APPLICATION_XHTML_XML, new MediaType("image","*"), MediaType.TEXT_HTML, MediaType.TEXT_PLAIN);
        preferredMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
        exceptionHandling.defaultAuthenticationEntryPointFor(postProcess(authenticationEntryPoint), preferredMatcher);
    } 
 
    @Override 
    public void configure(B http) throws Exception {
        PortMapper portMapper = http.getSharedObject(PortMapper.class);
        if(portMapper != null) {
            authenticationEntryPoint.setPortMapper(portMapper);
        } 
 
        authFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
    @Override 
    public void afterPropertiesSet() { 
        if (contentNegotiationManager == null) { 
            contentNegotiationManager = new ContentNegotiationManager( 
                    new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(defaultContentType)); 
        } 
        responseProcessor = new HttpEntityMethodProcessor(messageConverters, contentNegotiationManager); 
        fallbackResponseProcessor = new HttpEntityMethodProcessor(messageConverters, 
                new ContentNegotiationManager(new FixedContentNegotiationStrategy(defaultContentType))); 
    } 
 
    @Override 
    protected ModelAndView doResolveException( 
            HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { 
 
        ResponseEntity<?> entity; 
        try { 
            entity = handleException(exception, request); 
        } catch (NoExceptionHandlerFoundException ex) { 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java