org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter Java Examples
The following examples show how to use
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XpathRequestMatchersIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); List<Person> performers = Arrays.asList( new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true)); this.people = new PeopleWrapper(composers, performers); List<HttpMessageConverter<?>> converters = new ArrayList<>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #2
Source File: XmlContentRequestMatchersIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); this.people = new PeopleWrapper(composers); List<HttpMessageConverter<?>> converters = new ArrayList<>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #3
Source File: ServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-16172 public void httpEntityWithContentType() throws Exception { initServlet(wac -> { RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); messageConverters.add(new MappingJackson2HttpMessageConverter()); messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); adapterDef.getPropertyValues().add("messageConverters", messageConverters); wac.registerBeanDefinition("handlerAdapter", adapterDef); }, ResponseEntityController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test-entity"); MockHttpServletResponse response = new MockHttpServletResponse(); getServlet().service(request, response); assertEquals(200, response.getStatus()); assertEquals("application/xml", response.getHeader("Content-Type")); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<testEntity><name>Foo Bar</name></testEntity>", response.getContentAsString()); }
Example #4
Source File: AllEncompassingFormHttpMessageConverter.java From onetwo with Apache License 2.0 | 6 votes |
public AllEncompassingFormHttpMessageConverter() { addPartConverter(new SourceHttpMessageConverter<>()); if (jaxb2Present && !jackson2XmlPresent) { addPartConverter(new Jaxb2RootElementHttpMessageConverter()); } if (jackson2Present) { addPartConverter(new MappingJackson2HttpMessageConverter()); } else if (gsonPresent) { addPartConverter(new GsonHttpMessageConverter()); } /*else if (jsonbPresent) { addPartConverter(new JsonbHttpMessageConverter()); }*/ if (jackson2XmlPresent) { addPartConverter(new MappingJackson2XmlHttpMessageConverter()); } /*if (jackson2SmilePresent) { addPartConverter(new MappingJackson2SmileHttpMessageConverter()); }*/ }
Example #5
Source File: ExecuteTest.java From riptide with MIT License | 6 votes |
@Test void shouldFailIfNoConverterFoundForBodyOfUnknownContentType() { final MockSetup setup = new MockSetup("https://api.example.com", Collections.emptyList()); final MockRestServiceServer server = setup.getServer(); final Http unit = setup.getHttpBuilder() .converter(new Jaxb2RootElementHttpMessageConverter()).build(); // we never actually make the request, but the mock server is doing some magic pre-actively server.expect(requestTo(url)) .andRespond(withSuccess()); final CompletionException exception = assertThrows(CompletionException.class, () -> unit.delete(url) .body(new Success(true)) .dispatch(contentType()) .join()); assertThat(exception.getCause(), is(instanceOf(RestClientException.class))); assertThat(exception.getMessage(), containsString("no suitable HttpMessageConverter found")); assertThat(exception.getMessage(), containsString("org.zalando.riptide.model.Success")); }
Example #6
Source File: XpathRequestMatchersIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); List<Person> performers = Arrays.asList( new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true)); this.people = new PeopleWrapper(composers, performers); List<HttpMessageConverter<?>> converters = new ArrayList<>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #7
Source File: XmlContentRequestMatchersIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); this.people = new PeopleWrapper(composers); List<HttpMessageConverter<?>> converters = new ArrayList<>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #8
Source File: XmlContentRequestMatchersIntegrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); this.people = new PeopleWrapper(composers); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #9
Source File: XpathRequestMatchersIntegrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setup() { List<Person> composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN)); List<Person> performers = Arrays.asList( new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true)); this.people = new PeopleWrapper(composers, performers); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); converters.add(new Jaxb2RootElementHttpMessageConverter()); this.restTemplate = new RestTemplate(); this.restTemplate.setMessageConverters(converters); this.mockServer = MockRestServiceServer.createServer(this.restTemplate); }
Example #10
Source File: AllEncompassingFormHttpMessageConverter.java From spring4-understanding with Apache License 2.0 | 6 votes |
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()); } }
Example #11
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-16172 public void httpEntityWithContentType() throws Exception { initServlet(wac -> { RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); messageConverters.add(new MappingJackson2HttpMessageConverter()); messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); adapterDef.getPropertyValues().add("messageConverters", messageConverters); wac.registerBeanDefinition("handlerAdapter", adapterDef); }, ResponseEntityController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test-entity"); MockHttpServletResponse response = new MockHttpServletResponse(); getServlet().service(request, response); assertEquals(200, response.getStatus()); assertEquals("application/xml", response.getHeader("Content-Type")); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<testEntity><name>Foo Bar</name></testEntity>", response.getContentAsString()); }
Example #12
Source File: AllEncompassingFormHttpMessageConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public AllEncompassingFormHttpMessageConverter() { addPartConverter(new SourceHttpMessageConverter<Source>()); if (jaxb2Present && !jackson2XmlPresent) { addPartConverter(new Jaxb2RootElementHttpMessageConverter()); } if (jackson2Present) { addPartConverter(new MappingJackson2HttpMessageConverter()); } else if (gsonPresent) { addPartConverter(new GsonHttpMessageConverter()); } if (jackson2XmlPresent) { addPartConverter(new MappingJackson2XmlHttpMessageConverter()); } }
Example #13
Source File: RestTemplate.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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()); } }
Example #14
Source File: HttpClientConfig.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private List<HttpMessageConverter<?>> converters() { List<HttpMessageConverter<?>> result = Lists.newArrayList(); result.add(new ByteArrayHttpMessageConverter()); result.add(new StringHttpMessageConverter()); result.add(new ResourceHttpMessageConverter()); result.add(new SourceHttpMessageConverter<>()); result.add(new AllEncompassingFormHttpMessageConverter()); result.add(new Jaxb2RootElementHttpMessageConverter()); result.add(gsonHttpMessageConverter); return result; }
Example #15
Source File: RestTemplateFactory.java From sdk-rest with MIT License | 5 votes |
private static RestTemplate createRestTemplate() { List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new ByteArrayHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter(Charset.forName("UTF-8"))); messageConverters.add(new ResourceHttpMessageConverter()); messageConverters.add(new SourceHttpMessageConverter<Source>()); messageConverters.add(new AllEncompassingFormHttpMessageConverter()); messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); messageConverters.add(new MappingJackson2HttpMessageConverter()); return new RestTemplate(messageConverters); }
Example #16
Source File: DCTMJaxbClient.java From documentum-rest-client-java with Apache License 2.0 | 5 votes |
@Override protected void initRestTemplate(RestTemplate restTemplate) { super.initRestTemplate(restTemplate); restTemplate.setErrorHandler(new DCTMJaxbErrorHandler(restTemplate.getMessageConverters())); for(HttpMessageConverter<?> c : restTemplate.getMessageConverters()) { if(c instanceof FormHttpMessageConverter) { ((FormHttpMessageConverter)c).addPartConverter(new Jaxb2RootElementHttpMessageConverter()); break; } } }
Example #17
Source File: RestTemplate.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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()); } }
Example #18
Source File: AllEncompassingFormHttpMessageConverter.java From java-technology-stack with MIT License | 5 votes |
public AllEncompassingFormHttpMessageConverter() { try { addPartConverter(new SourceHttpMessageConverter<>()); } catch (Error err) { // Ignore when no TransformerFactory implementation is available } if (jaxb2Present && !jackson2XmlPresent) { addPartConverter(new Jaxb2RootElementHttpMessageConverter()); } if (jackson2Present) { addPartConverter(new MappingJackson2HttpMessageConverter()); } else if (gsonPresent) { addPartConverter(new GsonHttpMessageConverter()); } else if (jsonbPresent) { addPartConverter(new JsonbHttpMessageConverter()); } if (jackson2XmlPresent) { addPartConverter(new MappingJackson2XmlHttpMessageConverter()); } if (jackson2SmilePresent) { addPartConverter(new MappingJackson2SmileHttpMessageConverter()); } }
Example #19
Source File: AllEncompassingFormHttpMessageConverter.java From spring-analysis-note with MIT License | 5 votes |
public AllEncompassingFormHttpMessageConverter() { try { addPartConverter(new SourceHttpMessageConverter<>()); } catch (Error err) { // Ignore when no TransformerFactory implementation is available } if (jaxb2Present && !jackson2XmlPresent) { addPartConverter(new Jaxb2RootElementHttpMessageConverter()); } if (jackson2Present) { addPartConverter(new MappingJackson2HttpMessageConverter()); } else if (gsonPresent) { addPartConverter(new GsonHttpMessageConverter()); } else if (jsonbPresent) { addPartConverter(new JsonbHttpMessageConverter()); } if (jackson2XmlPresent) { addPartConverter(new MappingJackson2XmlHttpMessageConverter()); } if (jackson2SmilePresent) { addPartConverter(new MappingJackson2SmileHttpMessageConverter()); } }
Example #20
Source File: WebMvcConfigurationSupport.java From lams with GNU General Public License v2.0 | 4 votes |
/** * 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 (jackson2XmlPresent) { messageConverters.add(new MappingJackson2XmlHttpMessageConverter( Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build())); } else if (jaxb2Present) { messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); } if (jackson2Present) { messageConverters.add(new MappingJackson2HttpMessageConverter( Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build())); } else if (gsonPresent) { messageConverters.add(new GsonHttpMessageConverter()); } }
Example #21
Source File: WebConfig.java From Microservices-with-Spring-Cloud with MIT License | 4 votes |
@Override public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { converters.removeIf(c -> c instanceof Jaxb2RootElementHttpMessageConverter); }
Example #22
Source File: WebConfig.java From Microservices-with-Spring-Cloud with MIT License | 4 votes |
@Override public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { converters.removeIf(c -> c instanceof Jaxb2RootElementHttpMessageConverter); }
Example #23
Source File: WebConfig.java From Microservices-with-Spring-Cloud with MIT License | 4 votes |
@Override public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { converters.removeIf(c -> c instanceof Jaxb2RootElementHttpMessageConverter); }
Example #24
Source File: HttpMessageConvertersOverrideTest.java From riptide with MIT License | 4 votes |
@Bean @Qualifier("github-invalid") public ClientHttpMessageConverters githubInvalidHttpMessageConverters() { return new ClientHttpMessageConverters(singletonList(new Jaxb2RootElementHttpMessageConverter())); }
Example #25
Source File: HttpMessageConvertersOverrideTest.java From riptide with MIT License | 4 votes |
@Test void shouldOverride() { assertThat(unit.getConverters(), contains(instanceOf(Jaxb2RootElementHttpMessageConverter.class))); }
Example #26
Source File: TestRestConfiguration.java From moserp with Apache License 2.0 | 4 votes |
private void filterXmlConverters(RestTemplate restTemplate) { Stream<HttpMessageConverter<?>> messageConverterStream = restTemplate.getMessageConverters().stream(); Predicate<HttpMessageConverter<?>> noXmlConverters = httpMessageConverter -> !(httpMessageConverter instanceof Jaxb2RootElementHttpMessageConverter) && !(httpMessageConverter instanceof MappingJackson2XmlHttpMessageConverter); List<HttpMessageConverter<?>> filtered = messageConverterStream.filter(noXmlConverters).collect(Collectors.toList()); restTemplate.setMessageConverters(filtered); }
Example #27
Source File: RestTemplate.java From java-technology-stack with MIT License | 4 votes |
/** * Create a new instance of the {@link RestTemplate} using default settings. * Default {@link HttpMessageConverter HttpMessageConverters} are initialized. */ public RestTemplate() { this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); this.messageConverters.add(new ResourceHttpMessageConverter(false)); try { this.messageConverters.add(new SourceHttpMessageConverter<>()); } catch (Error err) { // Ignore when no TransformerFactory implementation is available } 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()); } else if (jsonbPresent) { this.messageConverters.add(new JsonbHttpMessageConverter()); } if (jackson2SmilePresent) { this.messageConverters.add(new MappingJackson2SmileHttpMessageConverter()); } if (jackson2CborPresent) { this.messageConverters.add(new MappingJackson2CborHttpMessageConverter()); } this.uriTemplateHandler = initUriTemplateHandler(); }
Example #28
Source File: RestTemplate.java From spring-analysis-note with MIT License | 4 votes |
/** * Create a new instance of the {@link RestTemplate} using default settings. * Default {@link HttpMessageConverter HttpMessageConverters} are initialized. */ public RestTemplate() { this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); this.messageConverters.add(new ResourceHttpMessageConverter(false)); try { this.messageConverters.add(new SourceHttpMessageConverter<>()); } catch (Error err) { // Ignore when no TransformerFactory implementation is available } 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()); } else if (jsonbPresent) { this.messageConverters.add(new JsonbHttpMessageConverter()); } if (jackson2SmilePresent) { this.messageConverters.add(new MappingJackson2SmileHttpMessageConverter()); } if (jackson2CborPresent) { this.messageConverters.add(new MappingJackson2CborHttpMessageConverter()); } this.uriTemplateHandler = initUriTemplateHandler(); }