Skip to content

Commit

Permalink
RESTFUL WEB SERVICES 2.3.1 UPGRADE
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranga Karanam authored and Ranga Karanam committed Jun 23, 2020
1 parent 6d76841 commit 5c6dbe1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
27 changes: 24 additions & 3 deletions 02.restful-web-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

<dependencies>
Expand All @@ -35,6 +36,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- START AND STOP THE APPLICATION AFTER MAKING THE CHANGE! -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!--<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -65,13 +72,19 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webmvc</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -111,6 +124,14 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jfrog-snapshots</id>
<name>JFROG Snapshots</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2
@EnableSwagger2WebMvc
public class SwaggerConfig {

public static final Contact DEFAULT_CONTACT = new Contact(
Expand All @@ -23,7 +23,7 @@ public class SwaggerConfig {
public static final ApiInfo DEFAULT_API_INFO = new ApiInfo(
"Awesome API Title", "Awesome API Description", "1.0",
"urn:tos", DEFAULT_CONTACT,
"Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0");
"Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Arrays.asList());

private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES =
new HashSet<String>(Arrays.asList("application/json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.in28minutes.rest.webservices.restfulwebservices.user;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import java.net.URI;
import java.util.List;
Expand All @@ -10,8 +10,8 @@
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -36,17 +36,17 @@ public List<User> retrieveAllUsers() {
}

@GetMapping("/jpa/users/{id}")
public Resource<User> retrieveUser(@PathVariable int id) {
public EntityModel<User> retrieveUser(@PathVariable int id) {
Optional<User> user = userRepository.findById(id);

if (!user.isPresent())
throw new UserNotFoundException("id-" + id);

// "all-users", SERVER_PATH + "/users"
// retrieveAllUsers
Resource<User> resource = new Resource<User>(user.get());
EntityModel<User> resource = EntityModel.of(user.get());//new EntityModel<User>(user.get());

ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());
WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());

resource.add(linkTo.withRel("all-users"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.in28minutes.rest.webservices.restfulwebservices.user;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import java.net.URI;
import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -32,7 +32,7 @@ public List<User> retrieveAllUsers() {
}

@GetMapping("/users/{id}")
public Resource<User> retrieveUser(@PathVariable int id) {
public EntityModel<User> retrieveUser(@PathVariable int id) {
User user = service.findOne(id);

if(user==null)
Expand All @@ -41,9 +41,9 @@ public Resource<User> retrieveUser(@PathVariable int id) {

//"all-users", SERVER_PATH + "/users"
//retrieveAllUsers
Resource<User> resource = new Resource<User>(user);
EntityModel<User> resource = EntityModel.of(user);

ControllerLinkBuilder linkTo =
WebMvcLinkBuilder linkTo =
linkTo(methodOn(this.getClass()).retrieveAllUsers());

resource.add(linkTo.withRel("all-users"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ management.endpoints.web.exposure.include=*
spring.security.user.name=username
spring.security.user.password=password
spring.jpa.show-sql=true
spring.h2.console.enabled=true
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.data.jpa.repositories.bootstrap-mode=default

0 comments on commit 5c6dbe1

Please sign in to comment.