* Simple Boot REST application and example

* BAEL-509 - Removed extra duplicate ant matcher

* Example and Unit Tests

* documentation

* BAEL-1085 - changes per PR code review and document review - altered integration to unit test - all's good

* BAEL-1085 - Renamed unit tests and added both to pom.xml

* IntelliJ formatter

* REVERT - Had removed a duplicate ant matcher from BAEL-509 - this was the incorrect process - reverting now, article has been corrected, but will issue a seperate PR for this
This commit is contained in:
Adam InTae Gerard
2017-09-03 00:56:40 -07:00
committed by Zeger Hendrikse
parent b6830cc736
commit 4baaf9f984
18 changed files with 668 additions and 3 deletions

View File

@@ -0,0 +1,38 @@
package com.baeldung.controllers;
import com.baeldung.services.ExampleService;
import com.baeldung.transfer.ResponseTransfer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.baeldung.transfer.LoginForm;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/post")
public class ExamplePostController {
private static Logger log = LoggerFactory.getLogger(ExamplePostController.class);
@Autowired ExampleService exampleService;
@PostMapping("/request")
public ResponseEntity postController(@RequestBody LoginForm loginForm) {
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
exampleService.fakeAuthenticate(loginForm);
return ResponseEntity.ok(HttpStatus.OK);
}
@PostMapping("/response")
@ResponseBody
public ResponseTransfer postResponseController(@RequestBody LoginForm loginForm) {
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
return new ResponseTransfer("Thanks For Posting!!!");
}
}

View File

@@ -0,0 +1,14 @@
package com.baeldung.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class ViewController {
@GetMapping("/")
public String welcome() {
return "index";
}
}

View File

@@ -0,0 +1,12 @@
package com.baeldung.services;
import com.baeldung.transfer.LoginForm;
import org.springframework.stereotype.Service;
@Service
public class ExampleService {
public boolean fakeAuthenticate(LoginForm lf) {
return true;
}
}

View File

@@ -0,0 +1,25 @@
package com.baeldung.transfer;
public class LoginForm {
private String username;
private String password;
public LoginForm() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@@ -0,0 +1,18 @@
package com.baeldung.transfer;
public class ResponseTransfer {
private String text;
public ResponseTransfer(String text) {
this.setText(text);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}