List of usage examples for org.springframework.http MediaType isWildcardSubtype
public boolean isWildcardSubtype()
*
or the wildcard character followed by a suffix (e.g. From source file:org.cloudfoundry.client.lib.rest.UploadApplicationPayloadHttpMessageConverter.java
private void setOutputContentType(MediaType contentType, HttpOutputMessage outputMessage) { HttpHeaders headers = outputMessage.getHeaders(); if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { contentType = MediaType.APPLICATION_OCTET_STREAM; }// w ww .j a v a2 s .co m if (contentType != null) { headers.setContentType(contentType); } }
From source file:org.cloudfoundry.client.lib.util.UploadApplicationPayloadHttpMessageConverter.java
public void write(UploadApplicationPayload t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { HttpHeaders headers = outputMessage.getHeaders(); if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { contentType = MediaType.APPLICATION_OCTET_STREAM; }//from w w w . ja v a 2s.com if (contentType != null) { headers.setContentType(contentType); } FileCopyUtils.copy(t.getInputStream(), outputMessage.getBody()); outputMessage.getBody().flush(); }
From source file:com.tasktop.c2c.server.internal.wiki.server.domain.validation.AttachmentValidator.java
@Override public void validate(Object target, Errors errors) { Attachment attachment = (Attachment) target; ValidationUtils.rejectIfEmpty(errors, "page", "field.required"); ValidationUtils.rejectIfEmpty(errors, "name", "field.required"); if (attachment.getName() != null && !NAME_PATTERN.matcher(attachment.getName()).matches()) { errors.rejectValue("name", "invalidValue", new Object[] { attachment.getName() }, "invalid name"); }/*from w w w. j a va2 s . com*/ if (attachment.getMimeType() != null) { MediaType mediaType = null; try { mediaType = MediaType.parseMediaType(attachment.getMimeType()); } catch (IllegalArgumentException e) { errors.rejectValue("mimeType", "invalidFormat"); } if (mediaType != null) { if (mediaType.isWildcardType() || mediaType.isWildcardSubtype()) { errors.rejectValue("mimeType", "mediaTypeWildcardNotAllowed"); } else if (!mediaTypes.isSupported(mediaType)) { errors.rejectValue("mimeType", "mediaTypeNotPermissible", new Object[] { attachment.getMimeType() }, "bad mime type"); } } } if (attachment.getContent() == null || attachment.getContent().length == 0) { errors.rejectValue("content", "field.required"); } else { int attachementSize = attachment.getContent().length; if (attachementSize > configuration.getMaxAttachmentSize()) { errors.rejectValue("content", "field.tooLarge", new Object[] { FileUtils.byteCountToDisplaySize(configuration.getMaxAttachmentSize()) }, "Field to large"); } } }
From source file:org.springframework.http.converter.AbstractHttpMessageConverter.java
/** * Add default headers to the output message. * <p>This implementation delegates to {@link #getDefaultContentType(Object)} if a * content type was not provided, set if necessary the default character set, calls * {@link #getContentLength}, and sets the corresponding headers. * @since 4.2// w w w. j a v a2s. c om */ protected void addDefaultHeaders(HttpHeaders headers, T t, @Nullable MediaType contentType) throws IOException { if (headers.getContentType() == null) { MediaType contentTypeToUse = contentType; if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { contentTypeToUse = getDefaultContentType(t); } else if (MediaType.APPLICATION_OCTET_STREAM.equals(contentType)) { MediaType mediaType = getDefaultContentType(t); contentTypeToUse = (mediaType != null ? mediaType : contentTypeToUse); } if (contentTypeToUse != null) { if (contentTypeToUse.getCharset() == null) { Charset defaultCharset = getDefaultCharset(); if (defaultCharset != null) { contentTypeToUse = new MediaType(contentTypeToUse, defaultCharset); } } headers.setContentType(contentTypeToUse); } } if (headers.getContentLength() < 0 && !headers.containsKey(HttpHeaders.TRANSFER_ENCODING)) { Long contentLength = getContentLength(t, headers.getContentType()); if (contentLength != null) { headers.setContentLength(contentLength); } } }