Created
December 13, 2018 15:15
-
-
Save eldermoraes/1b32b2962bc9a5ea99a89aaf7c44ebb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("app1") | |
public class App1 { | |
@Inject | |
private Auth auth; | |
@GET | |
public Response helloWorld(String token) { | |
if (!auth.isLogged(token)) { | |
throw new WebApplicationException(Response.Status.UNAUTHORIZED); | |
} | |
return Response.ok("Hello World. Welcome to App1!").build(); | |
} | |
@POST | |
@Consumes("application/x-www-form-urlencoded") | |
public Response helloWorld(@FormParam("login") String login, @FormParam("password") String password) { | |
if (Objects.isNull(login) || Objects.isNull(password)) { | |
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); | |
} | |
String token = auth.login(login, password); | |
return Response | |
.ok("Hello World. Welcome to App1!") | |
.header("token", token) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment