Package org.springframework.http

Examples of org.springframework.http.MediaType


  /**
   * Construct a new {@code MappingJackson2HttpMessageConverter}.
   */
  public MappingJackson2HttpMessageConverter() {
    super(new MediaType("application", "json", DEFAULT_CHARSET), new MediaType("application", "*+json", DEFAULT_CHARSET));
  }
View Full Code Here


  /**
   * Construct a new {@code MappingJacksonHttpMessageConverter}.
   */
  public MappingJacksonHttpMessageConverter() {
    super(new MediaType("application", "json", DEFAULT_CHARSET), new MediaType("application", "*+json", DEFAULT_CHARSET));
  }
View Full Code Here

          this.headers.add(headerName, headerValue);
        }
      }
      // HttpServletRequest exposes some headers as properties: we should include those if not already present
      if (this.headers.getContentType() == null && this.servletRequest.getContentType() != null) {
        MediaType contentType = MediaType.parseMediaType(this.servletRequest.getContentType());
        this.headers.setContentType(contentType);
      }
      if (this.headers.getContentType() != null && this.headers.getContentType().getCharSet() == null &&
          this.servletRequest.getCharacterEncoding() != null) {
        MediaType oldContentType = this.headers.getContentType();
        Charset charSet = Charset.forName(this.servletRequest.getCharacterEncoding());
        Map<String, String> params = new HashMap<String, String>(oldContentType.getParameters());
        params.put("charset", charSet.toString());
        MediaType newContentType = new MediaType(oldContentType.getType(), oldContentType.getSubtype(), params);
        this.headers.setContentType(newContentType);
      }
      if (this.headers.getContentLength() == -1 && this.servletRequest.getContentLength() != -1) {
        this.headers.setContentLength(this.servletRequest.getContentLength());
      }
View Full Code Here

  @SuppressWarnings("unchecked")
  public T extractData(ClientHttpResponse response) throws IOException {
    if (!hasMessageBody(response)) {
      return null;
    }
    MediaType contentType = getContentType(response);

    for (HttpMessageConverter messageConverter : this.messageConverters) {
      if (messageConverter instanceof GenericHttpMessageConverter) {
        GenericHttpMessageConverter genericMessageConverter = (GenericHttpMessageConverter) messageConverter;
        if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
View Full Code Here

        "Could not extract response: no suitable HttpMessageConverter found for response type [" +
            this.responseType + "] and content type [" + contentType + "]");
  }

  private MediaType getContentType(ClientHttpResponse response) {
    MediaType contentType = response.getHeaders().getContentType();
    if (contentType == null) {
      if (logger.isTraceEnabled()) {
        logger.trace("No Content-Type header found, defaulting to application/octet-stream");
      }
      contentType = MediaType.APPLICATION_OCTET_STREAM;
View Full Code Here

  }

  private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class paramType)
      throws Exception {

    MediaType contentType = inputMessage.getHeaders().getContentType();
    if (contentType == null) {
      StringBuilder builder = new StringBuilder(ClassUtils.getShortName(methodParam.getParameterType()));
      String paramName = methodParam.getParameterName();
      if (paramName != null) {
        builder.append(' ');
View Full Code Here

  private String determineEncoding(String contentTypeHeader, String defaultEncoding) {
    if (!StringUtils.hasText(contentTypeHeader)) {
      return defaultEncoding;
    }
    MediaType contentType = MediaType.parseMediaType(contentTypeHeader);
    Charset charset = contentType.getCharSet();
    return (charset != null ? charset.name() : defaultEncoding);
  }
View Full Code Here

  }

  private boolean isFormContentType(HttpServletRequest request) {
    String contentType = request.getContentType();
    if (contentType != null) {
      MediaType mediaType = MediaType.parseMediaType(contentType);
      return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
    }
    else {
      return false;
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  public T extractData(ClientHttpResponse response) throws IOException {
    if (!hasMessageBody(response)) {
      return null;
    }
    MediaType contentType = response.getHeaders().getContentType();
    if (contentType == null) {
      if (logger.isTraceEnabled()) {
        logger.trace("No Content-Type header found, defaulting to application/octet-stream");
      }
      contentType = MediaType.APPLICATION_OCTET_STREAM;
View Full Code Here

      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // check the resource's media type
    MediaType mediaType = getMediaType(resource);
    if (mediaType != null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Determined media type '" + mediaType + "' for " + resource);
      }
    }
View Full Code Here

TOP

Related Classes of org.springframework.http.MediaType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.