List of usage examples for org.springframework.http MediaType equals
@Override public boolean equals(@Nullable Object other)
From source file:org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter.java
private MediaType selectMediaType(List<MediaType> mediaTypes) { MediaType selectedMediaType = null;//from w w w . j a v a 2s. c o m for (MediaType mediaType : mediaTypes) { if (mediaType.isConcrete()) { selectedMediaType = mediaType; break; } else if (mediaType.equals(MediaType.ALL) || mediaType.equals(MEDIA_TYPE_APPLICATION)) { selectedMediaType = MediaType.APPLICATION_OCTET_STREAM; break; } } return selectedMediaType; }
From source file:org.springframework.cloud.config.server.encryption.EncryptionController.java
private String stripFormData(String data, MediaType type, boolean cipher) { if (data.endsWith("=") && !type.equals(MediaType.TEXT_PLAIN)) { try {//from ww w. j a v a2s . c o m data = URLDecoder.decode(data, "UTF-8"); if (cipher) { data = data.replace(" ", "+"); } } catch (UnsupportedEncodingException e) { // Really? } String candidate = data.substring(0, data.length() - 1); if (cipher) { if (data.endsWith("=")) { if (data.length() / 2 != (data.length() + 1) / 2) { try { Hex.decode(candidate); return candidate; } catch (IllegalArgumentException e) { if (Base64.isBase64(data.getBytes())) { return data; } } } } return data; } // User posted data with content type form but meant it to be text/plain data = candidate; } return data; }
From source file:org.springframework.cloud.config.server.EncryptionController.java
private String stripFormData(String data, MediaType type, boolean cipher) { if (data.endsWith("=") && !type.equals(MediaType.TEXT_PLAIN)) { try {//from w ww . j ava 2 s. c om data = URLDecoder.decode(data, "UTF-8"); if (cipher) { data = data.replace(" ", "+"); } } catch (UnsupportedEncodingException e) { // Really? } if (cipher && Base64.isBase64(data.getBytes())) { return data; } // User posted data with content type form but meant it to be text/plain data = data.substring(0, data.length() - 1); } return data; }
From source file:org.springframework.http.codec.EncoderHttpMessageWriter.java
private static boolean useFallback(@Nullable MediaType main, @Nullable MediaType fallback) { return (main == null || !main.isConcrete() || main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null); }
From source file:org.springframework.http.codec.ResourceHttpMessageWriter.java
private static MediaType getResourceMediaType(@Nullable MediaType mediaType, Resource resource, Map<String, Object> hints) { if (mediaType != null && mediaType.isConcrete() && !mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) { return mediaType; }// ww w. j a v a 2 s. c o m mediaType = MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM); if (logger.isDebugEnabled() && !Hints.isLoggingSuppressed(hints)) { logger.debug(Hints.getLogPrefix(hints) + "Resource associated with '" + mediaType + "'"); } return mediaType; }
From source file:org.springframework.http.converter.FormHttpMessageConverter.java
@Override public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) { if (!MultiValueMap.class.isAssignableFrom(clazz)) { return false; }/*from w w w . j a v a 2 s.c o m*/ if (mediaType == null) { return true; } for (MediaType supportedMediaType : getSupportedMediaTypes()) { // We can't read multipart.... if (!supportedMediaType.equals(MediaType.MULTIPART_FORM_DATA) && supportedMediaType.includes(mediaType)) { return true; } } return false; }
From source file:org.springframework.integration.x.bus.MessageBusSupport.java
protected final Message<?> serializePayloadIfNecessary(Message<?> message, MediaType to) { Object originalPayload = message.getPayload(); Object originalContentType = message.getHeaders().get(MessageHeaders.CONTENT_TYPE); Object contentType = originalContentType; if (to.equals(ALL)) { return message; } else if (to.equals(APPLICATION_OCTET_STREAM)) { contentType = resolveContentType(originalPayload); Object payload = serializePayloadIfNecessary(originalPayload); MessageBuilder<Object> messageBuilder = MessageBuilder.withPayload(payload) .copyHeaders(message.getHeaders()).setHeader(MessageHeaders.CONTENT_TYPE, contentType); if (originalContentType != null) { messageBuilder.setHeader(ORIGINAL_CONTENT_TYPE_HEADER, originalContentType); }// w ww. j av a 2 s . c o m return messageBuilder.build(); } else { throw new IllegalArgumentException("'to' can only be 'ALL' or 'APPLICATION_OCTET_STREAM'"); } }
From source file:org.springframework.integration.x.channel.registry.ChannelRegistrySupport.java
protected final Message<?> transformOutboundIfNecessary(Message<?> message, MediaType to) { Message<?> messageToSend = message; Object originalPayload = message.getPayload(); Object payload = null;//from ww w . ja v a2 s. com Object originalContentType = message.getHeaders().get(MessageHeaders.CONTENT_TYPE); String originalContentTypeString = null; if (originalContentType instanceof MediaType) { originalContentTypeString = originalContentType.toString(); } else if (originalContentType instanceof String) { originalContentTypeString = (String) originalContentType; } String contentType = originalContentTypeString; if (to.equals(MediaType.ALL)) { return message; } else if (to.equals(MediaType.APPLICATION_OCTET_STREAM)) { if (originalPayload instanceof byte[]) { payload = originalPayload; contentType = XD_OCTET_STREAM_VALUE; } else if (originalPayload instanceof String) { try { payload = ((String) originalPayload).getBytes("UTF-8"); contentType = XD_TEXT_PLAIN_UTF8_VALUE; } catch (UnsupportedEncodingException e) { logger.error("Could not convert String to bytes", e); } } else { payload = this.jsonMapper.toBytes(originalPayload); contentType = XD_JSON_OCTET_STREAM_VALUE; } } else { throw new IllegalArgumentException("'to' can only be 'ALL' or 'APPLICATION_OCTET_STREAM'"); } if (payload != null) { MessageBuilder<Object> messageBuilder = MessageBuilder.withPayload(payload) .copyHeaders(message.getHeaders()).setHeader(MessageHeaders.CONTENT_TYPE, contentType); if (originalContentTypeString != null) { messageBuilder.setHeader(ORIGINAL_CONTENT_TYPE_HEADER, originalContentTypeString); } messageToSend = messageBuilder.build(); } return messageToSend; }
From source file:org.springframework.social.oauth1.SigningSupport.java
private MultiValueMap<String, String> readFormParameters(MediaType bodyType, byte[] bodyBytes) { if (bodyType != null && bodyType.equals(MediaType.APPLICATION_FORM_URLENCODED)) { String body = new String(bodyBytes, charset); return parseFormParameters(body); } else {//from w w w .j a v a 2 s .c o m return EmptyMultiValueMap.instance(); } }
From source file:org.springframework.social.oauth1.SigningUtils.java
private static Map<String, String> extractBodyParameters(MediaType bodyType, byte[] bodyBytes) { if (bodyType != null && bodyType.equals(MediaType.APPLICATION_FORM_URLENCODED)) { return extractParameters(new String(bodyBytes)); }// w w w . j a v a 2s . c o m return new HashMap<String, String>(); }