这是在使用org.springframework.web.client.RestTemplate对服务进行休息调用的rest客户端的上下文中。
它使用XStreamMarshaller将实体编组为XML。
final public MarshallingHttpMessageConverter marshallingHttpMessageConverter(){
final MarshallingHttpMessageConverter marshallingHttpMessageConverter = new MarshallingHttpMessageConverter();
marshallingHttpMessageConverter.setMarshaller( xstreamMarshaller() );
marshallingHttpMessageConverter.setUnmarshaller( xstreamMarshaller() );
return marshallingHttpMessageConverter;
}
final public XStreamMarshaller xstreamMarshaller(){
final XStreamMarshaller xStreamMarshaller = new XStreamMarshaller();
xStreamMarshaller.setAutodetectAnnotations( true );
xStreamMarshaller.setMode( XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);
xStreamMarshaller.setAnnotatedClasses( new Class[] { User.class, UserRole.class, Role.class, RolePrivilege.class, Privilege.class } );
xStreamMarshaller.getXStream().addDefaultImplementation( java.sql.Timestamp.class, java.util.Date.class );
return xStreamMarshaller;
}
如何使用XStreamMarshaller手动获取在进行HTTP调用之前通过网络发送的XML?