Java 类org.springframework.http.converter.ByteArrayHttpMessageConverter 实例源码

项目:class-guard    文件:WebMvcConfigurationSupport.java   
/**
 * Adds a set of default HttpMessageConverter instances to the given list.
 * Subclasses can call this method from {@link #configureMessageConverters(List)}.
 * @param messageConverters the list to add the default message converters to
 */
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setWriteAcceptCharset(false);

    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(stringConverter);
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new SourceHttpMessageConverter<Source>());
    messageConverters.add(new AllEncompassingFormHttpMessageConverter());

    if (romePresent) {
        messageConverters.add(new AtomFeedHttpMessageConverter());
        messageConverters.add(new RssChannelHttpMessageConverter());
    }
    if (jaxb2Present) {
        messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        messageConverters.add(new MappingJackson2HttpMessageConverter());
    }
    else if (jacksonPresent) {
        messageConverters.add(new MappingJacksonHttpMessageConverter());
    }
}
项目:lams    文件:RestTemplate.java   
/**
 * Create a new instance of the {@link RestTemplate} using default settings.
 * Default {@link HttpMessageConverter}s are initialized.
 */
@SuppressWarnings("deprecation")
public RestTemplate() {
    this.messageConverters.add(new ByteArrayHttpMessageConverter());
    this.messageConverters.add(new StringHttpMessageConverter());
    this.messageConverters.add(new ResourceHttpMessageConverter());
    this.messageConverters.add(new SourceHttpMessageConverter<Source>());
    this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());

    if (romePresent) {
        this.messageConverters.add(new AtomFeedHttpMessageConverter());
        this.messageConverters.add(new RssChannelHttpMessageConverter());
    }
    if (jaxb2Present) {
        this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        this.messageConverters.add(new MappingJackson2HttpMessageConverter());
    }
    else if (jacksonPresent) {
        this.messageConverters.add(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
    }
}
项目:spring-rest-basis    文件:AbstractZg2proRestTemplate.java   
protected AbstractZg2proRestTemplate(SimpleModule sm) {
    super();
    //converters
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());
    ObjectMapper jsonMapper = camelToKebabObjectMapper(sm);
    messageConverters.add(new MappingJackson2HttpMessageConverter(jsonMapper));
    this.setMessageConverters(messageConverters);
    //errors handling
    setErrorHandler(new RestTemplateErrorHandler());
    /*
    //interceptors
    LoggingRequestInterceptor lri = new LoggingRequestInterceptor();
    this.setInterceptors(new ArrayList<>());
    this.getInterceptors().add(lri);
    this.setRequestFactory(LoggingRequestFactoryFactory.build(lri));
    */
}
项目:ugc-bot-redux    文件:ServerFileService.java   
public HttpStatus isUpToDate(ServerFile serverFile) {
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setBufferRequestBody(false);

    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(requestFactory);
    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());

    HttpHeaders requestHeaders = new HttpHeaders();
    //requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM));
    requestHeaders.setAccept(Collections.singletonList(MediaType.ALL));

    if (serverFile.geteTag() != null) {
        requestHeaders.setIfNoneMatch(serverFile.geteTag());
    }

    if (serverFile.getLastModified() != null) {
        requestHeaders.setLastModified(serverFile.getLastModified());
    }

    HttpEntity<String> entity = new HttpEntity<String>(requestHeaders);

    ResponseEntity<byte[]> response = restTemplate.exchange(serverFile.getRemoteUrl(), HttpMethod.GET, entity, byte[].class);

    return response.getStatusCode();
}
项目:ugc-bot-redux    文件:ServerFileService.java   
private ResponseEntity<byte[]> exchange(ServerFile serverFile) {
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setBufferRequestBody(false);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(requestFactory);
    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    HttpHeaders requestHeaders = new HttpHeaders();
    //requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM));
    requestHeaders.setAccept(Collections.singletonList(MediaType.ALL));
    if (serverFile.geteTag() != null) {
        requestHeaders.setIfNoneMatch(serverFile.geteTag());
    }
    if (serverFile.getLastModified() != null) {
        requestHeaders.setLastModified(serverFile.getLastModified());
    }
    HttpEntity<String> entity = new HttpEntity<String>(requestHeaders);
    return restTemplate.exchange(serverFile.getRemoteUrl(), HttpMethod.GET, entity, byte[].class);
}
项目:oma-riista-web    文件:WebMVCConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
    final MappingJackson2HttpMessageConverter jsonMessageConverter = jacksonMessageConverter();

    final StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    stringHttpMessageConverter.setWriteAcceptCharset(false);

    messageConverters.add(new CSVMessageConverter());
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(stringHttpMessageConverter);
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new SourceHttpMessageConverter<>());
    messageConverters.add(new AllEncompassingFormHttpMessageConverter());
    messageConverters.add(jsonMessageConverter);
    messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
}
项目:spring4-understanding    文件:ServletAnnotationControllerTests.java   
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
    @SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
        @Override
        protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
            RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
            adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
            wac.refresh();
            return wac;
        }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
    String requestBody = "Hello World";
    request.setContent(requestBody.getBytes("UTF-8"));
    request.addHeader("Content-Type", "application/pdf");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(415, response.getStatus());
    assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
