Package org.springframework.util

Examples of org.springframework.util.MimeType


   * @param mediaType the string to parse
   * @return the media type
   * @throws InvalidMediaTypeException if the string cannot be parsed
   */
  public static MediaType parseMediaType(String mediaType) {
    MimeType type;
    try {
      type = MimeTypeUtils.parseMimeType(mediaType);
    }
    catch (InvalidMimeTypeException ex) {
      throw new InvalidMediaTypeException(ex);
    }
    try {
      return new MediaType(type.getType(), type.getSubtype(), type.getParameters());
    }
    catch (IllegalArgumentException ex) {
      throw new InvalidMediaTypeException(mediaType, ex.getMessage());
    }
  }
View Full Code Here


  @Test
  public void fromMessageCharset() {
    Charset iso88591 = Charset.forName("ISO-8859-1");
    String payload = "H\u00e9llo W\u00f6rld";
    Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(iso88591))
        .setHeader(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain", iso88591)).build();

    assertEquals(payload, this.converter.fromMessage(message, String.class));
  }
View Full Code Here

    assertTrue(actual.contains("\"number\":42"));
    assertTrue(actual.contains("fraction\":42.0"));
    assertTrue(actual.contains("\"array\":[\"Foo\",\"Bar\"]"));
    assertTrue(actual.contains("\"bool\":true"));
    assertTrue(actual.contains("\"bytes\":\"AQI=\""));
    assertEquals("Invalid content-type", new MimeType("application", "json", UTF_8),
        message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class));
  }
View Full Code Here

  }

  @Test
  public void toMessageUtf16() {
    Charset utf16 = Charset.forName("UTF-16BE");
    MimeType contentType = new MimeType("application", "json", utf16);
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, contentType);
    MessageHeaders headers = new MessageHeaders(map);
    String payload = "H\u00e9llo W\u00f6rld";
    Message<?> message = this.converter.toMessage(payload, headers);
View Full Code Here

  @Test
  public void toMessageUtf16String() {
    this.converter.setSerializedPayloadClass(String.class);

    Charset utf16 = Charset.forName("UTF-16BE");
    MimeType contentType = new MimeType("application", "json", utf16);
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, contentType);
    MessageHeaders headers = new MessageHeaders(map);
    String payload = "H\u00e9llo W\u00f6rld";
    Message<?> message = this.converter.toMessage(payload, headers);
View Full Code Here

    this.template.setMessageConverter(new StringMessageConverter());
    this.template.convertAndSend("somewhere", "payload", messageHeaders);

    MessageHeaders actual = this.template.message.getHeaders();
    assertSame(messageHeaders, actual);
    assertEquals(new MimeType("text", "plain", Charset.forName("UTF-8")), actual.get(MessageHeaders.CONTENT_TYPE));
    assertEquals("bar", actual.get("foo"));
  }
View Full Code Here

    if (!canConvertTo(payload, headers)) {
      return null;
    }

    payload = convertToInternal(payload, headers);
    MimeType mimeType = getDefaultContentType(payload);

    if (headers != null) {
      MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class);
      if (accessor != null && accessor.isMutable()) {
        accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
View Full Code Here

  protected boolean supportsMimeType(MessageHeaders headers) {
    if (getSupportedMimeTypes().isEmpty()) {
      return true;
    }
    MimeType mimeType = getMimeType(headers);
    if (mimeType == null) {
      if (isStrictContentTypeMatch()) {
        return false;
      }
      else {
        return true;
      }
    }
    for (MimeType current : getSupportedMimeTypes()) {
      if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

  public StringMessageConverter() {
    this(Charset.forName("UTF-8"));
  }

  public StringMessageConverter(Charset defaultCharset) {
    super(new MimeType("text", "plain", defaultCharset));
    this.defaultCharset = defaultCharset;
  }
View Full Code Here

  private Boolean prettyPrint;


  public MappingJackson2MessageConverter() {
    super(new MimeType("application", "json", Charset.forName("UTF-8")));
  }
View Full Code Here

TOP

Related Classes of org.springframework.util.MimeType

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.