It's a complete application that reads a RFID tag and then search information about it on a remote database accessed through a REST interface. To avoid an extensive blog post, I divided it in 4 parts:
Part 1: The Application
Part 2: Reading RFID from Java
Part 3: REST API and Security
Part 4: The Client
The application
We will demonstrate the use of RFID with JavaFX using a simple Application where a person with will pass a card on a RFID reader and our application will give more information about the person, or if the person is in the database.The application also allows you to register a new person, delete existing people and modify information.
The app will basically work as demonstrated on the following diagram:
The Application Database
The database contains person information and also the RFID related to it and we give roles to this person, so we can authorize the person(if needed).
We also have a table to add administrators that can access this database information:
Our application is responsible to guarantee that only authorized users can access and change the information in the database. As you can see, the table person has a column for the RFID tag and the client application will be simple responsible to read it and access the person information using a REST API.
Accessing the data from Java using JPA
We use Java to access the database. Our final application will be in a WAR deployed in an application server (I'll talk more about it on the next post) that implements JEE 6 specification, and one of the famous JEE specification is JPA, that allow us to handle database information.To set the application persistence we need to have the persistence.xml file, which is the descriptor responsible to declare general JPA configuration. See persistence.xml.
Notice it refers to a Datasource, the application server we will use is Wildfly and datasources can be declared using *-ds.xml. Deployable datasources can be placed in the WEB-INF directory of our WAR. In our application we have the people-ds.xml, that we configure to access the default filesystem based database that comes with Wildfly. Code of both XMLs:
Now our application is ready to access a database and to have access to it from Java, we created model objects and we use JPA annotations in order to declare the database correspondence with our Java class. See Person.java source code.
Finally, to handle this information, we use a class named EntityManager in our PersonService Stateless EJB class.
Now we are ready to expose our DB information through a REST interface. But it's a subject for the next post ;)
See Complete Source code of the WEB module
Nenhum comentário:
Postar um comentário