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


Java MappingJackson2XmlHttpMessageConverter类代码示例

本文整理汇总了Java中org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter的典型用法代码示例。如果您正苦于以下问题:Java MappingJackson2XmlHttpMessageConverter类的具体用法?Java MappingJackson2XmlHttpMessageConverter怎么用?Java MappingJackson2XmlHttpMessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MappingJackson2XmlHttpMessageConverter类属于org.springframework.http.converter.xml包,在下文中一共展示了MappingJackson2XmlHttpMessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jacksonJsonViewWithResponseBodyAndXmlMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test  // SPR-12149
public void jacksonJsonViewWithResponseBodyAndXmlMessageConverter() throws Exception {
	Method method = JacksonController.class.getMethod("handleResponseBody");
	HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
	MethodParameter methodReturnType = handlerMethod.getReturnType();

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new MappingJackson2XmlHttpMessageConverter());

	RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(
			converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()));

	Object returnValue = new JacksonController().handleResponseBody();
	processor.handleReturnValue(returnValue, methodReturnType, this.mavContainer, this.webRequest);

	String content = this.servletResponse.getContentAsString();
	assertFalse(content.contains("<withView1>with</withView1>"));
	assertTrue(content.contains("<withView2>with</withView2>"));
	assertFalse(content.contains("<withoutView>without</withoutView>"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:RequestResponseBodyMethodProcessorTests.java

示例2: jacksonJsonViewWithResponseEntityAndXmlMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test  // SPR-12149
public void jacksonJsonViewWithResponseEntityAndXmlMessageConverter() throws Exception {
	Method method = JacksonController.class.getMethod("handleResponseEntity");
	HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
	MethodParameter methodReturnType = handlerMethod.getReturnType();

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new MappingJackson2XmlHttpMessageConverter());

	HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(
			converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()));

	Object returnValue = new JacksonController().handleResponseEntity();
	processor.handleReturnValue(returnValue, methodReturnType, this.mavContainer, this.webRequest);

	String content = this.servletResponse.getContentAsString();
	assertFalse(content.contains("<withView1>with</withView1>"));
	assertTrue(content.contains("<withView2>with</withView2>"));
	assertFalse(content.contains("<withoutView>without</withoutView>"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:RequestResponseBodyMethodProcessorTests.java

示例3: resolveArgumentWithJacksonJsonViewAndXmlMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test  // SPR-12501
public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
	String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
	this.servletRequest.setContent(content.getBytes("UTF-8"));
	this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);

	Method method = JacksonController.class.getMethod("handleRequestBody", JacksonViewBean.class);
	HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
	MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new MappingJackson2XmlHttpMessageConverter());

	RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(
			converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()));

	@SuppressWarnings("unchecked")
	JacksonViewBean result = (JacksonViewBean)processor.resolveArgument(methodParameter,
			this.mavContainer, this.webRequest, this.binderFactory);

	assertNotNull(result);
	assertEquals("with", result.getWithView1());
	assertNull(result.getWithView2());
	assertNull(result.getWithoutView());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:RequestResponseBodyMethodProcessorTests.java

示例4: resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test  // SPR-12501
public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
	String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
	this.servletRequest.setContent(content.getBytes("UTF-8"));
	this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);

	Method method = JacksonController.class.getMethod("handleHttpEntity", HttpEntity.class);
	HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
	MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new MappingJackson2XmlHttpMessageConverter());

	HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(
			converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()));

	@SuppressWarnings("unchecked")
	HttpEntity<JacksonViewBean> result = (HttpEntity<JacksonViewBean>)processor.resolveArgument(methodParameter,
			this.mavContainer, this.webRequest, this.binderFactory);

	assertNotNull(result);
	assertNotNull(result.getBody());
	assertEquals("with", result.getBody().getWithView1());
	assertNull(result.getBody().getWithView2());
	assertNull(result.getBody().getWithoutView());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:RequestResponseBodyMethodProcessorTests.java

示例5: AllEncompassingFormHttpMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
public AllEncompassingFormHttpMessageConverter() {
	addPartConverter(new SourceHttpMessageConverter<Source>());

	if (jaxb2Present && !jackson2Present) {
		addPartConverter(new Jaxb2RootElementHttpMessageConverter());
	}

	if (jackson2Present) {
		addPartConverter(new MappingJackson2HttpMessageConverter());
	}
	else if (gsonPresent) {
		addPartConverter(new GsonHttpMessageConverter());
	}

	if (jackson2XmlPresent) {
		addPartConverter(new MappingJackson2XmlHttpMessageConverter());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AllEncompassingFormHttpMessageConverter.java

示例6: defaultJacksonConvertersWithBuilder

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test
public void defaultJacksonConvertersWithBuilder() throws Exception {
	this.context.register(JacksonObjectMapperBuilderConfig.class,
			HttpMessageConvertersAutoConfiguration.class);
	this.context.refresh();

	assertConverterBeanExists(MappingJackson2HttpMessageConverter.class,
			"mappingJackson2HttpMessageConverter");
	assertConverterBeanExists(MappingJackson2XmlHttpMessageConverter.class,
			"mappingJackson2XmlHttpMessageConverter");

	assertConverterBeanRegisteredWithHttpMessageConverters(
			MappingJackson2HttpMessageConverter.class);
	assertConverterBeanRegisteredWithHttpMessageConverters(
			MappingJackson2XmlHttpMessageConverter.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:HttpMessageConvertersAutoConfigurationTests.java

示例7: containsDefaults

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的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

示例8: configureMessageConverters

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
/**
 * This is called from requestMappingHandlerAdapter to configure the message converters. We override it to configure our own converter in addition to the
 * default converters.
 *
 * @param converters the converter list we configure.
 */
@Override
@SuppressWarnings("rawtypes")
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters)
{
    // Add in our custom converter first.
    converters.add(marshallingMessageConverter());

    // Add in the default converters (e.g. standard JAXB, Jackson, etc.).
    addDefaultHttpMessageConverters(converters);

    // Remove the Jackson2Xml converter since we want to use JAXB instead when we encounter "application/xml". Otherwise, the XSD auto-generated
    // classes with JAXB annotations won't get used.
    // Set jackson mapper to include only properties with non-null values.
    for (HttpMessageConverter httpMessageConverter : converters)
    {
        if (httpMessageConverter instanceof MappingJackson2XmlHttpMessageConverter)
        {
            converters.remove(httpMessageConverter);
            break;
        }
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:29,代码来源:RestSpringModuleConfig.java

示例9: initRestTemplate

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
/**
 * springboot初始化restTemplate
 */
@Bean
public RestTemplate initRestTemplate() {
    // 长连接保持30秒
    PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
    // 总连接数
    pollingConnectionManager.setMaxTotal(1000);
    // 同路由的并发数
    pollingConnectionManager.setDefaultMaxPerRoute(1000);

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setConnectionManager(pollingConnectionManager);
    // 重试次数,默认是3次,没有开启
    httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
    // 保持长连接配置,需要在头添加Keep-Alive
    httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    RequestConfig.Builder builder = RequestConfig.custom();
    builder.setConnectionRequestTimeout(200);
    builder.setConnectTimeout(5000);
    builder.setSocketTimeout(5000);

    RequestConfig requestConfig = builder.build();
    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    List<Header> headers = new ArrayList<>();
    headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
    headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
    headers.add(new BasicHeader("Accept-Language", "zh-CN"));
    headers.add(new BasicHeader("Connection", "Keep-Alive"));

    httpClientBuilder.setDefaultHeaders(headers);

    HttpClient httpClient = httpClientBuilder.build();

    // httpClient连接配置,底层是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 连接超时
    clientHttpRequestFactory.setConnectTimeout(5000);
    // 数据读取超时时间,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(5000);
    // 连接不够用的等待时间,不宜过长,必须设置,比如连接不够用时,时间过长将是灾难性的
    clientHttpRequestFactory.setConnectionRequestTimeout(200);
    // 缓冲请求数据,默认值是true。通过POST或者PUT大量发送数据时,建议将此属性更改为false,以免耗尽内存。
    clientHttpRequestFactory.setBufferRequestBody(false);

    // 添加内容转换器
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(initStringHttpMessageConverter());
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());

    RestTemplate restTemplate = new RestTemplate(messageConverters);
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
    return restTemplate;

}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:62,代码来源:RestTemplateConfig.java

示例10: configureMessageConverters

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(true).dateFormat(new SimpleDateFormat("yyyy-MM-dd"));
    converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:8,代码来源:WebConfig.java

示例11: requestMappingHandlerAdapter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Test
public void requestMappingHandlerAdapter() throws Exception {
	ApplicationContext context = initContext(WebConfig.class);
	RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
	List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
	assertEquals(9, converters.size());
	for(HttpMessageConverter<?> converter : converters) {
		if (converter instanceof AbstractJackson2HttpMessageConverter) {
			ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
			assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
			assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
			assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
			if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
				assertEquals(XmlMapper.class, objectMapper.getClass());
			}
		}
	}

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	assertNotNull(initializer);

	ConversionService conversionService = initializer.getConversionService();
	assertNotNull(conversionService);
	assertTrue(conversionService instanceof FormattingConversionService);

	Validator validator = initializer.getValidator();
	assertNotNull(validator);
	assertTrue(validator instanceof LocalValidatorFactoryBean);

	DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
	@SuppressWarnings("unchecked")
	List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
	assertEquals(2, bodyAdvice.size());
	assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
	assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:37,代码来源:WebMvcConfigurationSupportTests.java

示例12: RestTemplate

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
/**
 * 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());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:RestTemplate.java

示例13: configureMessageConverters

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
	Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder = new Jackson2ObjectMapperBuilder()
			.annotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))
			.indentOutput(true);
	converters.add(new StringHttpMessageConverter());
	converters.add(new MappingJackson2HttpMessageConverter());
	converters.add(new MappingJackson2XmlHttpMessageConverter(
			jacksonObjectMapperBuilder
				.createXmlMapper(true)
				.build()));
}
 
开发者ID:samolisov,项目名称:spring-4x-demos,代码行数:13,代码来源:ApplicationConfig.java

示例14: mappingJackson2XmlHttpMessageConverter

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public MappingJackson2XmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter(
		Jackson2ObjectMapperBuilder builder) {
	return new MappingJackson2XmlHttpMessageConverter(
			builder.createXmlMapper(true).build());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:JacksonHttpMessageConvertersConfiguration.java

示例15: reorderXmlConvertersToEnd

import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; //导入依赖的package包/类
private void reorderXmlConvertersToEnd(List<HttpMessageConverter<?>> converters) {
	List<HttpMessageConverter<?>> xml = new ArrayList<HttpMessageConverter<?>>();
	for (Iterator<HttpMessageConverter<?>> iterator = converters.iterator(); iterator
			.hasNext();) {
		HttpMessageConverter<?> converter = iterator.next();
		if ((converter instanceof AbstractXmlHttpMessageConverter)
				|| (converter instanceof MappingJackson2XmlHttpMessageConverter)) {
			xml.add(converter);
			iterator.remove();
		}
	}
	converters.addAll(xml);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:HttpMessageConverters.java


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