當前位置: 首頁>>代碼示例>>Java>>正文


Java StringHttpMessageConverter.setSupportedMediaTypes方法代碼示例

本文整理匯總了Java中org.springframework.http.converter.StringHttpMessageConverter.setSupportedMediaTypes方法的典型用法代碼示例。如果您正苦於以下問題:Java StringHttpMessageConverter.setSupportedMediaTypes方法的具體用法?Java StringHttpMessageConverter.setSupportedMediaTypes怎麽用?Java StringHttpMessageConverter.setSupportedMediaTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.converter.StringHttpMessageConverter的用法示例。


在下文中一共展示了StringHttpMessageConverter.setSupportedMediaTypes方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyNoMarkupError

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
/**
 * Verifies that the HTML is well formed.
 * 
 * @param markup The HTML markup to be tested.
 */
public static void verifyNoMarkupError(String markup) {
//        List<MediaType> supportedMediaTypes = new ArrayList<>();
        List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
        supportedMediaTypes.add(new MediaType("text", "html", Charset.forName("UTF-8")));

        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
        stringHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);       

//        List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
        List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        messageConverters.add(stringHttpMessageConverter);

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(messageConverters);

        String result = restTemplate.postForObject(URL, markup, String.class);
        System.out.println("result: " + result);

        assertTrue("The document is not valid HTML5: " + markup, result.contains("The document is valid HTML5"));
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:26,代碼來源:MarkupValidationHelper.java

示例2: configureMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的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

示例3: getFormPartsMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
private List<HttpMessageConverter<?>> getFormPartsMessageConverters() {
    List<HttpMessageConverter<?>> partConverters = new ArrayList<HttpMessageConverter<?>>();
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setSupportedMediaTypes(Collections.singletonList(JsonUtil.JSON_MEDIA_TYPE));
    stringConverter.setWriteAcceptCharset(false);
    partConverters.add(stringConverter);
    partConverters.add(new ResourceHttpMessageConverter());
    partConverters.add(new UploadApplicationPayloadHttpMessageConverter());
    return partConverters;
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:11,代碼來源:RestUtil.java

示例4: setStringConverterMediaTypes

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
private void setStringConverterMediaTypes(HttpMessageConverter<?> x) {
    StringHttpMessageConverter converter = (StringHttpMessageConverter) x;
    List<MediaType> mediaTypes = Arrays.asList(
            new MediaType("text", "plain", StandardCharsets.UTF_8), 
            MediaType.ALL);
    converter.setSupportedMediaTypes(mediaTypes);
}
 
開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:8,代碼來源:WebWiring.java

示例5: initStringHttpMessageConverter

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
private StringHttpMessageConverter initStringHttpMessageConverter() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
    supportedMediaTypes.add(new MediaType("text", "plain", Charset.defaultCharset()));
    supportedMediaTypes.add(new MediaType("application", "json", Charset.defaultCharset()));
    supportedMediaTypes.add(new MediaType("text", "html", Charset.defaultCharset()));
    stringHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
    return stringHttpMessageConverter;
}
 
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:10,代碼來源:RestTemplateConfig.java

示例6: responseBodyNoAcceptableMediaType

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Test
public void responseBodyNoAcceptableMediaType() 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 converterDef = new RootBeanDefinition(StringHttpMessageConverter.class);
			converterDef.getPropertyValues().add("supportedMediaTypes", new MediaType("text", "plain"));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			StringHttpMessageConverter converter = new StringHttpMessageConverter();
			converter.setSupportedMediaTypes(Collections.singletonList(new MediaType("text", "plain")));
			adapterDef.getPropertyValues().add("messageConverters", converter);
			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", "text/plain; charset=utf-8");
	request.addHeader("Accept", "application/pdf, application/msword");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals(406, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:ServletAnnotationControllerTests.java

示例7: makeRestTemplateWithCustomObjectMapper

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
/**
 * Gets a customized {@link MappingJackson2HttpMessageConverter} to process
 * payload from TMS Rest API.
 *
 * @return
 */
protected void makeRestTemplateWithCustomObjectMapper(RestTemplate restTemplate) {
    logger.debug("Getting new rest template");

    for (HttpMessageConverter<?> httpMessageConverter : restTemplate.getMessageConverters()) {
        if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) {
            MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) httpMessageConverter;

            // Bug with application/x-spring-data-compact+json: https://jira.spring.io/browse/DATAREST-404
            logger.debug("Setting supported media type to just JSON. The Accept header will be updated accordingly to application/json");
            mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));

            // This helps with joda deserialize of joda date time string
            logger.debug("Creating custom jackson2 objectmapper with serialization inclusion changes");
            Jackson2ObjectMapperFactoryBean jackson2ObjectMapperFactoryBean = new Jackson2ObjectMapperFactoryBean();
            jackson2ObjectMapperFactoryBean.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            jackson2ObjectMapperFactoryBean.afterPropertiesSet();

            ObjectMapper objectMapper = jackson2ObjectMapperFactoryBean.getObject();
            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

            mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
        }

        // The default encoding is set to ISO-8559-1 for String type, which is why we have to override it here
        // For more info: https://jira.spring.io/browse/SPR-9099
        if (httpMessageConverter instanceof StringHttpMessageConverter) {
            StringHttpMessageConverter stringHttpMessageConverter = (StringHttpMessageConverter) httpMessageConverter;
            stringHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
                            MediaType.parseMediaType("text/plain;charset=UTF-8"),
                            MediaType.ALL)
            );
        }
    }
}
 
