Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

[Bug] No Postman funciona normal, contudo no Navegador recebo uma Exception.

Não estou entendo o por que no Postman eu consigo enviar esse formulário, mas quando tento no navegador dá uma exception: Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supported. segue as classes:

RegisterController:

//imports

@Controller
@RequestMapping("/StreamingDiary/register")
public class RegisterController {

    @Autowired
    private UserService userService;

    @GetMapping
    public String showRegisterForm(){
        return  "AuthenticationScreen/register";
    }

    @PostMapping
    public String processRegister(@RequestBody UserDTO user){
        userService.save(user);
        return "AuthenticationScreen/login";
    }
}

UserService

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public void save(UserDTO user){
        if(user == null){
            throw new RuntimeException("user cannot be null!");
        }
        userRepository.save(new UserEntity(user));
    }

    public UserDTO login(Email email, String password) {
        UserEntity user = userRepository.findByEmail(email);
        if(user != null && user.getPassword().equals(password)){
            return new UserDTO(user);
        }
        return null;
    }

}

register.html

<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{template.html}"
>
<head>
  <link rel="stylesheet" href="../static/css/style.css" th:href="@{/css/style.css}">
  <title>Register</title>
</head>
<body>

<div class="container">
  <form class="form" id="registerForm" method="post" action="/StreamingDiary/login">
    <h2>Register</h2>
    <label for="username">Nick name:</label>
    <input type="text" id="username" name="username" required>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
    <label for="password">Password:</label>
    <input type="password" id="password" name="password" required>
    <button type="submit">Inscribe</button>
    <a class="small-link" href="/StreamingDiary/login">Login</a>
  </form>
</div>

</body>
</html>
1 resposta
solução!

Encontrei esse link que relata o mesmo problema :https://stackoverflow.com/questions/33796218/content-type-application-x-www-form-urlencodedcharset-utf-8-not-supported-for. Aparentemente o problema seria o uso da anotação @RequestBody, e a solução seria remove-lo,.