當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。