fix spring-rest configuration
This commit is contained in:
parent
e6d11e531c
commit
f2c52d6cfc
@ -15,10 +15,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring Boot Dependencies -->
|
<!-- Spring Boot Dependencies -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
@ -75,6 +72,11 @@
|
|||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.thoughtworks.xstream</groupId>
|
<groupId>com.thoughtworks.xstream</groupId>
|
||||||
<artifactId>xstream</artifactId>
|
<artifactId>xstream</artifactId>
|
||||||
@ -146,11 +148,19 @@
|
|||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jayway.restassured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<version>${rest-assured.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>2.6.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.esotericsoftware</groupId>
|
<groupId>com.esotericsoftware</groupId>
|
||||||
<artifactId>kryo</artifactId>
|
<artifactId>kryo</artifactId>
|
||||||
@ -231,10 +241,6 @@
|
|||||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||||
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
|
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
|
||||||
|
|
||||||
<!-- marshalling -->
|
|
||||||
|
|
||||||
<jackson.version>2.7.2</jackson.version>
|
|
||||||
|
|
||||||
<!-- various -->
|
<!-- various -->
|
||||||
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
||||||
|
|
||||||
|
@ -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.EnableWebMvc;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
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
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@ComponentScan({ "org.baeldung.web" })
|
@ComponentScan({ "org.baeldung.web" })
|
||||||
|
@ -35,7 +35,6 @@ public class FooController {
|
|||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Foo updateFoo(@PathVariable("id") final String id, @RequestBody final Foo foo) {
|
public Foo updateFoo(@PathVariable("id") final String id, @RequestBody final Foo foo) {
|
||||||
System.out.println(foo);
|
|
||||||
return foo;
|
return foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,12 @@
|
|||||||
|
|
||||||
<context:component-scan base-package="org.baeldung.web" />
|
<context:component-scan base-package="org.baeldung.web" />
|
||||||
|
|
||||||
<mvc:annotation-driven />
|
<mvc:annotation-driven>
|
||||||
|
<mvc:message-converters register-defaults="true">
|
||||||
|
<bean class="org.baeldung.config.converter.KryoHttpMessageConverter"/>
|
||||||
|
<bean class="org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter"/>
|
||||||
|
</mvc:message-converters>
|
||||||
|
</mvc:annotation-driven>
|
||||||
|
|
||||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
|
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
|
||||||
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
|
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
|
||||||
|
@ -3,9 +3,7 @@ package org.baeldung.web.test;
|
|||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.baeldung.config.converter.KryoHttpMessageConverter;
|
import org.baeldung.config.converter.KryoHttpMessageConverter;
|
||||||
import org.baeldung.web.dto.Foo;
|
import org.baeldung.web.dto.Foo;
|
||||||
@ -17,11 +15,7 @@ import org.springframework.http.HttpHeaders;
|
|||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
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.protobuf.ProtobufHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
|
||||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +44,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase {
|
|||||||
final String URI = BASE_URI + "foos/{id}";
|
final String URI = BASE_URI + "foos/{id}";
|
||||||
|
|
||||||
final RestTemplate restTemplate = new RestTemplate();
|
final RestTemplate restTemplate = new RestTemplate();
|
||||||
restTemplate.setMessageConverters(getMessageConverters());
|
|
||||||
|
|
||||||
final HttpHeaders headers = new HttpHeaders();
|
final HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
|
headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
|
||||||
@ -67,7 +60,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase {
|
|||||||
final String URI = BASE_URI + "foos/{id}";
|
final String URI = BASE_URI + "foos/{id}";
|
||||||
|
|
||||||
final RestTemplate restTemplate = new RestTemplate();
|
final RestTemplate restTemplate = new RestTemplate();
|
||||||
restTemplate.setMessageConverters(getMessageConverters());
|
|
||||||
|
|
||||||
final HttpHeaders headers = new HttpHeaders();
|
final HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||||
@ -83,7 +75,6 @@ public class SpringHttpMessageConvertersIntegrationTestsCase {
|
|||||||
public void givenConsumingXml_whenWritingTheFoo_thenCorrect() {
|
public void givenConsumingXml_whenWritingTheFoo_thenCorrect() {
|
||||||
final String URI = BASE_URI + "foos/{id}";
|
final String URI = BASE_URI + "foos/{id}";
|
||||||
final RestTemplate restTemplate = new RestTemplate();
|
final RestTemplate restTemplate = new RestTemplate();
|
||||||
restTemplate.setMessageConverters(getMessageConverters());
|
|
||||||
|
|
||||||
final Foo resource = new Foo(4, "jason");
|
final Foo resource = new Foo(4, "jason");
|
||||||
final HttpHeaders headers = new HttpHeaders();
|
final HttpHeaders headers = new HttpHeaders();
|
||||||
@ -129,20 +120,4 @@ public class SpringHttpMessageConvertersIntegrationTestsCase {
|
|||||||
assertThat(resource, notNullValue());
|
assertThat(resource, notNullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTIL
|
|
||||||
|
|
||||||
private List<HttpMessageConverter<?>> getMessageConverters() {
|
|
||||||
final List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user