Package org.springframework.http

Examples of org.springframework.http.MediaType


        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
        // Add JSON message handler
        MappingJackson2HttpMessageConverter json = new MappingJackson2HttpMessageConverter();
        List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
        supportedMediaTypes.add(new MediaType("application","json", Charset.forName("UTF-8")));
        // Add default media type in case marketplace uses incorrect MIME type, otherwise
        // Spring refuses to process it, even if its valid JSON
        supportedMediaTypes.add(new MediaType("application","octet-stream", Charset.forName("UTF-8")));
        json.setSupportedMediaTypes(supportedMediaTypes);
        mc.add(json);
        restTemplate.setMessageConverters(mc);
        return restTemplate;
    }
View Full Code Here


    MultiValueMap<String, Object> multipartMap = new LinkedMultiValueMap<String, Object>();
    multipartMap.add("company", "SpringSource");
    multipartMap.add("company-logo", s2logo);
    logger.info("Created multipart request: " + multipartMap);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity<Object> request = new HttpEntity<Object>(multipartMap, headers);
    logger.info("Posting request to: " + uri);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, Object.class);
    if (!httpResponse.getStatusCode().equals(HttpStatus.OK)){
      logger.error("Problems with the request. Http status: " + httpResponse.getStatusCode());
View Full Code Here

        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
        // Add JSON message handler
        MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
        List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
        supportedMediaTypes.add(new MediaType("application","json", Charset.forName("UTF-8")));
        // Add default media type in case marketplace uses incorrect MIME type, otherwise
        // Spring refuses to process it, even if its valid JSON
        supportedMediaTypes.add(new MediaType("application","octet-stream", Charset.forName("UTF-8")));
        json.setSupportedMediaTypes(supportedMediaTypes);
        mc.add(json);
        restTemplate.setMessageConverters(mc);
        return restTemplate;
    }
View Full Code Here

        }
        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);
    }
View Full Code Here

    }


    @Test
    public void javadocApplicationAllJsonUseEquals() {
        request.addHeader("Accept", new MediaType("application","*"));
        MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.APPLICATION_JSON);
        matcher.setUseEquals(true);
        assertThat(matcher.matches(request)).isFalse();
    }
View Full Code Here

    @Test
    public void resolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
        when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));

        matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text","*"));
        assertThat(matcher.matches(request)).isTrue();
    }
View Full Code Here

        assertThat(matcher.matches(request)).isTrue();
    }

    @Test
    public void resolveTextAllMatchesTextPlain() throws HttpMediaTypeNotAcceptableException {
        when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text","*")));

        matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
        assertThat(matcher.matches(request)).isTrue();
    }
View Full Code Here

    // useEquals

    @Test
    public void useEqualsResolveTextAllMatchesTextPlain() throws HttpMediaTypeNotAcceptableException {
        when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text","*")));

        matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_PLAIN);
        matcher.setUseEquals(true);
        assertThat(matcher.matches(request)).isFalse();
    }
View Full Code Here

    @Test
    public void useEqualsResolveTextPlainMatchesTextAll() throws HttpMediaTypeNotAcceptableException {
        when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN));

        matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text","*"));
        matcher.setUseEquals(true);
        assertThat(matcher.matches(request)).isFalse();
    }
View Full Code Here

        assertThat(matcher.matches(request)).isTrue();
    }

    @Test
    public void useEqualsWithCustomMediaType() throws HttpMediaTypeNotAcceptableException {
        when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(new MediaType("text","unique")));

        matcher = new MediaTypeRequestMatcher(negotiationStrategy, new MediaType("text","unique"));
        matcher.setUseEquals(true);
        assertThat(matcher.matches(request)).isTrue();
    }
View Full Code Here

TOP

Related Classes of org.springframework.http.MediaType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.