List of usage examples for org.springframework.http MediaType isWildcardType
public boolean isWildcardType()
*
or not. 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 w w .j av a 2 s . c om if (contentType != null) { headers.setContentType(contentType); } }
From source file:org.mitre.openid.connect.web.UserInfoEndpoint.java
/** * Get information about the user as specified in the accessToken included in this request *///from w w w . j av a2 s . c o m @PreAuthorize("hasRole('ROLE_USER') and #oauth2.hasScope('" + SystemScopeService.OPENID_SCOPE + "')") @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE, UserInfoJWTView.JOSE_MEDIA_TYPE_VALUE }) public String getInfo(@RequestParam(value = "claims", required = false) String claimsRequestJsonString, @RequestHeader(value = HttpHeaders.ACCEPT, required = false) String acceptHeader, OAuth2Authentication auth, Model model) { if (auth == null) { logger.error("getInfo failed; no principal. Requester is not authorized."); model.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN); return HttpCodeView.VIEWNAME; } String username = auth.getName(); UserInfo userInfo = userInfoService.getByUsernameAndClientId(username, auth.getOAuth2Request().getClientId()); if (userInfo == null) { logger.error("getInfo failed; user not found: " + username); model.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND); return HttpCodeView.VIEWNAME; } model.addAttribute(UserInfoView.SCOPE, auth.getOAuth2Request().getScope()); model.addAttribute(UserInfoView.AUTHORIZED_CLAIMS, auth.getOAuth2Request().getExtensions().get("claims")); if (!Strings.isNullOrEmpty(claimsRequestJsonString)) { model.addAttribute(UserInfoView.REQUESTED_CLAIMS, claimsRequestJsonString); } model.addAttribute(UserInfoView.USER_INFO, userInfo); // content negotiation // start off by seeing if the client has registered for a signed/encrypted JWT from here ClientDetailsEntity client = clientService.loadClientByClientId(auth.getOAuth2Request().getClientId()); model.addAttribute(UserInfoJWTView.CLIENT, client); List<MediaType> mediaTypes = MediaType.parseMediaTypes(acceptHeader); MediaType.sortBySpecificityAndQuality(mediaTypes); if (client.getUserInfoSignedResponseAlg() != null || client.getUserInfoEncryptedResponseAlg() != null || client.getUserInfoEncryptedResponseEnc() != null) { // client has a preference, see if they ask for plain JSON specifically on this request for (MediaType m : mediaTypes) { if (!m.isWildcardType() && m.isCompatibleWith(UserInfoJWTView.JOSE_MEDIA_TYPE)) { return UserInfoJWTView.VIEWNAME; } else if (!m.isWildcardType() && m.isCompatibleWith(MediaType.APPLICATION_JSON)) { return UserInfoView.VIEWNAME; } } // otherwise return JWT return UserInfoJWTView.VIEWNAME; } else { // client has no preference, see if they asked for JWT specifically on this request for (MediaType m : mediaTypes) { if (!m.isWildcardType() && m.isCompatibleWith(MediaType.APPLICATION_JSON)) { return UserInfoView.VIEWNAME; } else if (!m.isWildcardType() && m.isCompatibleWith(UserInfoJWTView.JOSE_MEDIA_TYPE)) { return UserInfoJWTView.VIEWNAME; } } // otherwise return JSON return UserInfoView.VIEWNAME; } }
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 ww. j ava2s . co m if (contentType != null) { headers.setContentType(contentType); } FileCopyUtils.copy(t.getInputStream(), outputMessage.getBody()); outputMessage.getBody().flush(); }
From source file:com.asual.summer.core.spring.ViewResolverConfiguration.java
public AbstractView handleViews(Collection<AbstractView> views, NativeWebRequest request) { List<MediaType> requestedMediaTypes; try {/* w w w. j a v a 2s. com*/ requestedMediaTypes = contentNegotiationManager.resolveMediaTypes(request); for (MediaType requestedMediaType : requestedMediaTypes) { for (AbstractView view : views) { MediaType producableMediaType = MediaType.parseMediaType(view.getContentType()); if (requestedMediaType.isCompatibleWith(producableMediaType) && !requestedMediaType.isWildcardType() && requestedMediaType.getQualityValue() > 0.9) { return view; } } } } catch (HttpMediaTypeNotAcceptableException e) { logger.debug(e.getMessage(), e); } return null; }
From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java
private MediaType getMediaType(final List<MediaType> supportedMediaTypes, final MediaType acceptedMediaType) { for (final MediaType mediaType : supportedMediaTypes) { if (mediaType.equals(acceptedMediaType)) { return mediaType; }/* ww w .ja v a2s. c o m*/ } for (final MediaType mediaType : supportedMediaTypes) { if (acceptedMediaType.isWildcardType() || mediaType.includes(acceptedMediaType)) { return mediaType; } } return null; }
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"); }/*www .j a v a 2s . c o m*/ 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//from www .j a va 2 s .co m */ 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); } } }