further marshalling work
This commit is contained in:
parent
71c8dffe40
commit
72edb72fd5
@ -16,12 +16,23 @@
|
|||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-oxm</artifactId>
|
||||||
|
<version>${org.springframework.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- web -->
|
<!-- web -->
|
||||||
|
|
||||||
@ -67,6 +78,31 @@
|
|||||||
<version>3.2.1</version>
|
<version>3.2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- logging -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> -->
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||||
|
</dependency>
|
||||||
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,16 +1,44 @@
|
|||||||
package org.baeldung.config;
|
package org.baeldung.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import java.util.List;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
@EnableWebMvc
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
@Configuration
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
@ComponentScan({ "org.baeldung.web" })
|
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
||||||
public class WebConfig {
|
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
public WebConfig() {
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
super();
|
|
||||||
}
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
}
|
@ComponentScan({ "org.baeldung.web" })
|
||||||
|
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
public WebConfig() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
// API
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureMessageConverters(final List<HttpMessageConverter<?>> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -4,11 +4,14 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
|||||||
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
||||||
|
|
||||||
import org.baeldung.web.dto.Foo;
|
import org.baeldung.web.dto.Foo;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class FooController {
|
public class FooController {
|
||||||
@ -17,7 +20,7 @@ public class FooController {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// API
|
// API - read
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
|
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
@ -25,4 +28,12 @@ public class FooController {
|
|||||||
return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.restassured</groupId>
|
<groupId>com.jayway.restassured</groupId>
|
||||||
<artifactId>rest-assured</artifactId>
|
<artifactId>rest-assured</artifactId>
|
||||||
<version>2.1.0</version>
|
<version>2.2.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -275,12 +275,12 @@
|
|||||||
|
|
||||||
<!-- persistence -->
|
<!-- persistence -->
|
||||||
<hibernate.version>4.3.0.Final</hibernate.version>
|
<hibernate.version>4.3.0.Final</hibernate.version>
|
||||||
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
|
<mysql-connector-java.version>5.1.28</mysql-connector-java.version>
|
||||||
<spring-data-jpa.version>1.4.3.RELEASE</spring-data-jpa.version>
|
<spring-data-jpa.version>1.4.3.RELEASE</spring-data-jpa.version>
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
|
|
||||||
<jackson.version>2.2.3</jackson.version>
|
<jackson.version>2.3.0</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
<!-- logging -->
|
||||||
<org.slf4j.version>1.7.5</org.slf4j.version>
|
<org.slf4j.version>1.7.5</org.slf4j.version>
|
||||||
@ -291,7 +291,7 @@
|
|||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>15.0</guava.version>
|
<guava.version>15.0</guava.version>
|
||||||
<commons-lang3.version>3.1</commons-lang3.version>
|
<commons-lang3.version>3.2.1</commons-lang3.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user