项目:spring4-understanding    文件:RequestPartIntegrationTests.java   
@Before
public void setUp() {
    ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
    emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));

    List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
    converters.add(emptyBodyConverter);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());

    AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
    converter.setPartConverters(converters);

    restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    restTemplate.setMessageConverters(Collections.singletonList(converter));
}
项目:spring4-understanding    文件:ServletAnnotationControllerHandlerMethodTests.java   
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
        @Override
        public void initialize(GenericWebApplicationContext wac) {
            RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
            adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
        }
    }, RequestResponseBodyController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
    String requestBody = "Hello World";
    request.setContent(requestBody.getBytes("UTF-8"));
    request.addHeader("Content-Type", "application/pdf");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(415, response.getStatus());
    assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
项目:spring-cloud-gateway    文件:ProxyResponseAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver(
        Optional<RestTemplateBuilder> optional, ProxyProperties proxy) {
    RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder());
    RestTemplate template = builder.build();
    template.setErrorHandler(new NoOpResponseErrorHandler());
    template.getMessageConverters().add(new ByteArrayHttpMessageConverter() {
        @Override
        public boolean supports(Class<?> clazz) {
            return true;
        }
    });
    ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(
            template);
    resolver.setHeaders(proxy.convertHeaders());
    resolver.setSensitive(proxy.getSensitive()); // can be null
    return resolver;
}
项目:SpringMVCWithJavaConfig    文件:WebConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    ByteArrayHttpMessageConverter byteArrayHttpMessageConverter = new ByteArrayHttpMessageConverter();

    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setDefaultCharset(Charset.forName("UTF-8"));
    stringHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
    //避免IE执行AJAX时,返回JSON出现下载文件
    MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
    mappingJackson2HttpMessageConverter.setDefaultCharset(Charset.forName("UTF-8"));
    mappingJackson2HttpMessageConverter.setSupportedMediaTypes(asList(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML));

    converters.add(byteArrayHttpMessageConverter);
    converters.add(stringHttpMessageConverter);
    converters.add(mappingJackson2HttpMessageConverter);
}
项目:contestparser    文件:HttpMessageConvertersTests.java   
@Test
public void containsDefaults() throws Exception {
    HttpMessageConverters converters = new HttpMessageConverters();
    List<Class<?>> converterClasses = new ArrayList<Class<?>>();
    for (HttpMessageConverter<?> converter : converters) {
        converterClasses.add(converter.getClass());
    }
    assertThat(converterClasses,
            equalTo(Arrays.<Class<?>>asList(ByteArrayHttpMessageConverter.class,
                    StringHttpMessageConverter.class,
                    ResourceHttpMessageConverter.class,
                    SourceHttpMessageConverter.class,
                    AllEncompassingFormHttpMessageConverter.class,
                    MappingJackson2HttpMessageConverter.class,
                    MappingJackson2XmlHttpMessageConverter.class)));
}
项目:bookshop-api    文件:AbstractWebConfig.java   
@Override
public void configureMessageConverters( final List<HttpMessageConverter<?>> converters ) {

    final ByteArrayHttpMessageConverter byteArrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
    byteArrayHttpMessageConverter.setSupportedMediaTypes( Arrays.asList( MediaType.APPLICATION_OCTET_STREAM ) );
    converters.add( byteArrayHttpMessageConverter );

    final ObjectMapper mapper = Jackson2ObjectMapperBuilder.json()
     .serializationInclusion(JsonInclude.Include.NON_NULL) // Don’t include null values
     .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //ISODate
     .build();

    final MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    jsonConverter.setSupportedMediaTypes( Arrays.asList( MediaType.APPLICATION_JSON ) );
    jsonConverter.setObjectMapper( mapper );
    converters.add( jsonConverter );

    super.configureMessageConverters( converters );
}
项目:class-guard    文件:ServletAnnotationControllerTests.java   
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
    @SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
        @Override
        protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
            GenericWebApplicationContext wac = new GenericWebApplicationContext();
            wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
            RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
            adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
            wac.refresh();
            return wac;
        }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
    String requestBody = "Hello World";
    request.setContent(requestBody.getBytes("UTF-8"));
    request.addHeader("Content-Type", "application/pdf");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(415, response.getStatus());
    assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
