当前位置: 首页>>代码示例>>Java>>正文


Java ByteArrayHttpMessageConverter类代码示例

本文整理汇总了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());
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:30,代码来源:WebMvcConfigurationSupport.java

示例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());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:RestTemplate.java

示例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));
    */
}
 
开发者ID:zg2pro,项目名称:spring-rest-basis,代码行数:22,代码来源:AbstractZg2proRestTemplate.java

示例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();
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:27,代码来源:ServerFileService.java

示例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);
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:19,代码来源:ServerFileService.java

示例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());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:WebMVCConfig.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:ServletAnnotationControllerTests.java

示例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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:RequestPartIntegrationTests.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:20,代码来源:ProxyResponseAutoConfiguration.java

示例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);
}
 
开发者ID:izhangzhihao,项目名称:SpringMVCWithJavaConfig,代码行数:17,代码来源:WebConfig.java

示例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)));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:HttpMessageConvertersTests.java

示例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 );
}
 
开发者ID:lucamartellucci,项目名称:bookshop-api,代码行数:20,代码来源:AbstractWebConfig.java

示例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;
}
 
开发者ID:stairs,项目名称:intermine-android,代码行数:21,代码来源:RoboSpiceService.java

示例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);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:12,代码来源:TwitterEscapingFormHttpMessageConverter.java


注:本文中的org.springframework.http.converter.ByteArrayHttpMessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。