RESTful Web Service with Java JAX-RS. Create & Deploy to AWS
This is a very practical video course aimed at beginner Java developers to help them build their very first RESTful Java Web Service with JAX-RS and Jersey framework as well as implement features like:
- User sign up,
- User sign in,
- Token base authentication.
Students will also learn how to encrypt user provided password, generate a public user id which is safe to pass around the network in HTTP Requests, and how to generate and securely store as well as validate a secure access token,
- Protect RESTful WebService endpoints,
- Update database records by implementing Update User Profile details feature,
- and learn how to Delete database records,
- Implement Email Verification feature using Amazon AWS SES(Simple Email Service)
Students will learn how to use Postman HTTP client software to send: HTTP POST, GET, DELETE and PUT requests, as well as how to set needed HTTP Headers. We will also cover how to:
- Send data to your RESTful WebService via HTTP Body and
- How to pass data via URL Query String and as a Path parameter
You will also learn how to make your RESTful Web Service accept and respond back with JSON or XML media type.
This video course also teaches how to install needed software on local computer to be able to build RESTful Java Web Service as well as:
- How to start up your own Linux server in Amazon cloud( AWS EC2),
- Install needed software on a remote EC2 instance and finally,
- How deploy created WebService on AWS EC2 instance.
Please note that even though this video course covers all of the above mentioned, it is not a comprehensive guide that covers, in little details, all and everything about building Web Services. There are still things to be learned. But you will definitely benefit and gain by learning the above mentioned material.
This section contains a link to download entire source code of my project.
Introduction to a course
In this video we will download and install Postman client which we will use in this course to send HTTP Requests to our RESTful WebService.
This video will cover Postman HTTP client user interface and show you how to use it to send HTTP Requests.
When building RESTful WebServices it is very important to understand what is a Resource and what is a Resource collection as well as how to structure a URL to a Resource and to a Resource collection. In this video we will learn how the URL to a Resource should be structured and look like.
In this video we will learn about most commonly used HTTP Methods and how they are being used in RESTful Web Services.
In this video we will learn about Accept and Content type HTTP headers and how they used with RESTful Web Services.
Development Environment: Netbeans
In this video we will download and Install Java Development Kit on our computer.
In this video I will give you an overview of Netbeans Development Environment which we will then download and install on our computer.
In this lesson I will introduce you to a Software Management Tool called Maven. We will then learn how to create a new Java project using Maven.
In this video we are going to learn how to add dependency libraries to our project. We will use Maven to download and add to our project following libraries: Jersey framework, MySQL database server and Hibernate framework.
In this lesson we will learn how to download and install on our local computer Apache Tomcat Servlet Container. We will also learn how to add Apache Tomcat to our Netbeans project.
What if You Use IntelliJ?
What if You Use Eclipse
MySQL Database on Local Computer
In this lesson we will download and install MySQL database server.
In this video we will learn how to create a new database and a new database user.
In this video we will talk about the Hibernate configuration file learn how to configure it so that we can use Hibernate framework to persist Java objects into MySQL database.
In this lesson I will give you an overview of how I have organized my code in this project. There are three main layers I am going to introduce you to: Presentation layer, Service layer and Data layer and you will learn what objects live in each of these layers.
In this lesson we will create our Web Service application starting point.
HTTP POST. Creating New User Profile
In this video we are going to create a Web Service Resource Class which will be responsible for accepting HTTP Requests and responding to those HTTP Requests and this Resource class service HTTP requests that are only related to working with User and their Profile. For example to create a new user in our application we will send an HTTP Post request, and it is this Resource class, that will be responsible for handling that HTTP request and responding to it. Or if our mobile application needs to update or delete user profile, it is also this Resource class that will be service these http requests.
This resource class will need to be annotated with @Path annotation which will be used to specify the URI path to this resource class. For example by annotating this resource class with @Path("/users") we are making it available for http requests which are sent to a /api/users web service endpoint.
In this video we are going to create two Plain Old Java Objects which will be used when the framework needs to convert the JSON Payload into Java object when HTTP Request arrives and then back from Java to JSON or XML when we need to send the HTTP Response back.
And this conversion of JSON to Java and from Java back to JSON is done by the Jersey framework for us and we do not need to do anything manually other than create a Java class that will match the fields in the JSON object.
Also, I am going to use the Java Architecture for XML Binding (JAXB) approach and will annotate my Java Model classes with @XmlRootElement. The use JAXB will allow me to support both XML and JSON as a MediaType of the Resource Representation my Web Service sends back to a mobile application.
In this video we are going to create a UserService interface and interface implementation code.
In this video we will write code to check if all the required fields are present and their values are not empty.
In this video we will start talking about how to handle errors in our Web Services project and will create a first class that will hold the description of error messages that we will handle and return back with a HTTP Response.
In this video we are going to create our first custom exception class which is a Missing Required Field Exception.
In this video I am going to show you how to enable Netbeans hits and how to install a Netbeans plugin that generates a unique value for serialVersionUID
In this lesson we will create an ErrorMessage class which will eventually we converted into JSON or XML format and returned back with HTTP Response of an error took place.
In this lesson we will learn how to create Exception Mapper class and how to make it return the error message we want.
In this video we will run our project and will send an HTTP request which should trigger and error message. We will see how an error message is triggered and returned back with HTTP response.
In those cases when an error took place and we do not have a handler for that Exception message, we will use a Generic Exception Mapper class to handle all other error messages. This way we will always return back a properly formatted error message in JSON format.
Working with Database
In thi lesson we will learn what is an Entity class and will create our very first Entity class which will be persisted into MySQL database.
In this video we will learn how to register Entity classes in Hibernate configuration file.
In this video we will create a Database Access Object which will encapsulate code that communicates with Database. If eventually we need to go away from Hibernate and MySQL database we can simply add another Database Access Object class and will not need to rework our application much.
In this video we will write Java code to create a Hibernate Session Factory class.
In this video we will learn how to generate a secure public user id value which is safe to pass around the network and is safe to include in HTTP requests.
In this video we will learn how to encrypt user provided clear text password and how it should be stored in a database.
In this video we will write code to persist user details in a database.
In this video we will sent HTTP POST request to create a new user and see if the code we have put together until now works well.
In this video we are going to configure our project to use a better connection pooling algorithm - the C3P0 Connections Pooling Provider.
Hibernate's internal connection pooling algorithm is rudimentary, and is provided for development and testing purposes. And when our application is ready to be published into production environment it is recommended that a better connection pooling algorithm is used.
HTTP GET. Get User Profile API Call
In this video we will learn about two new annotations and how they are used: @Path and @PathParam.
In this lesson we will create a new custom Exception class - NoRecordFoundException.
In this video we will prepare Service layer and Data Access layer code for our get user profile functionality.
In this video we will send HTTP GET request to try if the code we have put together so far works well and we can retried the user record with provided user id.
User Sign In and Secure Access Token
In this video we will start working on Authentication Web Service End Point.
In this lesson we will create an AuthenticationException which will be thrown when user authentication fails.
In this video we will write Java code for an Authentication Service layer.
In this video we will learn how to generate a secure access token and include it in HTTP Response.
In this video we will try how the Authentication Web Service Endpoint works and if the provided access token can be successfully validated.
To make our Authentication mechanism more secure we will reset security credentials and the secure access token every time when user successfully sign in using our Authentication Service.
Access Protected WS Endpoints With Access Token
In this video we will learn how to use @NameBinding to create a @Secure annotation which will be used to protect WebService endpoints that required Authentication.
In this video we will create an Authentication Filter class to perform Token-Based Authentication.
In this video we will annotate the Get User Profile WebService endpoint with @Secure annotation to make the WebService endpoint protected and require an authentication to be performed before a user details can be returned with a response.
Get All Users. Implementing Pagination.
When the number if registered users grows to thousands it is not a good idea to return entire list of users in a single response. Mobile applications and web sites implement pagination functionality to return a certain amount of records per page.
In this lesson I will introduce you to @QueryParam and @Default value annotations and we will learn how to implement support for "pagination" in our RESTful Webservice.
In this video we will write code for the Service Layer of our Get Users http request.
In this video we will write code for Data layer of our Get Users functionality. We will learn how to query a list of users from a database and limit the result list to a requested range of records.
In this video we will try how to Get Users HTTP Request works and if the implemented pagination supports works well and returns a requested range of records.
HTTP PUT. Update User Details Request.
In this video we will start working on an Update User details functionality and I will introduce you to a new @PUT annotation.
In this video we will be working on a Service and Data layer code for our update User Profile functionality.
In this video we will use Postman tool to send HTTP PUT request to see of the code we have prepared for the Update user profile functionality works and we can successfully update user details.
HTTP DELETE. Delete User Details
In this video we will start working on the Delete user functionality and I will introduce you to a new @DELETE annotation.
In this lesson we will be working on Service Layer and Data layer code for our Delete record functionality.
In this video we will user Postman tool to send HTTP DELETE request to see if out Delete record functionality works well and we can successfully delete user profile details from our database.
Free Video Course that uses this API
Deploy Web Service App on Amazon EC2 Linux Server
In this video I will introduce you to Amazon Web Services(AWS) page and we will learn how to start up our very own AWS EC2 Linux Server. I will walk you through the needed steps and we will finish up with a new Linux server running in Amazon cloud.
In this video I will show you how to connect to your EC2 Linux server via SSH.
In this video we will learn how to update software packages on our newly started Linux server in Amazon cloud and how to update Java and switch to a specific version of Java we need.
In this video we will learn how to download and Install Apache Tomcat on our EC2 Linux Server. I will also show you how to start up, stop and restart your Apache Tomcat Servlet container on Linux Server.
To be able to deploy your RESTful Web Service application into Tomcat Servlet Container we will need to configure a new user with proper permissions. In this video I will show you how to add a new Tomcat user. You will use the credentials we will create in this video to deploy your RESTful WebService on your EC2 instance.
In this video you will learn how to download and install MySQL Server on your EC2 server.
In this video you will learn how to create a new Database and a new database user. The credentials of this newly created user will need to be added to our Web Services project so that it can communicate with the database we will create in this video.
In this video we will learn how to deploy our RESTful Web Service application on to Apache Tomcat Servlet Container running on our own server in Amazon cloud.
In this video we will use Postman tool to send HTTP request to a remote AWS EC2 instance and see of our RESTful Web Service application can successfully communicate with MySQL database and can write and read records from it.
Implement Email Verification Feature with AWS SES (Simple Email Service)
In this video we will learn how to use Amazon AWS SES(Simple Email Service) to verify the email address which we will use as a Sender email address. Sender email address is an email address on behalf of which an email message is sent.