项目:class-guard    文件:ServletAnnotationControllerHandlerMethodTests.java   
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
        @Override
        public void initialize(GenericWebApplicationContext wac) {
            RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
            adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
        }
    }, RequestResponseBodyController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
    String requestBody = "Hello World";
    request.setContent(requestBody.getBytes("UTF-8"));
    request.addHeader("Content-Type", "application/pdf");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(415, response.getStatus());
    assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
项目:intermine-android    文件:RoboSpiceService.java   
@Override
public RestTemplate createRestTemplate() {
    RestTemplate rtp = new RestTemplate();
    Charset utf8 = Charset.forName(CHARSET);

    ByteArrayHttpMessageConverter byteConv = new ByteArrayHttpMessageConverter();
    StringHttpMessageConverter stringConv = new StringHttpMessageConverter(utf8);

    FormHttpMessageConverter formConv = new FormHttpMessageConverter();
    formConv.setCharset(utf8);

    List<HttpMessageConverter<?>> converters = rtp.getMessageConverters();

    converters.add(byteConv);
    converters.add(stringConv);
    converters.add(formConv);

    rtp.setMessageConverters(converters);
    return rtp;
}
项目:xm-uaa    文件:TwitterEscapingFormHttpMessageConverter.java   
TwitterEscapingFormHttpMessageConverter() {
    setCharset(Charset.forName("UTF-8"));
    List<HttpMessageConverter<?>> partConverters = new ArrayList<>();
    partConverters.add(new ByteArrayHttpMessageConverter());
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(
        Charset.forName("UTF-8"));
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    partConverters.add(stringHttpMessageConverter);
    partConverters.add(new ResourceHttpMessageConverter());
    setPartConverters(partConverters);
}
项目:incubator-servicecomb-java-chassis    文件:TestRestTemplateWrapper.java   
@SuppressWarnings("unchecked")
@Test
public void setMessageConvertersWithUnderlying() {
  ByteArrayHttpMessageConverter messageConverter = mock(ByteArrayHttpMessageConverter.class);

  wrapper.setMessageConverters(singletonList(messageConverter));

  assertThat(wrapper.getMessageConverters(), contains(messageConverter));
  assertThat(wrapper.defaultRestTemplate.getMessageConverters(), contains(messageConverter));

  verify(underlying, never()).setMessageConverters(singletonList(messageConverter));
}
项目:cf-java-client-sap    文件:RestUtil.java   
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new UploadApplicationPayloadHttpMessageConverter());
    messageConverters.add(getFormHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    messageConverters.add(new LoggregatorHttpMessageConverter());
    return messageConverters;
}
项目:sns-todo    文件:WebMvcConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

    // See SPR-7316,for weixin token verify.fastjson will convert string 123 to "123"
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    converters.add(stringHttpMessageConverter);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(fastJsonHttpMessageConverter());
}
项目:syndesis    文件:BaseITCase.java   
@Autowired
public void setRestTemplate(TestRestTemplate testRestTemplate) {
    List<HttpMessageConverter<?>> messageConverters = testRestTemplate.getRestTemplate().getMessageConverters();
    messageConverters.add(0, new YamlJackson2HttpMessageConverter());
    messageConverters.add(0, new JsonJackson2HttpMessageConverter());
    messageConverters.add( 0, new ByteArrayHttpMessageConverter());
    this.restTemplate = testRestTemplate;
}
项目:crnk-framework    文件:SpringParameterProvider.java   
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

    List<HttpMessageConverter<?>> converters = new ArrayList<>(4);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(stringHttpMessageConverter);
    converters.add(new SourceHttpMessageConverter<>());
    converters.add(new AllEncompassingFormHttpMessageConverter());

    return converters;
}
项目:xm-ms-entity    文件:MultipartMixedConverter.java   
public MultipartMixedConverter() {
    this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
    this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA);
    this.supportedMediaTypes.add(mixed);
    this.supportedMediaTypes.add(related);

    this.partConverters.add(new ByteArrayHttpMessageConverter());
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    this.partConverters.add(stringHttpMessageConverter);
    this.partConverters.add(new ResourceHttpMessageConverter());
    this.partConverters.add(new MappingJackson2HttpMessageConverter());
}
项目:swordfish-service    文件:DownloadServiceImpl.java   
private HttpEntity<String> downloadHeaders() {
    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

    return new HttpEntity<>(headers);
}
项目:second-opinion-api    文件:MediaDownloadControllerIT.java   
private RestTemplate getRawRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();

    restTemplate.getMessageConverters().add(
            new ByteArrayHttpMessageConverter());

    restTemplate.setRequestFactory(
            new InterceptingClientHttpRequestFactory(
                    restTemplate.getRequestFactory(),
                    Collections.singletonList(
                            new BasicAuthorizationInterceptor("1", "1"))));
    return restTemplate;
}
项目:CityPower-Build-Sample    文件:WebConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    final ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
    final List<MediaType> list = new ArrayList<>();
    list.add(MediaType.IMAGE_JPEG);
    list.add(MediaType.APPLICATION_OCTET_STREAM);
    arrayHttpMessageConverter.setSupportedMediaTypes(list);
    converters.add(arrayHttpMessageConverter);

    super.configureMessageConverters(converters);
}
项目:CityPower-Build-Sample    文件:WebConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    final ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
    final List<MediaType> list = new ArrayList<>();
    list.add(MediaType.IMAGE_JPEG);
    list.add(MediaType.APPLICATION_OCTET_STREAM);
    arrayHttpMessageConverter.setSupportedMediaTypes(list);
    converters.add(arrayHttpMessageConverter);

    super.configureMessageConverters(converters);
}
项目:CityPower-Build-Sample    文件:WebConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    final ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
    final List<MediaType> list = new ArrayList<>();
    list.add(MediaType.IMAGE_JPEG);
    list.add(MediaType.APPLICATION_OCTET_STREAM);
    arrayHttpMessageConverter.setSupportedMediaTypes(list);
    converters.add(arrayHttpMessageConverter);

    super.configureMessageConverters(converters);
}
项目:spring-credhub    文件:CredHubClient.java   
/**
 * Create the {@link HttpMessageConverter}s necessary to build request to
 * and parse responses from CredHub.
 *
 * @return the list of {@link HttpMessageConverter}s
 */
