@Override public List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException { String key = exchange.getRequest().getQueryParams().getFirst(getParameterName()); if (!StringUtils.hasText(key)) { return MEDIA_TYPE_ALL_LIST; } key = formatKey(key); MediaType match = this.mediaTypes.get(key); if (match == null) { match = MediaTypeFactory.getMediaType("filename." + key) .orElseThrow(() -> { List<MediaType> supported = new ArrayList<>(this.mediaTypes.values()); return new NotAcceptableStatusException(supported); }); } this.mediaTypes.putIfAbsent(key, match); return Collections.singletonList(match); }
private void testMediaTypeNotAcceptable(String url) { ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON)); Mono<Object> mono = this.handlerMapping.getHandler(exchange); assertError(mono, NotAcceptableStatusException.class, ex -> assertEquals("Invalid supported producible media types", Collections.singletonList(new MediaType("application", "xml")), ex.getSupportedMediaTypes())); }
@Override public List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException { try { List<MediaType> mediaTypes = exchange.getRequest().getHeaders().getAccept(); MediaType.sortBySpecificityAndQuality(mediaTypes); return (!CollectionUtils.isEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST); } catch (InvalidMediaTypeException ex) { String value = exchange.getRequest().getHeaders().getFirst("Accept"); throw new NotAcceptableStatusException( "Could not parse 'Accept' header [" + value + "]: " + ex.getMessage()); } }
private Mono<? extends Void> render(List<View> views, Map<String, Object> model, ServerWebExchange exchange) { for (View view : views) { if (view.isRedirectView()) { return view.render(model, null, exchange); } } List<MediaType> mediaTypes = getMediaTypes(views); MediaType bestMediaType = selectMediaType(exchange, () -> mediaTypes); if (bestMediaType != null) { for (View view : views) { for (MediaType mediaType : view.getSupportedMediaTypes()) { if (mediaType.isCompatibleWith(bestMediaType)) { return view.render(model, mediaType, exchange); } } } } throw new NotAcceptableStatusException(mediaTypes); }
return Mono.error(new NotAcceptableStatusException(getMediaTypesFor(elementType)));
throw new NotAcceptableStatusException(new ArrayList<>(mediaTypes));
return Mono.error(new NotAcceptableStatusException(producibleMediaTypes));
@Override protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException { throw new NotAcceptableStatusException(getAllMediaTypes()); }
@Override protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException { if (this.useJaf) { MediaType mediaType = MediaTypeFactory.getMediaType("file." + key); if (mediaType != null && !MediaType.APPLICATION_OCTET_STREAM.equals(mediaType)) { return mediaType; } } if (!this.ignoreUnknownExtensions) { throw new NotAcceptableStatusException(getAllMediaTypes()); } return null; }
private Mono<? extends Void> render(List<View> views, Map<String, Object> model, ServerWebExchange exchange) { List<MediaType> mediaTypes = getMediaTypes(views); MediaType bestMediaType = selectMediaType(exchange, () -> mediaTypes); if (bestMediaType != null) { for (View view : views) { for (MediaType mediaType : view.getSupportedMediaTypes()) { if (mediaType.isCompatibleWith(bestMediaType)) { return view.render(model, mediaType, exchange); } } } } throw new NotAcceptableStatusException(mediaTypes); }
private List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException { try { List<MediaType> mediaTypes = exchange.getRequest().getHeaders().getAccept(); MediaType.sortBySpecificityAndQuality(mediaTypes); return mediaTypes; } catch (InvalidMediaTypeException ex) { String value = exchange.getRequest().getHeaders().getFirst("Accept"); throw new NotAcceptableStatusException( "Could not parse 'Accept' header [" + value + "]: " + ex.getMessage()); } }
@Override public List<MediaType> resolveMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException { try { List<MediaType> mediaTypes = exchange.getRequest().getHeaders().getAccept(); MediaType.sortBySpecificityAndQuality(mediaTypes); return mediaTypes; } catch (InvalidMediaTypeException ex) { String value = exchange.getRequest().getHeaders().getFirst("Accept"); throw new NotAcceptableStatusException( "Could not parse 'Accept' header [" + value + "]: " + ex.getMessage()); } }
throw new NotAcceptableStatusException(new ArrayList<>(mediaTypes));
return Mono.error(new NotAcceptableStatusException(getProducibleMediaTypes(elementType)));