From f2c52d6cfcf42bc0f83a4be5383f75d3daf8f246 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 12 Sep 2016 12:55:46 +0200 Subject: [PATCH] fix spring-rest configuration --- spring-rest/pom.xml | 22 ++++++++++------ .../java/org/baeldung/config/WebConfig.java | 5 ++++ .../web/controller/FooController.java | 1 - .../src/main/webapp/WEB-INF/api-servlet.xml | 7 +++++- spring-rest/src/main/webapp/WEB-INF/web.xml | 4 +-- ...MessageConvertersIntegrationTestsCase.java | 25 ------------------- 6 files changed, 27 insertions(+), 37 deletions(-) diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index e28f7e7e33..0c0d6219dd 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -15,10 +15,7 @@ - - org.springframework.boot - spring-boot-starter-security - + org.springframework.boot spring-boot-starter-thymeleaf @@ -74,6 +71,11 @@ com.fasterxml.jackson.core jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + com.thoughtworks.xstream @@ -146,11 +148,19 @@ spring-test + + com.jayway.restassured + rest-assured + ${rest-assured.version} + + + com.google.protobuf protobuf-java 2.6.1 + com.esotericsoftware kryo @@ -231,10 +241,6 @@ 4.3.11.Final 5.1.39 - - - 2.7.2 - 5.2.2.Final diff --git a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java index d5cd6e1eae..d116148f09 100644 --- a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java @@ -15,6 +15,11 @@ import org.springframework.oxm.xstream.XStreamMarshaller; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +/* + * Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml + * + */ + @Configuration @EnableWebMvc @ComponentScan({ "org.baeldung.web" }) diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java b/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java index 386c64bb09..dd1e3ca222 100644 --- a/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java @@ -35,7 +35,6 @@ public class FooController { @ResponseStatus(HttpStatus.OK) @ResponseBody public Foo updateFoo(@PathVariable("id") final String id, @RequestBody final Foo foo) { - System.out.println(foo); return foo; } diff --git a/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml b/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml index 5afc637ece..c08faaf70d 100644 --- a/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml +++ b/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml @@ -8,7 +8,12 @@ - + + + + + + diff --git a/spring-rest/src/main/webapp/WEB-INF/web.xml b/spring-rest/src/main/webapp/WEB-INF/web.xml index 01e7620c44..a439de8a05 100644 --- a/spring-rest/src/main/webapp/WEB-INF/web.xml +++ b/spring-rest/src/main/webapp/WEB-INF/web.xml @@ -8,7 +8,7 @@ Spring MVC Application - + contextClass org.springframework.web.context.support.AnnotationConfigWebApplicationContext @@ -18,7 +18,7 @@ contextConfigLocation org.baeldung.config - + org.springframework.web.context.ContextLoaderListener diff --git a/spring-rest/src/test/java/org/baeldung/web/test/SpringHttpMessageConvertersIntegrationTestsCase.java b/spring-rest/src/test/java/org/baeldung/web/test/SpringHttpMessageConvertersIntegrationTestsCase.java index 1536f14bc8..1dfe509c09 100644 --- a/spring-rest/src/test/java/org/baeldung/web/test/SpringHttpMessageConvertersIntegrationTestsCase.java +++ b/spring-rest/src/test/java/org/baeldung/web/test/SpringHttpMessageConvertersIntegrationTestsCase.java @@ -3,9 +3,7 @@ package org.baeldung.web.test; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import org.baeldung.config.converter.KryoHttpMessageConverter; import org.baeldung.web.dto.Foo; @@ -17,11 +15,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; -import org.springframework.http.converter.xml.MarshallingHttpMessageConverter; -import org.springframework.oxm.xstream.XStreamMarshaller; import org.springframework.web.client.RestTemplate; /** @@ -50,7 +44,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase { final String URI = BASE_URI + "foos/{id}"; final RestTemplate restTemplate = new RestTemplate(); - restTemplate.setMessageConverters(getMessageConverters()); final HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML)); @@ -67,7 +60,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase { final String URI = BASE_URI + "foos/{id}"; final RestTemplate restTemplate = new RestTemplate(); - restTemplate.setMessageConverters(getMessageConverters()); final HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @@ -83,7 +75,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase { public void givenConsumingXml_whenWritingTheFoo_thenCorrect() { final String URI = BASE_URI + "foos/{id}"; final RestTemplate restTemplate = new RestTemplate(); - restTemplate.setMessageConverters(getMessageConverters()); final Foo resource = new Foo(4, "jason"); final HttpHeaders headers = new HttpHeaders(); @@ -129,20 +120,4 @@ public class SpringHttpMessageConvertersIntegrationTestsCase { assertThat(resource, notNullValue()); } - // UTIL - - private List> getMessageConverters() { - final List> converters = new ArrayList>(); - - final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter(); - final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller(); - xmlConverter.setMarshaller(xstreamMarshaller); - xmlConverter.setUnmarshaller(xstreamMarshaller); - - converters.add(xmlConverter); - converters.add(new MappingJackson2HttpMessageConverter()); - - return converters; - } - }