cleanup and testing work

This commit is contained in:
eugenp
2016-10-12 08:00:02 +03:00
parent 2aa2f43c6e
commit eb7650eead
24 changed files with 259 additions and 271 deletions
@@ -2,14 +2,14 @@ package com.baeldung.model;
public class Message {
private String from;
private String text;
private String from;
private String text;
public String getText() {
return text;
}
public String getText() {
return text;
}
public String getFrom() {
return from;
}
public String getFrom() {
return from;
}
}
@@ -2,26 +2,26 @@ package com.baeldung.model;
public class OutputMessage {
private String from;
private String text;
private String time;
private String from;
private String text;
private String time;
public OutputMessage(final String from, final String text, final String time) {
public OutputMessage(final String from, final String text, final String time) {
this.from = from;
this.text = text;
this.time = time;
}
this.from = from;
this.text = text;
this.time = time;
}
public String getText() {
return text;
}
public String getText() {
return text;
}
public String getTime() {
return time;
}
public String getTime() {
return time;
}
public String getFrom() {
return from;
}
public String getFrom() {
return from;
}
}
@@ -10,15 +10,15 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/chat").withSockJS();
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/chat").withSockJS();
}
}
@@ -22,59 +22,55 @@ import com.baeldung.model.Company;
@Controller
public class CompanyController {
Map<Long, Company> companyMap = new HashMap<>();
Map<Long, Company> companyMap = new HashMap<>();
@RequestMapping(value = "/company", method = RequestMethod.GET)
public ModelAndView showForm() {
return new ModelAndView("companyHome", "company", new Company());
}
@RequestMapping(value = "/company", method = RequestMethod.GET)
public ModelAndView showForm() {
return new ModelAndView("companyHome", "company", new Company());
}
@RequestMapping(value = "/company/{Id}", produces = { "application/json",
"application/xml" }, method = RequestMethod.GET)
public @ResponseBody Company getCompanyById(@PathVariable final long Id) {
return companyMap.get(Id);
}
@RequestMapping(value = "/company/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET)
public @ResponseBody Company getCompanyById(@PathVariable final long Id) {
return companyMap.get(Id);
}
@RequestMapping(value = "/addCompany", method = RequestMethod.POST)
public String submit(@ModelAttribute("company") final Company company,
final BindingResult result, final ModelMap model) {
if (result.hasErrors()) {
return "error";
}
model.addAttribute("name", company.getName());
model.addAttribute("id", company.getId());
@RequestMapping(value = "/addCompany", method = RequestMethod.POST)
public String submit(@ModelAttribute("company") final Company company, final BindingResult result, final ModelMap model) {
if (result.hasErrors()) {
return "error";
}
model.addAttribute("name", company.getName());
model.addAttribute("id", company.getId());
companyMap.put(company.getId(), company);
companyMap.put(company.getId(), company);
return "companyView";
}
return "companyView";
}
@RequestMapping(value = "/companyEmployee/{company}/employeeData/{employee}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Map<String, String>> getEmployeeDataFromCompany(
@MatrixVariable(pathVar = "employee") final Map<String, String> matrixVars) {
return new ResponseEntity<>(matrixVars, HttpStatus.OK);
}
@RequestMapping(value = "/companyEmployee/{company}/employeeData/{employee}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Map<String, String>> getEmployeeDataFromCompany(@MatrixVariable(pathVar = "employee") final Map<String, String> matrixVars) {
return new ResponseEntity<>(matrixVars, HttpStatus.OK);
}
@RequestMapping(value = "/companyData/{company}/employeeData/{employee}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Map<String, String>> getCompanyName(
@MatrixVariable(value = "name", pathVar = "company") final String name) {
final Map<String, String> result = new HashMap<String, String>();
result.put("name", name);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestMapping(value = "/companyData/{company}/employeeData/{employee}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Map<String, String>> getCompanyName(@MatrixVariable(value = "name", pathVar = "company") final String name) {
final Map<String, String> result = new HashMap<String, String>();
result.put("name", name);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Company getCompanyResponseBody() {
final Company company = new Company(2, "ABC");
return company;
}
@RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Company getCompanyResponseBody() {
final Company company = new Company(2, "ABC");
return company;
}
@RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Company> getCompanyResponseEntity() {
final Company company = new Company(3, "123");
return new ResponseEntity<Company>(company, HttpStatus.OK);
}
@RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Company> getCompanyResponseEntity() {
final Company company = new Company(3, "123");
return new ResponseEntity<Company>(company, HttpStatus.OK);
}
}
@@ -31,10 +31,8 @@ public class EmployeeController {
return new ModelAndView("employeeHome", "employee", new Employee());
}
@RequestMapping(value = "/employee/{Id}", produces = {"application/json", "application/xml"}, method = RequestMethod.GET)
public
@ResponseBody
Employee getEmployeeById(@PathVariable final long Id) {
@RequestMapping(value = "/employee/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET)
public @ResponseBody Employee getEmployeeById(@PathVariable final long Id) {
return employeeMap.get(Id);
}
@@ -10,15 +10,15 @@ import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping("/message")
public class MessageController {
@RequestMapping(value = "/showForm", method = RequestMethod.GET)
public String showForm() {
return "message";
}
@RequestMapping(value = "/showForm", method = RequestMethod.GET)
public String showForm() {
return "message";
}
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
public String processForm(@RequestParam("message") final String message, final Model model) {
model.addAttribute("message", message);
return "message";
}
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
public String processForm(@RequestParam("message") final String message, final Model model) {
model.addAttribute("message", message);
return "message";
}
}
@@ -6,8 +6,8 @@ import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpRespon
@ControllerAdvice
public class JsonpControllerAdvice extends AbstractJsonpResponseBodyAdvice {
public JsonpControllerAdvice() {
super("callback");
}
public JsonpControllerAdvice() {
super("callback");
}
}