本文整理汇总了Java中org.springframework.http.converter.ByteArrayHttpMessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayHttpMessageConverter类的具体用法?Java ByteArrayHttpMessageConverter怎么用?Java ByteArrayHttpMessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteArrayHttpMessageConverter类属于org.springframework.http.converter包,在下文中一共展示了ByteArrayHttpMessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultHttpMessageConverters
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
/**
* 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());
}
}
示例2: RestTemplate
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
/**
* 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());
}
}
示例3: AbstractZg2proRestTemplate
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
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));
*/
}
示例4: isUpToDate
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
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();
}
示例5: exchange
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
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);
}
示例6: configureMessageConverters
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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());
}
示例7: unsupportedRequestBody
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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"));
}
示例8: setUp
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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));
}
示例9: unsupportedRequestBody
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ServletAnnotationControllerHandlerMethodTests.java
示例10: proxyExchangeArgumentResolver
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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;
}
示例11: configureMessageConverters
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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);
}
示例12: containsDefaults
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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)));
}
示例13: configureMessageConverters
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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 );
}
示例14: createRestTemplate
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
@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;
}
示例15: TwitterEscapingFormHttpMessageConverter
import org.springframework.http.converter.ByteArrayHttpMessageConverter; //导入依赖的package包/类
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);
}