I consider using fluent-http in a project.
I started with a simple "login/password" page. I create a simple POJO with fields login and password :
public class LoginRequest() {
private String login;
private String password;
//...
}
And I send it to fluent-http via a Resource :
@Prefix("/user")
public class PersonResource {
@Post("/")
public String get(LoginRequest loginRequest) {
//[...]
}
}
And it works well :)
Now, I wondered if it was possible to send a response with code HTTP 200 in case of success and code HTTP 401 in case of failure.
So I tried to inject the Response :
@Post("/")
public String login(LoginRequest loginRequest, Response response) {
if(loginRequest.getPassword().equals("helloworld")) {
response.setStatus(200);
return "SUCCESS";
} else {
response.setStatus(401);
return "ERROR";
}
}
The correct String is returned but the status code does not seem to be used. In both cases, the response has a code HTTP 200.
Note : I found that some status code are pre-implemented :
- In case of exception, a code 500 is returned.
- In case of resource not found, a code 400 is returned.
Any idea?