diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 2aa91aab45..07231e35f4 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -16,12 +16,23 @@ org.springframework spring-web ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework spring-webmvc ${org.springframework.version} + + org.springframework + spring-oxm + ${org.springframework.version} + @@ -67,6 +78,31 @@ 3.2.1 + + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + 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 c26e09ca54..d068910042 100644 --- a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java @@ -1,16 +1,44 @@ -package org.baeldung.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -@EnableWebMvc -@Configuration -@ComponentScan({ "org.baeldung.web" }) -public class WebConfig { - - public WebConfig() { - super(); - } - -} \ No newline at end of file +package org.baeldung.config; + +import java.util.List; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.xml.MarshallingHttpMessageConverter; +import org.springframework.oxm.xstream.XStreamMarshaller; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +@ComponentScan({ "org.baeldung.web" }) +public class WebConfig extends WebMvcConfigurerAdapter { + + public WebConfig() { + super(); + } + + // API + + @Override + public void configureMessageConverters(final List> messageConverters) { + messageConverters.add(marshallingHttpMessageConverter()); + messageConverters.add(new MappingJackson2HttpMessageConverter()); + + super.configureMessageConverters(messageConverters); + } + + // UTIL + + private final MarshallingHttpMessageConverter marshallingHttpMessageConverter() { + final MarshallingHttpMessageConverter marshallingHttpMessageConverter = new MarshallingHttpMessageConverter(); + final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller(); + marshallingHttpMessageConverter.setMarshaller(xstreamMarshaller); + marshallingHttpMessageConverter.setUnmarshaller(xstreamMarshaller); + + return marshallingHttpMessageConverter; + } + +} 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 d90a98d389..4dc6949c5d 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 @@ -4,11 +4,14 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; import org.baeldung.web.dto.Foo; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; @Controller public class FooController { @@ -17,7 +20,7 @@ public class FooController { super(); } - // API + // API - read @RequestMapping(method = RequestMethod.GET, value = "/foos/{id}") public @ResponseBody @@ -25,4 +28,12 @@ public class FooController { return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4)); } + // API - write + + @RequestMapping(method = RequestMethod.PUT, value = "/foos/{id}") + @ResponseStatus(HttpStatus.OK) + public void updateFoo(@PathVariable("id") final String id, @RequestBody final Foo foo) { + System.out.println(foo); + } + } diff --git a/spring-security-rest-full/pom.xml b/spring-security-rest-full/pom.xml index 4e45b9c18b..8b9eb62ca3 100644 --- a/spring-security-rest-full/pom.xml +++ b/spring-security-rest-full/pom.xml @@ -196,7 +196,7 @@ com.jayway.restassured rest-assured - 2.1.0 + 2.2.0 test @@ -275,12 +275,12 @@ 4.3.0.Final - 5.1.27 + 5.1.28 1.4.3.RELEASE - 2.2.3 + 2.3.0 1.7.5 @@ -291,7 +291,7 @@ 15.0 - 3.1 + 3.2.1 1.3