List of usage examples for org.springframework.http MediaType MULTIPART_FORM_DATA
MediaType MULTIPART_FORM_DATA
To view the source code for org.springframework.http MediaType MULTIPART_FORM_DATA.
Click Source Link
From source file:org.springframework.http.codec.multipart.DefaultMultipartMessageReader.java
@Override public List<MediaType> getReadableMediaTypes() { return Collections.singletonList(MediaType.MULTIPART_FORM_DATA); }
From source file:org.springframework.http.codec.multipart.DefaultMultipartMessageReader.java
@Override public boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType) { return (Part.class.equals(elementType.toClass()) && (mediaType == null || MediaType.MULTIPART_FORM_DATA.isCompatibleWith(mediaType))); }
From source file:org.springframework.http.converter.FormHttpMessageConverter.java
public FormHttpMessageConverter() { this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED); this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA); StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(); stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316 this.partConverters.add(new ByteArrayHttpMessageConverter()); this.partConverters.add(stringHttpMessageConverter); this.partConverters.add(new ResourceHttpMessageConverter()); applyDefaultCharset();// w w w . j ava 2 s . c om }
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; }/*ww w. j a va 2 s . co 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.http.converter.FormHttpMessageConverter.java
private boolean isMultipart(MultiValueMap<String, ?> map, @Nullable MediaType contentType) { if (contentType != null) { return MediaType.MULTIPART_FORM_DATA.includes(contentType); }/*from www . j a v a 2 s . co m*/ for (String name : map.keySet()) { for (Object value : map.get(name)) { if (value != null && !(value instanceof String)) { return true; } } } return false; }
From source file:org.springframework.http.converter.FormHttpMessageConverter.java
private void writeMultipart(final MultiValueMap<String, Object> parts, HttpOutputMessage outputMessage) throws IOException { final byte[] boundary = generateMultipartBoundary(); Map<String, String> parameters = new HashMap<>(2); parameters.put("boundary", new String(boundary, "US-ASCII")); if (!isFilenameCharsetSet()) { parameters.put("charset", this.charset.name()); }//w ww . ja v a2s . co m MediaType contentType = new MediaType(MediaType.MULTIPART_FORM_DATA, parameters); HttpHeaders headers = outputMessage.getHeaders(); headers.setContentType(contentType); if (outputMessage instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) outputMessage; streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() { @Override public void writeTo(OutputStream outputStream) throws IOException { writeParts(outputStream, parts, boundary); writeEnd(outputStream, boundary); } }); } else { writeParts(outputMessage.getBody(), parts, boundary); writeEnd(outputMessage.getBody(), boundary); } }
From source file:org.springframework.social.box.api.impl.BoxOperations.java
protected BoxFile boxFileUploadOperation(String attributes, Resource file, List<BoxFileFields> fields) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(); form.add("attributes", attributes); form.add("file", file); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(form, httpHeaders);/* www. j a v a2 s. c o m*/ URIBuilder uriBuilder = URIBuilder.fromUri(BOX_FILE_UPLOAD_API_URL); appendFieldsParameter(fields, uriBuilder); BoxFileUploadResult boxFileUploadResult = restTemplate.postForObject(uriBuilder.build(), httpEntity, BoxFileUploadResult.class); if (boxFileUploadResult.getTotalCount() == 1) { return boxFileUploadResult.getEntries().get(0); } else { throw new ApiException(BOX_PROVIDER_NAME, "Could not verify the file was uploaded"); } }
From source file:ren.hankai.cordwood.web.security.support.DefaultRequestInspector.java
@Override public boolean verifyRequestParameters(HttpServletRequest request, String sk) { final Map<String, String[]> params = request.getParameterMap(); // ? form//from ww w.ja v a 2 s. c o m final MediaType contentType = MediaType.valueOf(request.getContentType()); if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { // URL?? return verifyRequestParameters(params, sk); } else if (MediaType.APPLICATION_JSON.isCompatibleWith(contentType) || MediaType.APPLICATION_XML.isCompatibleWith(contentType)) { // ?URL?? String requestBody = null; try { requestBody = IOUtils.toString(request.getInputStream()); } catch (final IOException ex) { logger.warn("Failed to verify request parameters due to io error while parsing request body.", ex); return false; } final String expSign = signRequestBody(requestBody, sk); final Object sign = params.get(RequestInspector.REQUEST_SIGN); if (sign != null) { if ((sign instanceof String) && expSign.equalsIgnoreCase((String) sign)) { return true; } else if (sign instanceof String[]) { final String[] strArr = (String[]) sign; if ((strArr.length > 0) && expSign.equalsIgnoreCase(strArr[0])) { return true; } } } return false; } else if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) { // TODO: ?? return true; } return false; }