開發者ID:box,項目名稱:mojito,代碼行數:41,代碼來源:AuthenticatedRestTemplate.java

示例8: configureMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setSupportedMediaTypes(Arrays.asList(
			new MediaType("application", "rdf", UTF8)));
	converters.add(stringConverter);
}
 
開發者ID:erfgoed-en-locatie,項目名稱:artsholland-platform,代碼行數:8,代碼來源:BaseConfig.java

示例9: getFormPartsMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
private List<HttpMessageConverter<?>> getFormPartsMessageConverters() {
	List<HttpMessageConverter<?>> partConverters = new ArrayList<HttpMessageConverter<?>>();
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setSupportedMediaTypes(Collections.singletonList(JsonUtil.JSON_MEDIA_TYPE));
	stringConverter.setWriteAcceptCharset(false);
	partConverters.add(stringConverter);
	partConverters.add(new ResourceHttpMessageConverter());
	partConverters.add(new UploadApplicationPayloadHttpMessageConverter());
	return partConverters;
}
 
開發者ID:OpenNTF,項目名稱:XPagesExtensionLibrary,代碼行數:11,代碼來源:RestUtil.java

示例10: createRestTemplate

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Override
protected RestTemplate createRestTemplate() {
    ClientHttpRequestFactory requestFactory = ClientHttpRequestFactorySelector.getRequestFactory();
    RestTemplate restTemplate = new RestTemplate(requestFactory);
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(2);
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    stringHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
    converters.add(stringHttpMessageConverter);
    restTemplate.setMessageConverters(converters);

    return restTemplate;
}
 
開發者ID:avidoggy,項目名稱:spring-social-tencent-weibo,代碼行數:13,代碼來源:TencentWeiboOAuth2Template.java

示例11: configureMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(jacksonMessageConverter());
    StringHttpMessageConverter converter = new StringHttpMessageConverter();
    converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
    converters.add(converter);
}
 
開發者ID:alfio-event,項目名稱:alf.io,代碼行數:8,代碼來源:MvcConfiguration.java

示例12: stringMessageConverter

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Bean
public StringHttpMessageConverter stringMessageConverter() {
	StringHttpMessageConverter messageConverter = new StringHttpMessageConverter();
	messageConverter.setDefaultCharset(Charset.forName("UTF-8"));
	messageConverter.setWriteAcceptCharset(false);
	List<MediaType> mediaTypes = new ArrayList<>();
	mediaTypes.add(MediaType.TEXT_PLAIN);
	messageConverter.setSupportedMediaTypes(mediaTypes);

	return messageConverter;
}
 
開發者ID:thm-projects,項目名稱:arsnova-backend,代碼行數:12,代碼來源:AppConfig.java

示例13: configureMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
/**
 * Ensure that we always return UTF-8 when returning text/plain and text/html.
 */
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
    stringConverter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", StandardCharsets.UTF_8),
                                                         new MediaType("text", "html", StandardCharsets.UTF_8)));
    converters.add(stringConverter);

    addDefaultHttpMessageConverters(converters);
}
 
開發者ID:jegbjerg,項目名稱:webapp-base,代碼行數:13,代碼來源:WebConfig.java

示例14: configureMessageConverters

import org.springframework.http.converter.StringHttpMessageConverter; //導入方法依賴的package包/類
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
	StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
	stringConverter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", Charset.forName("UTF-8"))));
	converters.add(stringConverter);
}
 
開發者ID:lf23617358,項目名稱:training-sample,代碼行數:7,代碼來源:WebAppConfig.java


注:本文中的org.springframework.http.converter.StringHttpMessageConverter.setSupportedMediaTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。