0% found this document useful (0 votes)
1 views19 pages

JavaEE TodoApp Section10

The Capstone Project 1 is a full-stack Java EE Todo App that covers Arquillian testing, JPA, EJB, REST, JWT security, and Docker deployment. It involves building a Todo application with user registration, login, and task management using Jakarta EE technologies, while implementing JWT for authentication and testing with Arquillian. The project culminates in a Docker deployment, showcasing a real-world enterprise application structure and integration of various Java EE concepts.

Uploaded by

csesanjay17
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views19 pages

JavaEE TodoApp Section10

The Capstone Project 1 is a full-stack Java EE Todo App that covers Arquillian testing, JPA, EJB, REST, JWT security, and Docker deployment. It involves building a Todo application with user registration, login, and task management using Jakarta EE technologies, while implementing JWT for authentication and testing with Arquillian. The project culminates in a Docker deployment, showcasing a real-world enterprise application structure and integration of various Java EE concepts.

Uploaded by

csesanjay17
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Capstone Project 1 - Todo App (Section 10)

• This project demonstrates a full-stack Java EE Todo App.


• Concepts covered: Arquillian testing, JPA, EJB, REST, JWT
Security, and Docker deployment.
• We'll develop, test, secure, and package a complete Todo
application.
Introduction to Capstone Project

• Objective: Build a Todo application with user registration, login,


and task management.
• Use Jakarta EE technologies: JPA, JAX-RS, EJB, CDI, Bean
Validation.
• Implement authentication using JWT for stateless sessions.
• Run and test using Arquillian and package with Docker.
Introduction to Testing with Arquillian

• Arquillian enables in-container testing of Java EE components.


• Part 1 and 2 explain dependency setup and integration with
JUnit.
• You can create deployment archives using ShrinkWrap and run
inside Payara or WildFly.
• Running our first test (Part 1 & 2) validates persistence and
business logic.
Arquillian Test Structure - Example

• @RunWith([Link])
• public class TodoServiceTest {
• @Inject private TodoService service;
• @Deployment public static Archive<?> createDeployment()
{...}
• @Test public void shouldSaveUser() {...}
• }
356–358. Modelling the TodoUser

• The TodoUser entity represents the application's registered


users.
• Includes basic attributes like email, password, and name.
• Validation constraints ensure input correctness.
• @Email, @NotNull, and @Size annotations enforce rules.
TodoUser Entity - Example

• public class TodoUser {


• @Id @GeneratedValue private Long id;
• @Email @NotNull private String email;
• @NotNull @Size(min=4) private String password;
• @NotNull private String name;
• }
Querying TodoUser and Todo Entity

• JPA queries allow fetching users and their todos.


• Todo entity includes fields: task, completed, and user
relationship.
• Example JPQL: SELECT t FROM Todo t WHERE [Link] = :uid
Todo Entity - Example

• public class Todo {


• @Id @GeneratedValue private Long id;
• private String task; private boolean completed;
• @ManyToOne private TodoUser user;
• }
TodoService Class

• TodoService is an @Stateless EJB handling business logic.


• Includes methods for saving users, saving todos, and querying
data.
• Implements user validation and persistence logic.
• SaveTodoUser method persists a new TodoUser instance.
TodoService Class - Example

• @Stateless public class TodoService {


• @PersistenceContext EntityManager em;
• public TodoUser saveUser(TodoUser u){ [Link](u); return
u; }
• public List<Todo> getTodosByUser(Long id){ ... }
• }
Todo Service Test and Preventing Double Signups

• Arquillian test verifies TodoService persistence methods.


• Double signup prevention checks if an email already exists
before saving.
• Throws WebApplicationException with 409 Conflict if
duplicate.
Implementing Todo Methods

• Find Todo by ID, Get List of Todos, and Get Todos by Task.
• These REST endpoints allow clients to view and filter todos.
• Example: @GET /todos?userId=1 returns all todos for a user.
Stateless Security with JWT

• JWT-based security ensures stateless authentication.


• Authz annotation and JWTFilter verify tokens for protected
endpoints.
• JWT library generates and validates tokens with secret keys.
• ContainerRequestFilter inspects headers to authorize access.
JWTFilter - Example

• public void filter(ContainerRequestContext ctx) throws IOException {


• String token =
[Link]([Link]).substring(7);
• try { [Link](token); }
• catch (Exception e) { [Link]([Link](401).build()); }
• }
REST Web Service

• UserResource handles signup and login using JAX-RS.


• TodoResource handles CRUD operations for Todo entities.
• RESTful API endpoints are stateless and secured using JWT
tokens.
UserResource - Example

• @Path('/users') public class UserResource {


• @POST @Path('/signup') public TodoUser signup(TodoUser
user){...}
• @POST @Path('/login') public Map<String,String>
login(TodoUser user){...}
• }
Running Our App

• Deploy the Todo App on Payara/WildFly server.


• Access endpoints via browser or REST client (e.g.,
Insomnia/Postman).
• Test signup, login, add todo, and retrieve todos.
• Validate token-based access to secured routes.
Packaging with Docker

• Create a Dockerfile to package the Todo App for deployment.


• FROM payara/micro COPY target/[Link]
/opt/payara/deployments/
• Build: docker build -t todoapp .
• Run: docker run -p 8080:8080 todoapp
Summary

• Capstone Project integrates all Java EE concepts: JPA, EJB, REST,


JWT, and Arquillian.
• Demonstrates real-world enterprise application structure.
• Docker deployment allows containerized testing and scalability.
• This completes Section 10 of the Udemy Java EE course.

You might also like