List of usage examples for org.springframework.http MediaType TEXT_PLAIN
MediaType TEXT_PLAIN
To view the source code for org.springframework.http MediaType TEXT_PLAIN.
Click Source Link
From source file:org.springframework.boot.actuate.endpoint.mvc.LogFileMvcEndpoint.java
private ResponseEntity<?> getResponse(boolean includeBody) { if (!isEnabled()) { return (includeBody ? DISABLED_RESPONSE : ResponseEntity.notFound().build()); }//from w w w . j ava2 s . c o m Resource resource = getLogFileResource(); if (resource == null) { return ResponseEntity.notFound().build(); } BodyBuilder response = ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN); return (includeBody ? response.body(resource) : response.build()); }
From source file:org.springframework.cloud.aws.messaging.endpoint.NotificationMessageHandlerMethodArgumentResolver.java
private static MediaType getMediaType(JsonNode content) { JsonNode contentTypeNode = content.findPath("MessageAttributes").findPath("contentType"); if (contentTypeNode.isObject()) { String contentType = contentTypeNode.findPath("Value").asText(); if (StringUtils.hasText(contentType)) { return MediaType.parseMediaType(contentType); }//from w ww. j a v a 2s. c o m } return MediaType.TEXT_PLAIN; }
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 {// w w w. j ava 2s. co 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 {/* w w w. j a v a 2 s .c o m*/ 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.cloud.config.server.environment.EnvironmentController.java
private ResponseEntity<String> getSuccess(String body) { return new ResponseEntity<>(body, getHttpHeaders(MediaType.TEXT_PLAIN), HttpStatus.OK); }
From source file:org.springframework.cloud.function.web.flux.request.FluxHandlerMethodArgumentResolver.java
private boolean isPlainText(NativeWebRequest webRequest) { String value = webRequest.getHeader("Content-Type"); if (value != null) { return MediaType.valueOf(value).isCompatibleWith(MediaType.TEXT_PLAIN); }/*from ww w .j a v a 2s. c o m*/ return false; }
From source file:org.springframework.cloud.function.web.flux.response.FluxReturnValueHandler.java
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); return;//w ww .jav a 2 s . c o m } Object adaptFrom = returnValue; if (returnValue instanceof ResponseEntity) { ResponseEntity<?> value = (ResponseEntity<?>) returnValue; adaptFrom = value.getBody(); webRequest.getNativeResponse(HttpServletResponse.class).setStatus(value.getStatusCodeValue()); } Publisher<?> flux = (Publisher<?>) adaptFrom; Object handler = webRequest.getAttribute(WebRequestConstants.HANDLER, NativeWebRequest.SCOPE_REQUEST); Class<?> type = inspector.getOutputType(inspector.getName(handler)); boolean inputSingle = isInputSingle(webRequest, handler); if (inputSingle && isOutputSingle(handler)) { single.handleReturnValue(Flux.from(flux).blockFirst(), singleReturnType, mavContainer, webRequest); return; } MediaType mediaType = null; if (isPlainText(webRequest) && CharSequence.class.isAssignableFrom(type)) { mediaType = MediaType.TEXT_PLAIN; } else { mediaType = findMediaType(webRequest); } if (logger.isDebugEnabled()) { logger.debug("Handling return value " + type + " with media type: " + mediaType); } delegate.handleReturnValue(getEmitter(timeout, flux, mediaType), returnType, mavContainer, webRequest); }
From source file:org.springframework.cloud.netflix.zuul.FormZuulServletProxyApplicationTests.java
@Test public void postWithMultipartFile() { MultiValueMap<String, Object> form = new LinkedMultiValueMap<>(); HttpHeaders part = new HttpHeaders(); part.setContentType(MediaType.TEXT_PLAIN); part.setContentDispositionFormData("file", "foo.txt"); form.set("foo", new HttpEntity<>("bar".getBytes(), part)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.set("Transfer-Encoding", "chunked"); headers.setContentLength(-1);/*from w w w . j a v a 2 s. c o m*/ ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simplefzspat/file", HttpMethod.POST, new HttpEntity<>(form, headers), String.class); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals("Posted! bar", result.getBody()); }
From source file:org.springframework.data.keyvalue.riak.core.AbstractRiakTemplate.java
protected <B, K> Class<?> getType(B bucket, K key, ClassLoader classLoader) { Class<?> clazz = null;//from w w w . j a v a 2 s .co m try { HttpHeaders headers = getRestTemplate().headForHeaders(defaultUri, bucket, key); if (null != headers) { String s = headers.getFirst(RIAK_META_CLASSNAME); if (null != s) { try { if (null != classLoader) { clazz = Class.forName(s, false, classLoader); } else { clazz = Class.forName(s); } } catch (ClassNotFoundException ignored) { } } } if (null == clazz) { if (headers.getContentType().equals(MediaType.APPLICATION_JSON)) { clazz = Map.class; } else if (headers.getContentType().equals(MediaType.TEXT_PLAIN)) { clazz = String.class; } else { // handle as bytes log.error("Need to handle bytes!"); clazz = byte[].class; } } } catch (ResourceAccessException notFound) { clazz = String.class; } return clazz; }
From source file:org.springframework.http.codec.multipart.DefaultMultipartMessageReader.java
/** * Convert the given data buffer into a Part. All data up until the header separator (\r\n\r\n) * is passed to {@link #toHeaders(DataBuffer)}, the remaining data is considered to be the * body.//from w w w . j av a2 s.c o m */ private static Part toPart(DataBuffer dataBuffer) { int readPosition = dataBuffer.readPosition(); if (dataBuffer.readableByteCount() >= 2) { if (dataBuffer.getByte(readPosition) == CR && dataBuffer.getByte(readPosition + 1) == LF) { dataBuffer.readPosition(readPosition + 2); } } if (logger.isTraceEnabled()) { logger.trace("Part data: " + toString(dataBuffer)); } int endIdx = HEADER_MATCHER.match(dataBuffer); HttpHeaders headers; DataBuffer body; if (endIdx > 0) { readPosition = dataBuffer.readPosition(); int headersLength = endIdx + 1 - (readPosition + HEADER_BODY_SEPARATOR.length); DataBuffer headersBuffer = dataBuffer.retainedSlice(readPosition, headersLength); int bodyLength = dataBuffer.writePosition() - (1 + endIdx); body = dataBuffer.retainedSlice(endIdx + 1, bodyLength); headers = toHeaders(headersBuffer); } else { headers = new HttpHeaders(); body = DataBufferUtils.retain(dataBuffer); } DataBufferUtils.release(dataBuffer); ContentDisposition cd = headers.getContentDisposition(); MediaType contentType = headers.getContentType(); if (StringUtils.hasLength(cd.getFilename())) { return new DefaultFilePart(headers, body); } else if (StringUtils.hasLength(cd.getName()) && (contentType == null || MediaType.TEXT_PLAIN.isCompatibleWith(contentType))) { return new DefaultFormPart(headers, body); } else { return new DefaultPart(headers, body); } }