Skip to content

Instantly share code, notes, and snippets.

@eldermoraes
Created December 13, 2018 15:16
Show Gist options
  • Save eldermoraes/8ba0e1af831a2a0164aa3b72d5119a9b to your computer and use it in GitHub Desktop.
Save eldermoraes/8ba0e1af831a2a0164aa3b72d5119a9b to your computer and use it in GitHub Desktop.
@Path("app2")
public class App2 {
@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 App2!").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 App2!")
.header("token", token)
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment