Java Magazine, Sept/Oct 2018
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2018 34 the leading edge This class is annotated with @ javax ejb Stateless marking it as a stateless session bean The javax ws rs Path annotation defines the URL path that can be used to access the class service endpoints The TeamRosterFacadeREST class contains two service methods find and findAll to find a TeamRoster or a List of TeamRoster respectively The service can be used by calling the URL http localhost 8080 SportsTeamQueryService rest teamrosterqueryservice or a TeamRoster ID can be passed as a path parameter by appending it to the end of the URL Registration service The SportsTeamRegistrationService exposes a web service capable of registering new players to a sports team The service is nearly identical to the SportsTeamQueryService with the exception of the TeamRosterFacadeREST class Listing 6 which contains different RESTful web service methods It contains a @ GET method named countRoster that returns a count of TeamRoster objects and a @ POST method named addPlayer that accepts parameters of type @ FormParam for a players first name last name and position The method creates a new TeamRoster object sets the values passed in as parameters and persists the object to the database using an EntityManager Finally the method returns a javax ws rs core Response to indicate success or failure To register a player a javax ws rs core Form can be sent via a JAX RS client to the addPlayer web service The following section demonstrates how to do so via a JSF user interface User interface service The SportsTeamUIService drives the user interface using the JSF framework The service also requires the JAX RS client dependency to query the SportsTeamQueryService web services and to register new players by using the SportsTeamRegistrationService The POM file is shown in Listing 7 The UI service could use any web framework but here I chose to use JSF Therefore the web views are created as XHTML files and CDI controller classes are used to communicate between the front end and the back end The main view the index xhtml file shown in Listing 8 simply uses a DataTable to list each of the registered players and it also contains a form for registering new players The backing beans behind index xhtml are CDI controllers named TeamRegistrationController shown in Listing 9 and TeamQueryController shown in Listing 10
You must have JavaScript enabled to view digital editions.