Java Code Examples for org.springframework.http.MediaType#APPLICATION_JSON
The following examples show how to use
org.springframework.http.MediaType#APPLICATION_JSON .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityConfig.java From pizzeria with MIT License | 6 votes |
@Bean public LogoutSuccessHandler logoutSuccessHandler() { ContentNegotiationStrategy contentNegotiationStrategy = new HeaderContentNegotiationStrategy(); MediaTypeRequestMatcher jsonMediaTypeRequestMatcher = new MediaTypeRequestMatcher(contentNegotiationStrategy, MediaType.APPLICATION_JSON); jsonMediaTypeRequestMatcher.setUseEquals(true); LinkedHashMap<RequestMatcher, LogoutSuccessHandler> matcherToHandler = new LinkedHashMap<>(); matcherToHandler.put(jsonMediaTypeRequestMatcher, new HttpStatusReturningLogoutSuccessHandler()); DelegatingLogoutSuccessHandler delegatingLogoutSuccessHandler = new DelegatingLogoutSuccessHandler(matcherToHandler); SimpleUrlLogoutSuccessHandler simpleUrlLogoutSuccessHandler = new SimpleUrlLogoutSuccessHandler(); simpleUrlLogoutSuccessHandler.setUseReferer(true); simpleUrlLogoutSuccessHandler.setDefaultTargetUrl("/"); delegatingLogoutSuccessHandler.setDefaultLogoutSuccessHandler(simpleUrlLogoutSuccessHandler); return delegatingLogoutSuccessHandler; }
Example 2
Source File: RestTemplateSender.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
RestTemplateSender(RestTemplate restTemplate, String baseUrl, BytesEncoder<Span> encoder) { this.restTemplate = restTemplate; this.encoding = encoder.encoding(); if (encoder.equals(JSON_V2)) { this.mediaType = MediaType.APPLICATION_JSON; this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v2/spans"; } else if (this.encoding == Encoding.PROTO3) { this.mediaType = MediaType.parseMediaType("application/x-protobuf"); this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v2/spans"; } else if (this.encoding == Encoding.JSON) { this.mediaType = MediaType.APPLICATION_JSON; this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v1/spans"; } else { throw new UnsupportedOperationException( "Unsupported encoding: " + this.encoding.name()); } this.messageEncoder = BytesMessageEncoder.forEncoding(this.encoding); }
Example 3
Source File: JsonViewUtils.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
/** * Render model and view. * * @param model the model * @param response the response */ public static void render(final Object model, final HttpServletResponse response) { try { final MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); jsonConverter.setPrettyPrint(true); final MediaType jsonMimeType = MediaType.APPLICATION_JSON; jsonConverter.write(model, jsonMimeType, new ServletServerHttpResponse(response)); } catch (final Exception e) { throw new RuntimeException(e); } }
Example 4
Source File: ResponseEntityExceptionHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handleHttpMediaTypeNotSupported() { List<MediaType> acceptable = Arrays.asList(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML); Exception ex = new HttpMediaTypeNotSupportedException(MediaType.APPLICATION_JSON, acceptable); ResponseEntity<Object> responseEntity = testException(ex); assertEquals(acceptable, responseEntity.getHeaders().getAccept()); }
Example 5
Source File: ApiClient.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Select the Content-Type header's value from the given array: * if JSON exists in the given array, use it; * otherwise use the first one of the array. * * @param contentTypes The Content-Type array to select from * @return MediaType The Content-Type header to use. If the given array is empty, JSON will be used. */ public MediaType selectHeaderContentType(String[] contentTypes) { if (contentTypes.length == 0) { return MediaType.APPLICATION_JSON; } for (String contentType : contentTypes) { MediaType mediaType = MediaType.parseMediaType(contentType); if (isJsonMime(mediaType)) { return mediaType; } } return MediaType.parseMediaType(contentTypes[0]); }
Example 6
Source File: RequestPredicatesTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void accept() { MediaType json = MediaType.APPLICATION_JSON; RequestPredicate predicate = RequestPredicates.accept(json); MockServerRequest request = MockServerRequest.builder().header("Accept", json.toString()).build(); assertTrue(predicate.test(request)); request = MockServerRequest.builder().header("Accept", MediaType.TEXT_XML_VALUE).build(); assertFalse(predicate.test(request)); }
Example 7
Source File: RequestPredicatesTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void contentType() { MediaType json = MediaType.APPLICATION_JSON; RequestPredicate predicate = RequestPredicates.contentType(json); MockServerRequest request = MockServerRequest.builder().header("Content-Type", json.toString()).build(); assertTrue(predicate.test(request)); request = MockServerRequest.builder().build(); assertFalse(predicate.test(request)); }
Example 8
Source File: ResponseEntityExceptionHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void handleHttpMediaTypeNotSupported() { List<MediaType> acceptable = Arrays.asList(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML); Exception ex = new HttpMediaTypeNotSupportedException(MediaType.APPLICATION_JSON, acceptable); ResponseEntity<Object> responseEntity = testException(ex); assertEquals(acceptable, responseEntity.getHeaders().getAccept()); }
Example 9
Source File: UserSecurityDetailsMessageConverter.java From elucidate-server with MIT License | 4 votes |
public UserSecurityDetailsMessageConverter() { super(MediaType.APPLICATION_JSON); }
Example 10
Source File: AbstractJsonHttpMessageConverter.java From java-technology-stack with MIT License | 4 votes |
public AbstractJsonHttpMessageConverter() { super(MediaType.APPLICATION_JSON, new MediaType("application", "*+json")); setDefaultCharset(DEFAULT_CHARSET); }
Example 11
Source File: AnnotationReferenceCollectionMessageConverter.java From elucidate-server with MIT License | 4 votes |
@Autowired public AnnotationReferenceCollectionMessageConverter(IRIBuilderService iriBuilder) { super(MediaType.APPLICATION_JSON); this.iriBuilder = iriBuilder; }
Example 12
Source File: JsonFormWriter.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Override protected MediaType getContentType() { return MediaType.APPLICATION_JSON; }
Example 13
Source File: AbstractJsonHttpMessageConverter.java From spring-analysis-note with MIT License | 4 votes |
public AbstractJsonHttpMessageConverter() { super(MediaType.APPLICATION_JSON, new MediaType("application", "*+json")); setDefaultCharset(DEFAULT_CHARSET); }
Example 14
Source File: MethodParameterDetailsTest.java From jfilter with Apache License 2.0 | 4 votes |
@Test public void testNullNotEquals() { MethodParameterDetails methodParameterDetails1 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, new FilterFields()); assertNotEquals(methodParameterDetails1, null); }
Example 15
Source File: ObjectMapperCacheITest.java From jfilter with Apache License 2.0 | 4 votes |
@Test public void testFindObjectMapper() { MethodParameterDetails methodParameterDetails = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, new FilterFields()); ObjectMapper objectMapper = objectMapperCache.findObjectMapper(methodParameterDetails); assertNotNull(objectMapper); }
Example 16
Source File: MethodParameterDetailsTest.java From jfilter with Apache License 2.0 | 4 votes |
@Test public void testGetMethodHashCode() { MethodParameterDetails methodParameterDetails = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, new FilterFields()); assertEquals(methodParameterHash, methodParameterDetails.getMethodHashCode()); }
Example 17
Source File: MethodParameterDetailsTest.java From jfilter with Apache License 2.0 | 4 votes |
@Test public void testEqualsCurrentMethod() { MethodParameterDetails methodParameterDetails1 = new MethodParameterDetails(methodParameter, MediaType.APPLICATION_JSON, new FilterFields()); assertEquals(methodParameterDetails1, methodParameterDetails1); }
Example 18
Source File: SecurityGroupMessageConverter.java From elucidate-server with MIT License | 4 votes |
public SecurityGroupMessageConverter() { super(MediaType.APPLICATION_JSON); }
Example 19
Source File: MessageControllerTest.java From holdmail with Apache License 2.0 | 3 votes |
@Test public void shouldServeContentWhenDataIsNull() { Object content = "{}"; MediaType type = MediaType.APPLICATION_JSON; ResponseEntity response = messageControllerSpy.serveContent(content, type); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getHeaders().getContentType()).isEqualTo(type); assertThat(response.getBody()).isEqualTo(content); }
Example 20
Source File: FastJsonHttpMessageConverter.java From mcg-helper with Apache License 2.0 | 2 votes |
public FastJsonHttpMessageConverter() { super(MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED); }