List of usage examples for org.springframework.http MediaType parseMediaType
public static MediaType parseMediaType(String mediaType)
From source file:org.springframework.web.multipart.commons.CommonsFileUploadSupport.java
private String determineEncoding(String contentTypeHeader, String defaultEncoding) { if (!StringUtils.hasText(contentTypeHeader)) { return defaultEncoding; }/*from w ww . ja v a 2s .co m*/ MediaType contentType = MediaType.parseMediaType(contentTypeHeader); Charset charset = contentType.getCharset(); return (charset != null ? charset.name() : defaultEncoding); }
From source file:org.springframework.web.reactive.result.condition.AbstractMediaTypeExpression.java
AbstractMediaTypeExpression(String expression) { if (expression.startsWith("!")) { this.isNegated = true; expression = expression.substring(1); } else {/*from w w w . j av a 2 s . c om*/ this.isNegated = false; } this.mediaType = MediaType.parseMediaType(expression); }
From source file:org.springframework.web.servlet.view.ContentNegotiatingViewResolver.java
private View getBestView(List<View> candidateViews, List<MediaType> requestedMediaTypes, RequestAttributes attrs) {//from ww w . j ava 2s . c om for (View candidateView : candidateViews) { if (candidateView instanceof SmartView) { SmartView smartView = (SmartView) candidateView; if (smartView.isRedirectView()) { if (logger.isDebugEnabled()) { logger.debug("Returning redirect view [" + candidateView + "]"); } return candidateView; } } } for (MediaType mediaType : requestedMediaTypes) { for (View candidateView : candidateViews) { if (StringUtils.hasText(candidateView.getContentType())) { MediaType candidateContentType = MediaType.parseMediaType(candidateView.getContentType()); if (mediaType.isCompatibleWith(candidateContentType)) { if (logger.isDebugEnabled()) { logger.debug("Returning [" + candidateView + "] based on requested media type '" + mediaType + "'"); } attrs.setAttribute(View.SELECTED_CONTENT_TYPE, mediaType, RequestAttributes.SCOPE_REQUEST); return candidateView; } } } } return null; }
From source file:org.talend.components.service.rest.impl.PropertiesControllerImpl.java
@Override public ResponseEntity<InputStreamResource> getIcon(String definitionName, DefinitionImageType imageType) { notNull(definitionName, "Definition name cannot be null."); notNull(imageType, "Definition image type cannot be null."); final Definition<?> definition = propertiesHelpers.getDefinition(definitionName); notNull(definition, "Could not find definition of name %s", definitionName); // Undefined and missing icon resources are simply 404. String imagePath = definition.getImagePath(imageType); if (imagePath == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); }//from w ww . j a va2 s . c o m InputStream is = definition.getClass().getResourceAsStream(imagePath); if (is == null) { log.info("The image type %s should exist for %s at %s, but is missing. " + "The component should provide this resource.", imageType, definitionName, imagePath); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } // At this point, we have enough information for a correct response. ResponseEntity.BodyBuilder response = ResponseEntity.ok(); // Add the content type if it can be determined. MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); String contentType = mimeTypesMap.getContentType(imagePath); if (contentType != null) { response = response.contentType(MediaType.parseMediaType(contentType)); } return response.body(new InputStreamResource(is)); }
From source file:org.venice.beachfront.bfapi.geoserver.GeoserverEnvironment.java
private void installStyle() { authHeaders.setContentType(MediaType.parseMediaType("application/vnd.ogc.sld+xml")); final String styleURL = String.format("%s/styles?name=%s", getWorkspaceBaseUrl(), STYLE_NAME); try {// w w w. j ava2 s. c o m final HttpEntity<String> request = new HttpEntity<>(getStyleCreationPayload(), authHeaders.get()); restTemplate.exchange(styleURL, HttpMethod.POST, request, String.class); piazzaLogger.log("GeoServer Style Layer created successfully.", Severity.INFORMATIONAL); } catch (final HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger .log(String.format("HTTP Error occurred while trying to create Beachfront GeoServer Style: %s", exception.getResponseBodyAsString()), Severity.ERROR); determineExit(); } catch (final IOException | URISyntaxException | ResourceAccessException exception) { piazzaLogger.log(String.format("Unexpected Error Reading GeoServer Style XML with message %s", exception.getMessage()), Severity.ERROR); } }
From source file:org.venice.beachfront.bfapi.geoserver.GeoserverEnvironment.java
private void installLayerGroup() { authHeaders.setContentType(MediaType.parseMediaType("application/xml")); final String layerGroupURL = String.format("%s/layergroups", getWorkspaceBaseUrl()); try {//w ww . ja v a2 s. co m final HttpEntity<String> request = new HttpEntity<>(getLayerGroupCreationPayload(), authHeaders.get()); restTemplate.exchange(layerGroupURL, HttpMethod.POST, request, String.class); piazzaLogger.log("GeoServer Layer Group created successfully.", Severity.INFORMATIONAL); } catch (final HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log( String.format("HTTP Error occurred while trying to create Beachfront GeoServer Layer Group: %s", exception.getResponseBodyAsString()), Severity.ERROR); determineExit(); } catch (final IOException | URISyntaxException | ResourceAccessException exception) { piazzaLogger.log(String.format("Unexpected Error Reading GeoServer Layer Group XML with message %s", exception.getMessage()), Severity.ERROR); } }