private static List<HttpMessageConverter<?>> createMessageConverters() {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(3);
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper()));

    return messageConverters;
}
项目:apollo-custom    文件:HttpMessageConverterConfiguration.java   
@Bean
public HttpMessageConverters messageConverters() {
  GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
  gsonHttpMessageConverter.setGson(
          new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
  final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
          new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
          new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
  return new HttpMessageConverters() {
    @Override
    public List<HttpMessageConverter<?>> getConverters() {
      return converters;
    }
  };
}
项目:lodsve-framework    文件:LodsveWebMvcConfigurerAdapter.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new CustomObjectMapper());
    converters.add(converter);
    converters.add(new ByteArrayHttpMessageConverter());
}
项目:apollo    文件:HttpMessageConverterConfiguration.java   
@Bean
public HttpMessageConverters messageConverters() {
  GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
  gsonHttpMessageConverter.setGson(
          new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
  final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
          new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
          new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
  return new HttpMessageConverters() {
    @Override
    public List<HttpMessageConverter<?>> getConverters() {
      return converters;
    }
  };
}
项目:spring4-understanding    文件:AnnotationMethodHandlerAdapter.java   
public AnnotationMethodHandlerAdapter() {
    // no restriction of HTTP methods by default
    super(false);

    // See SPR-7316
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    this.messageConverters = new HttpMessageConverter<?>[] {
        new ByteArrayHttpMessageConverter(), stringHttpMessageConverter,
        new SourceHttpMessageConverter<Source>(),
        new org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter() };
}
项目:spring4-understanding    文件:ExceptionHandlerExceptionResolver.java   
public ExceptionHandlerExceptionResolver() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316

    this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
    this.messageConverters.add(new ByteArrayHttpMessageConverter());
    this.messageConverters.add(stringHttpMessageConverter);
    this.messageConverters.add(new SourceHttpMessageConverter<Source>());
    this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
项目:spring4-understanding    文件:RequestMappingHandlerAdapter.java   
public RequestMappingHandlerAdapter() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);  // see SPR-7316

    this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
    this.messageConverters.add(new ByteArrayHttpMessageConverter());
    this.messageConverters.add(stringHttpMessageConverter);
    this.messageConverters.add(new SourceHttpMessageConverter<Source>());
    this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
