Skip to content

Commit 9f9362d

Browse files
committed
[BAEL-18367] Moving articles from rest-spring-** pt 4
1 parent b15d47b commit 9f9362d

35 files changed

Lines changed: 190 additions & 562 deletions

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@
805805
<module>spring-reactive-kotlin</module>
806806
<module>spring-reactor</module>
807807
<module>spring-remoting</module>
808-
<module>spring-rest</module>
808+
<module>spring-rest-http</module>
809809
<module>spring-rest-angular</module>
810810
<module>spring-rest-compress</module>
811811
<module>spring-rest-testing</module>
@@ -1411,7 +1411,7 @@
14111411
<module>spring-reactive-kotlin</module>
14121412
<module>spring-reactor</module>
14131413
<module>spring-remoting</module>
1414-
<module>spring-rest</module>
1414+
<module>spring-rest-http</module>
14151415
<module>spring-rest-angular</module>
14161416
<module>spring-rest-compress</module>
14171417
<module>spring-rest-testing</module>

spring-rest-http/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Spring REST HTTP
2+
3+
This module contains articles about HTTP in REST APIs with Spring
4+
5+
### The Course
6+
The "REST With Spring" Classes: http://bit.ly/restwithspring
7+
8+
### Relevant Articles:
9+
10+
- [Guide to UriComponentsBuilder in Spring](https://www.baeldung.com/spring-uricomponentsbuilder)
11+
- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) - The tests contained for this article rely on the sample application within the [spring-resttemplate](/spring-resttemplate) module
12+
- [Returning Custom Status Codes from Spring Controllers](https://www.baeldung.com/spring-mvc-controller-custom-http-status-code)
13+
- [Spring @RequestMapping](https://www.baeldung.com/spring-requestmapping)
14+
- [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result)

spring-rest-http/pom.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>spring-rest-http</artifactId>
6+
<version>0.1-SNAPSHOT</version>
7+
<name>spring-rest-http</name>
8+
<packaging>war</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-boot-2</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../parent-boot-2</relativePath>
15+
</parent>
16+
17+
<dependencies>
18+
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-oxm</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.thoughtworks.xstream</groupId>
29+
<artifactId>xstream</artifactId>
30+
<version>${xstream.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-actuator</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-devtools</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
</dependency>
44+
45+
</dependencies>
46+
47+
48+
<properties>
49+
<xstream.version>1.4.9</xstream.version>
50+
</properties>
51+
52+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.baeldung.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.http.converter.HttpMessageConverter;
7+
8+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
9+
10+
import org.springframework.oxm.xstream.XStreamMarshaller;
11+
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
12+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
13+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
14+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
15+
16+
import java.text.SimpleDateFormat;
17+
import java.util.List;
18+
19+
/*
20+
* Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml
21+
*/
22+
@Configuration
23+
@EnableWebMvc
24+
@ComponentScan({ "com.baeldung.web", "com.baeldung.requestmapping" })
25+
public class MvcConfig implements WebMvcConfigurer {
26+
27+
public MvcConfig() {
28+
super();
29+
}
30+
31+
//
32+
33+
@Override
34+
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
35+
final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
36+
builder.indentOutput(true)
37+
.dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
38+
39+
}
40+
41+
42+
@Override
43+
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
44+
configurer.defaultContentType(MediaType.APPLICATION_JSON);
45+
}
46+
47+
@Override
48+
public void addCorsMappings(CorsRegistry registry) {
49+
registry.addMapping("/**");
50+
}
51+
}

spring-rest/src/main/java/com/baeldung/controllers/DeferredResultController.java renamed to spring-rest-http/src/main/java/com/baeldung/controllers/DeferredResultController.java

File renamed without changes.

spring-rest-simple/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java renamed to spring-rest-http/src/main/java/com/baeldung/requestmapping/BarMappingExamplesController.java

File renamed without changes.

spring-rest-simple/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java renamed to spring-rest-http/src/main/java/com/baeldung/requestmapping/BazzNewMappingsExampleController.java

File renamed without changes.

spring-rest-simple/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java renamed to spring-rest-http/src/main/java/com/baeldung/requestmapping/FooMappingExamplesController.java

File renamed without changes.

spring-rest-simple/src/main/java/com/baeldung/web/controller/status/ExampleController.java renamed to spring-rest-http/src/main/java/com/baeldung/web/controller/status/ExampleController.java

File renamed without changes.

spring-rest-simple/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java renamed to spring-rest-http/src/main/java/com/baeldung/web/controller/status/ForbiddenException.java

File renamed without changes.

0 commit comments

Comments
 (0)