项目:spring4-understanding    文件:RequestPartIntegrationTests.java   
@Test  // SPR-13319
public void standardMultipartResolverWithEncodedFileName() throws Exception {
    byte[] boundary = MimeTypeUtils.generateMultipartBoundary();
    String boundaryText = new String(boundary, "US-ASCII");
    Map<String, String> params = Collections.singletonMap("boundary", boundaryText);

    String content =
            "--" + boundaryText + "\n" +
            "Content-Disposition: form-data; name=\"file\"; filename*=\"utf-8''%C3%A9l%C3%A8ve.txt\"\n" +
            "Content-Type: text/plain\n" +
            "Content-Length: 7\n" +
            "\n" +
            "content\n" +
            "--" + boundaryText + "--";

    RequestEntity<byte[]> requestEntity =
            RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
                    .contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
                    .body(content.getBytes(Charset.forName("us-ascii")));

    ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
    converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
    this.restTemplate.setMessageConverters(Collections.singletonList(converter));

    ResponseEntity<Void> responseEntity = restTemplate.exchange(requestEntity, Void.class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
项目:spring4-understanding    文件:RequestResponseBodyMethodProcessorTests.java   
@Test
public void handleReturnValueString() throws Exception {
    List<HttpMessageConverter<?>>converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new StringHttpMessageConverter());

    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
    processor.handleReturnValue("Foo", returnTypeString, mavContainer, webRequest);

    assertEquals("text/plain;charset=ISO-8859-1", servletResponse.getHeader("Content-Type"));
    assertEquals("Foo", servletResponse.getContentAsString());
}
项目:spring4-understanding    文件:RequestResponseBodyMethodProcessorTests.java   
@Test
public void handleReturnValueStringAcceptCharset() throws Exception {
    this.servletRequest.addHeader("Accept", "text/plain;charset=UTF-8");

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new StringHttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);

    processor.writeWithMessageConverters("Foo", returnTypeString, webRequest);

    assertEquals("text/plain;charset=UTF-8", servletResponse.getHeader("Content-Type"));
}
项目:spring4-understanding    文件:RestTemplate.java   
/**
 * Create a new instance of the {@link RestTemplate} using default settings.
 * Default {@link HttpMessageConverter}s are initialized.
 */
public RestTemplate() {
    this.messageConverters.add(new ByteArrayHttpMessageConverter());
    this.messageConverters.add(new StringHttpMessageConverter());
    this.messageConverters.add(new ResourceHttpMessageConverter());
    this.messageConverters.add(new SourceHttpMessageConverter<Source>());
    this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());

    if (romePresent) {
        this.messageConverters.add(new AtomFeedHttpMessageConverter());
        this.messageConverters.add(new RssChannelHttpMessageConverter());
    }

    if (jackson2XmlPresent) {
        this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
    }
    else if (jaxb2Present) {
        this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }

    if (jackson2Present) {
        this.messageConverters.add(new MappingJackson2HttpMessageConverter());
    }
    else if (gsonPresent) {
        this.messageConverters.add(new GsonHttpMessageConverter());
    }
}
项目:spring-vault    文件:VaultClients.java   
/**
 * Create a {@link RestTemplate} for Vault interaction. {@link RestTemplate} is
 * configured with a {@link ClientHttpRequestInterceptor} to enforce serialization to
 * a byte array prior continuing the request. Eager serialization leads to a known
 * request body size that is required to send a
 * {@link org.springframework.http.HttpHeaders#CONTENT_LENGTH} request header.
 * Otherwise, Vault will deny body processing.
 * <p>
 * Requires Jackson 2 for Object-to-JSON mapping.
 *
 * @return the {@link RestTemplate}.
 * @see org.springframework.http.client.Netty4ClientHttpRequestFactory
 * @see MappingJackson2HttpMessageConverter
 */
public static RestTemplate createRestTemplate() {

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(3);
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());

    RestTemplate restTemplate = new RestTemplate(messageConverters);

    restTemplate.getInterceptors().add(
            (request, body, execution) -> execution.execute(request, body));

    return restTemplate;
}