Red Hat JBoss Developer Studio 8.0 Start Developing

Similar documents
Red Hat CloudForms 3.2 NetApp Storage Integration Guide

Red Hat Customer Portal 1 Managing User Access to the Red Hat Customer Portal and the Red Hat Network Application

Red Hat Cloud Infrastructure 5 Release Notes

Red Hat CloudForms 3.1 Management Engine 5.3 OpenShift Enterprise Deployment Guide

Red Hat Enterprise Virtualization 3.6- Beta Java SDK Guide

Red Hat Cloud Infrastructure 5 Introduction to Red Hat Cloud Infrastructure Architecture

JBoss Developer Studio 6.0

Red Hat JBoss Core Services Apache HTTP Server 2.4 Apache HTTP Server Installation Guide

Red Hat JBoss Data Virtualization 6.1 Migration Guide

Red Hat Enterprise Linux OpenStack Platform 7 OpenStack Data Processing

Red Hat JBoss BPM Suite 6.1 IBM WebSphere Installation and Configuration Guide

Red Hat JBoss Developer Studio 7.0 User Guide

Red Hat Subscription Management All Subscription Docs Quick Registration for RHEL

Red Hat Cloud Infrastructure 6 Getting Started with the Red Hat Cloud Infrastructure Unified Installer

Red Hat Enterprise Linux 7 High Availability Add-On Overview

Red Hat JBoss Developer Studio Release Notes

Red Hat JBoss Fuse 6.1 Cloud Computing with Fabric

Red Hat JBoss Developer Studio 7.1 Installation Guide

Red Hat JBoss Fuse 6.2 Management Console User Guide

Red Hat JBoss Developer Studio 4.1 Smooks Developer Tools Reference Guide

Red Hat Customer Portal Current Customer Portal Subscription Management

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

IBM TRIRIGA Anywhere Version 10 Release 4. Installing a development environment

Red Hat Enterprise Virtualization 3.0 User Portal Guide. Accessing and Using Virtual Machines from the User Portal Edition 1

Crystal Reports Installation Guide

Red Hat Enterprise Linux 7 High Availability Add-On Administration. Configuring and Managing the High Availability Add-On

Red Hat JBoss A-MQ 6.2 Cloud Deployment Guide

Building and Using Web Services With JDeveloper 11g

JBoss Developer Studio 4.1

JBoss Developer Studio 3.0

Red Hat Cloud Infrastructure 4 Quick Start for Red Hat Enterprise Virtualization and Red Hat CloudForms

Setting up SQL Translation Framework OBE for Database 12cR1

Cloud Administration Guide for Service Cloud. August 2015 E

Red Hat Network Satellite 5.5 Channel Management Guide

Installing and Configuring Adobe LiveCycle 9.5 Connector for Microsoft SharePoint

Getting Started using the SQuirreL SQL Client

JBoss Developer Studio 3.0

JBoss Operations Network 3.1 Deploying Applications and Content

1.- L a m e j o r o p c ió n e s c l o na r e l d i s co ( s e e x p li c a r á d es p u é s ).

Red Hat Directory Server 8.2 Using the Directory Server Console

Tutorial: BlackBerry Object API Application Development. Sybase Unwired Platform 2.2 SP04

Red Hat Enterprise Linux OpenStack Platform 7 Back Up and Restore Red Hat Enterprise Linux OpenStack Platform

Tutorial: Mobile Business Object Development. SAP Mobile Platform 2.3

Red Hat JBoss Developer Studio 7.0 JBoss SOAP Web Services User Guide

Ahsay Offsite Backup Server and Ahsay Replication Server

Tutorial: Mobile Business Object Development. SAP Mobile Platform 2.3 SP02

IBM Rational University. Essentials of IBM Rational RequisitePro v7.0 REQ370 / RR331 October 2006 Student Workbook Part No.

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

JBoss Developer Studio 3.0

Portions of this product were created using LEADTOOLS LEAD Technologies, Inc. ALL RIGHTS RESERVED.

Red Hat JBoss Fuse 6.1 Cloud Deployment Guide

Put the human back in Human Resources.

Tutorial: Mobile Business Object Development. Sybase Unwired Platform 2.2 SP02

Query JD Edwards EnterpriseOne Customer Credit using Oracle BPEL Process Manager

ORACLE BUSINESS INTELLIGENCE WORKSHOP. Prerequisites for Oracle BI Workshop

Connector for Microsoft Office SharePoint Server. ados.com Therefore Corporation, all rights reserved.

ORACLE BUSINESS INTELLIGENCE WORKSHOP

Install BA Server with Your Own BA Repository

H ig h L e v e l O v e r v iew. S te p h a n M a rt in. S e n io r S y s te m A rc h i te ct

Database Studio is the new tool to administrate SAP MaxDB database instances as of version 7.5.

BillQuick Installation Guide for Microsoft SQL Server 2005 Express Edition

Installing OneStop Reporting Products

ISL Online Integration Manual

Kony MobileFabric. Sync Server Tomcat Installation Manual. On-Premises

Interact for Microsoft Office

Oracle SOA Suite 11g Oracle SOA Suite 11g HL7 Inbound Example

DCA. Document Control & Archiving USER S GUIDE

Secure Agent Quick Start for Windows

Orchestrating Document and Media Management using CMIS

Parallels Virtuozzo Containers 4.6 for Windows

Litigation Support connector installation and integration guide for Summation

SC-T35/SC-T45/SC-T46/SC-T47 ViewSonic Device Manager User Guide

Foxit Reader Quick Guide

Red Hat OpenStack Platform 8 DNS-as-a-Service Guide

Tutorial: BlackBerry Application Development. Sybase Unwired Platform 2.0

Java with Eclipse: Setup & Getting Started

Fuse ESB Enterprise 7.0 Installation Guide

Standard Client Configuration Requirements

Installation Guide of the Change Management API Reference Implementation

Decision Support AITS University Administration. EDDIE 4.1 User Guide

TrueSight Operations Management Monitoring Studio

Quick start. A project with SpagoBI 3.x

HR Onboarding Solution

Print Audit 6 - SQL Server 2005 Express Edition

Backup Assistant. User Guide. NEC NEC Unified Solutions, Inc. March 2008 NDA-30282, Revision 6

DOCUMENTATION MICROSOFT SQL BACKUP & RESTORE OPERATIONS

LogMeIn Network Console Version 8 Getting Started Guide

McAfee VirusScan Enterprise for Linux Software

Using EMC Documentum with Adobe LiveCycle ES

Integrating WebSphere Portal V8.0 with Business Process Manager V8.0

Evaluator s Guide. PC-Duo Enterprise HelpDesk v5.0. Copyright 2006 Vector Networks Ltd and MetaQuest Software Inc. All rights reserved.

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

IBM. Implementing SMTP and POP3 Scenarios with WebSphere Business Integration Connect. Author: Ronan Dalton

Red Hat Developer Toolset 1.1

L01: Using the WebSphere Application Server Liberty Profile for lightweight, rapid development. Lab Exercise

Talend for Data Integration guide

Connection Broker Managing User Connections to Workstations, Blades, VDI, and more. Security Review

Transcription:

Red Hat JBoss Developer Studio 8.0 Start Developing Tutorial for first time users Red Hat Customer Content Services

Red Hat JBoss Developer Studio 8.0 Start Developing Tutorial for first time users Red Hat Custo mer Co ntent Services

Legal Notice Copyright 2014 Red Hat, Inc. This do cument is licensed by Red Hat under the Creative Co mmo ns Attributio n- ShareAlike 3.0 Unported License. If you distribute this document, or a modified version of it, you must provide attribution to Red Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be remo ved. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other co untries. Linux is the registered trademark of Linus Torvalds in the United States and other countries. Java is a registered trademark o f Oracle and/o r its affiliates. XFS is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/o r o ther co untries. MySQL is a registered trademark of MySQL AB in the United States, the European Union and o ther co untries. Node.js is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project. The OpenStack Wo rd Mark and OpenStack Lo go are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endo rsed o r spo nso red by the OpenStack Fo undatio n, o r the OpenStack co mmunity. All o ther trademarks are the pro perty o f their respective o wners. Abstract This document details how to start developing applications with JBoss Developer Studio.

T able of Cont ent s Table of Contents. Chapt..... er.. 1.. St.. art... Developing........... wit.. h.. JBoss...... Developer......... St.. udio...................................... 2.......... 1.1. Ab o ut Start Develo p ing 2 1.2. Ab o ut the TicketMo nster Ap p licatio n 2 1.3. Tuto rial Assump tio ns 2 1.4. Tuto rial O utline 2. Chapt..... er.. 2.. Creat..... ing... t. he... T. icket.... Monst...... er.. Applicat....... ion........................................... 4.......... 2.1. O p en the JBo ss Persp ective 4 2.2. Co nfig ure Maven to use the JBo ss EAP Maven Rep o sito ry 4 2.3. Set Up a Server Using Runtime Detectio n 5 2.4. Create a Java EE Web Pro ject Using JBo ss Central 6 2.5. Ad d an Entity Using Fo rg e To o ls 8 2.6. Ad d an Entity Using Hib ernate To o ls 10 2.7. Prep are Event Reco rd s to Po p ulate the Datab ase 13 2.8. Dep lo y the Ap p licatio n using JBo ss Server To o ls 14 2.9. Access and Q uery the Datab ase 16 2.10. Ad d a RESTful Web Service 18 2.11. Ad d a User Interface O p timized fo r Mo b ile Devices 21 2.12. Test the Mo b ile User Interface Using Bro wsersim 24. Revision........ Hist... ory........................................................................ 2. 6.......... 1

Red Hat JBoss Developer St udio 8.0 St art Developing Chapter 1. Start Developing with JBoss Developer Studio 1.1. About St art Developing Start D eveloping is a step-by-step tutorial that introduces JBoss D eveloper Studio to new users. It aims to give you a taste of developing applications with JBoss D eveloper Studio. The tutorial here demonstrates how to create a web application, TicketMonster, that includes typical enterprise functionality by using JBoss D eveloper Studio. In guiding you through the tutorial steps, a number of assumptions are made about your system. You must ensure you system complies with the assumptions before proceeding to complete the tutorial. For information, see Section 1.3, Tutorial Assumptions. The information in this tutorial is minimal. It describes one way of completing each step in the tutorial; in fact, there may be several alternatives for each step in the tutorial. For more information about alternative ways to complete tasks, see the Red Hat JBoss D eveloper Studio 8.0 documentation available on the Red Hat Customer Portal. 1.2. About t he T icket Monst er Applicat ion TicketMonster is an example web application demonstrating ticket purchasing. The application provides an online environment in which users can purchase tickets for events and administrators can manage the data relating to events and ticket sales. You can see a running example of the TicketMonster application at https://ticketmonster-jdf.rhcloud.com/. The application consists of a user interface and web services. The user interface allows users to purchase tickets for listed events and it enables administrators to access and modify event and ticket information. The user interface is optimized for desktop and mobile clients. The web services enable access to information about members, events and venues stored in a database. TicketMonster demonstrates the combining of Red Hat and JBoss technologies and frameworks to build, test and deploy applications. For example, the running instance of TicketMonster at https://ticketmonster-jdf.rhcloud.com/ is hosted in the cloud on the OpenShift platform. 1.3. T ut orial Assumpt ions The TicketMonster application is built on a Maven-based Java EE Web project. To ensure successful completion of the tutorial, a number of assumptions are made about your system: JBoss D eveloper Studio 8.0 stand-alone or Bring-Your-Own-Eclipse (BYOE) is installed; for instructions, see Install Red Hat JBoss D eveloper Studio. JBoss Enterprise Application Platform 6.x is installed Corresponding JBoss Enterprise Application Platform 6.x Maven repository is installed but Maven is not necessarily configured to use it 1.4. T ut orial Out line 2

Chapt er 1. St art Developing wit h JBoss Developer St udio The diversity and complexity of the TicketMonster application makes it ideal for demonstrating some of the capabilities of JBoss D eveloper Studio. This tutorial sets the stage for building TicketMonster. It shows you how to develop a number of the TicketMonster application features using JBoss D eveloper Studio: Open the JBoss perspective Configure Maven for use with JBoss Central projects Set up a server using JBoss Server Tools runtime detection Create a Java EE web project to which the TicketMonster functionality is added using JBoss Central Create Event and Venue entity classes for the database entities using Forge Tools and Hibernate Tools Prepare event records to populate the database at runtime D eploy the application on a runtime server using JBoss Server Tools Access and query the database holding the member, event and venue records Add a RESTful web service so that the application can retrieve the information in the database Add a user interface to the application that is optimized for mobile devices using Mobile Web Tools Test the mobile user interface using BrowserSim You must work through these tasks in the order they are presented because the earlier tasks are prerequisites for the later tutorial tasks. Note For information about building the complete TicketMonster application using JBoss D eveloper Studio see http://www.jboss.org/ticket-monster/ on the JBoss D eveloper website. 3

Red Hat JBoss Developer St udio 8.0 St art Developing Chapter 2. Creating the TicketMonster Application 2.1. Open t he JBoss Perspect ive When following this tutorial, you must use the JBo ss perspective. Specific views, toolbars, and menu options most used by JBoss developers are available when this perspective is open. Instructions in the tutorial are given based on the JBo ss perspective and if you use an alternative perspective you might not be able to find some of the items as detailed in the tutorial procedures. The procedure below details how to open the JBo ss perspective. Procedure 2.1. O pen the JBoss Perspective 1. Click Window O pen Perspective O ther. 2. From the list of perspectives, double-click JBo ss. 2.2. Configure Maven t o use t he JBoss EAP Maven Reposit ory The Java EE Web project, on which the tutorial TicketMonster application is built, is constructed from an enterprise Maven archetype. Maven is distributed with JBoss D eveloper Studio so it is not necessary to install Maven but, to be able to use the Java EE Web project enterprise archetype, Maven must be correctly configured to use the JBoss EAP 6.x Maven repository. Instructions are given here for editing your Maven configuration file from within JBoss D eveloper Studio to achieve this. Procedure 2.2. Configure Maven to use the JBoss EAP Maven Repository 1. Click Window Preferences, expand JBo ss T o o l s and select JBo ss Maven Integ rati o n. 2. Click C o nfi g ure Maven R epo si to ri es. 3. Click Ad d R epo si to ry. 4. Click R eco g ni ze JBo ss Maven Enterpri se R epo si to ri es. 5. Navigate to path/to /jbo ss-eap-6. x. y-maven-repo si to ry and click O K. JBoss Maven Tools recursively scans the path searching for the Maven repository. 6. Modify the information in the ID and Name fields as desired, ensure the Acti ve by d efaul t check box is selected and click O K. 4

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Figure 2.1. JBoss EAP Maven Repository Listed for Adding to the Maven Configuration File 7. Click Fi ni sh and at the prompt asking if you are sure you want to update the Maven configuration file click Y es. If the specified configuration file does not exist, JBoss Maven Tools creates it. Note Maven settings, such as the configuration file, are specified in P references under Maven User Setti ng s. These settings can be customized. 8. Click Appl y and click O K to close the Preferences window. 2.3. Set Up a Server Using Runt ime Det ect ion Servers can be defined from within the Java EE Web Project wizard. But for the purposes of exploring JBoss D eveloper Studio the procedure below defines the server first using JBoss Server Tools runtime detection. Procedure 2.3. Define a Server Using Runtime Detection 1. Click Window Preferences, expand JBo ss T o o l s and select JBo ss R unti me D etecti o n. 5

Red Hat JBoss Developer St udio 8.0 St art Developing 2. Click Ad d. 3. Select the directory containing the JBo ss EAP 6. x installation and click O K. The directory is now scanned for application servers and JBoss EAP 6.x found. Figure 2.2. JBoss EAP 6.x Found by Runtime Detection 4. To create a server for JBoss EAP 6.x, ensure the jbo ss-eap-6. x check box is selected and click O K. 5. Click Appl y and click O K to close the P references window. The server is listed in the Servers view. Figure 2.3. JBoss EAP 6.x Server Listed in Servers View 6. The server is initially shown in stopped mode. Start the server by right-clicking jbo ss-eap- 6. x and clicking Start. After a short pause, the view switches to the C o nso l e view and shows the startup output of the server. 2.4. Creat e a Java EE Web Project Using JBoss Cent ral The TicketMonster application is based on a Java EE web application. A wizard is provided for creating this type of project in JBoss Central and the procedure below guides you through using the wizard. Procedure 2.4. Create a Web Application Using the Java EE Web Project Wiz ard 6

Chapt er 2. Creat ing t he T icket Monst er Applicat ion 1. Click the JBo ss C entral tab. 2. In JBoss Central under Start fro m scratch, click Java EE Web P ro ject to open the Java EE Web Project wizard. If JBoss Central is not visible, click Help JBoss Central. Figure 2.4. Java EE Web Project in JBoss Central 3. From the T arg et R unti me list, select jbo ss-eap-6. x R unti me and click Next. Figure 2.5. JBoss EAP 6.x Selected as Target Runtime in Java EE Web Project Wiz ard 4. Complete the fields about the project as follows: In the P ro ject name field, type ti cket-mo nster. 7

Red Hat JBoss Developer St udio 8.0 St art Developing In the P ackag e field, type o rg. jbo ss. jd f. exampl e. ti cketmo nster. Figure 2.6. Completed Project Name and Package Fields in Java EE Web Project Wiz ard 5. Click Fi ni sh to create the project. D uring project creation, the wizard imports project dependencies. When the Java EE Web Pro ject wizard displays ' Java EE Web P ro ject' P ro ject i s no w read y, click Fi ni sh to close the wizard. A R EAD ME. md file for the project automatically opens for viewing and the project is listed in the P ro ject Expl o rer view. 2.5. Add an Ent it y Using Forge T ools A new entity class can be added to the TicketMonster project using Forge Tools. In the procedure below an Event entity class is created to hold information about the events for which users can buy tickets. This Event entity has id, name, description, major and picture fields. Procedure 2.5. Add an Entity Using Forge Tools 1. In the P ro ject Expl o rer view, expand ti cket-mo nster Java R eso urces src/mai n/java. 2. Click o rg. jbo ss. jd f. exampl e. ti cketmo nster. mo d el and press C trl + 4 (C md + 4 ). 3. From the Forge wizards list, click JP A: New Enti ty. 4. In the Enti ty name field, type Event and click Fi ni sh. 8

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Figure 2.7. New Event Entity using Forge 2 JP A: New Enti ty Wiz ard 5. In the P ro ject Expl o rer view, ensure o rg. jbo ss. jd f. exampl e. ti cketmo nster Event. java is selected and press C trl + 4. 6. From the Forge wizards list, click JP A: New Fi el d. 7. Complete the fields about the field as follows: In the Fi el d name field, type name. In the Leng th field, type 50. 9

Red Hat JBoss Developer St udio 8.0 St art Developing Figure 2.8. New name Field using Forge 2 JP A: New Fi el d Wiz ard 8. Click Fi ni sh to create the field. 9. Repeat steps 5 and 6 to create three more fields for the Event entity as follows: d escri pti o n, with Fi el d T ype Stri ng and Leng th 10 0 0 majo r, with Fi el d T ype Bo o l ean pi cture, with Fi el d T ype Stri ng 10. In the P ro ject Expl o rer view, right-click Event. java and click Show In Forge Console. 11. In the Fo rg e C o nso l e view, on the Forge 2 command line enter constraint-add --onproperty name and from the list of options enter the number corresponding to No tnul l. 2.6. Add an Ent it y Using Hibernat e T ools A new entity class can be added to the TicketMonster project using Hibernate Tools. In the procedure below a Venue entity class is created to hold information about the venues where events will be held. This Venue entity has id, name, description and capacity fields. Procedure 2.6. Add an Entity Using Hibernate Tools 10

Chapt er 2. Creat ing t he T icket Monst er Applicat ion 1. In the P ro ject Expl o rer view, expand ti cket-mo nster Java R eso urces src/mai n/java. 2. Right-click o rg. jbo ss. jd f. exampl e. ti cketmo nster. mo d el and click New Class. 3. In the Name field, type Venue and click Fi ni sh. This creates a Venue. java file that is automatically opened in a Java editor. Figure 2.9. New Venue Class using Java Class Wiz ard 4. Add fields to the entity by adding the following lines in between the braces of the Venue class 11

Red Hat JBoss Developer St udio 8.0 St art Developing private Long id; private String name; private String description; private int capacity; 5. Save the Venue. java file by pressing C trl + S (C md + S). 6. Add g et and set methods by right-clicking on a new line after pri vate i nt capaci ty; and clicking Source G enerate G etters and Setters. 7. Click Sel ect Al l and click O K. Figure 2.10. List of Attributes Selected for Creating G et and Set Methods 8. Save the Venue. java file. 9. Make the class an entity by right-clicking anywhere in the Venue class and clicking Source G enerate Hibernate/JPA annotations. 12

Chapt er 2. Creat ing t he T icket Monst er Applicat ion 10. Ensure o rg. jbo ss. jd f. exampl e. ti cketmo nster. mo d el. Venue is selected and click Next. Figure 2.11. Venue Class Selected for Adding JPA Annotations 11. Click Fi ni sh and save the Venue. java file. 2.7. Prepare Event Records t o Populat e t he Dat abase This web project uses H2 for data storage by default. H2 is a Java database integrated with the application servers of JBoss EAP 6.x. It is an in-memory database which means that the data does not persist once the application using the database stops running. For this reason, seed data must be stored in a file within the project and added to the database each time the application starts. While it might not seem practical to have to construct the database each time the application starts, this type of data storage is useful during development for testing purposes. Warning The use of H2 for data storage is for testing purposes only and must not be used during production. The procedure below demonstrates preparing two sample Event records for addition to the H2 database once the TicketMonster application starts. 13

Red Hat JBoss Developer St udio 8.0 St art Developing Procedure 2.7. Prepare Event Records 1. In the P ro ject Expl o rer view, expand ti cket-mo nster Java R eso urces src/mai n/reso urces. 2. Double-click the i mpo rt. sq l file to open it for editing. 3. Double-click the i mpo rt. sq l view label to make the editor fill the window. 4. Create a new Event record by copying the following on one line after the existing Member record insert into Event (id, name, description, major, picture, version) values (1, 'Shane''s Sock Puppets', 'This critically acclaimed masterpiece...', true, 'http://dl.dropbox.com/u/65660684/640px- Carnival_Puppets.jpg', 1); 5. Create a second new Event record by copying the following on one line after the first new Event record insert into Event (id, name, description, major, picture, version) values (2, 'Rock concert of the decade', 'Get ready to rock...', true, 'http://dl.dropbox.com/u/65660684/640px- Weir%2C_Bob_(2007)_2.jpg', 1); Figure 2.12. Content of the i mpo rt. sq l File for this TicketMonster Workflow 6. Save the i mpo rt. sq l file. 7. Double-click the i mpo rt. sq l view label to make the editor return to its previous size. 2.8. Deploy t he Applicat ion using JBoss Server T ools The TicketMonster application can be deployed on the JBoss EAP 6.x server created earlier in the tutorial. The procedure below guides you through how to do this. 14

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Procedure 2.8. Deploy the Application Using JBoss Server Tools 1. In the P ro ject Expl o rer view, right-click the ti cket-mo nster project name and click Run As Run on Server. 2. In the Run O n Server wizard, ensure C ho o se an exi sti ng server is selected. 3. From the Sel ect the server that yo u want to use table, select jbo ss-eap-6. x and click Fi ni sh. If not already in view, the C o nso l e view automatically opens and shows the runtime server output. Also, a Web Bro wser automatically opens and displays the web page of the running TicketMonster application. Figure 2.13. JBoss EAP 6.x Selected in Run on Server Wiz ard In the Web Bro wser, enter sample Member data in the Member Registration fields and click R eg i ster. The submitted data is displayed in the Members table, which is visible at the bottom of the web page. 15

Red Hat JBoss Developer St udio 8.0 St art Developing Figure 2.14. Sample Data in the Member Registration Fields 2.9. Access and Query t he Dat abase This web project uses the in-memory database, H2, of the application servers in JBoss EAP 6.x. The H2 console web application can be used to access the H2 database but this is not packaged with JBoss EAP 6.x. As the procedure below explains, the H2 console web application must be downloaded and deployed on the application server from outside JBoss D eveloper Studio before the H2 database can be accessed. Procedure 2.9. Access and Q uery the Database 1. Go to http://www.jboss.org/quickstarts/eap/h2-console/. 2. Click D o wnl o ad. 3. Extract the contents of the archive $ unzip jboss-eap-quickstarts-<version>.zip 4. Copy the h2co nso l e. war file to the JBoss EAP 6.x d epl o yments directory $ cp jboss-eap-quickstarts-<version>/h2-console/h2console.war /path/to/jboss-eap/standalone/deployments/ 16

Chapt er 2. Creat ing t he T icket Monst er Applicat ion 5. Confirm the H2 console web application is running by looking at the server output in the C o nso l e view in JBoss Developer Studio. Figure 2.15. Console O utput showing h2co nso l e. war Deployed 6. In the IDE open a new Web Bro wser by clicking Window Show View O ther, expand G eneral and double-click Internal Web Bro wser. 7. In the address bar of the Web Bro wser, enter http://localhost:8080/h2console. 8. In the Lo g i n area, in the JD BC UR L field type jd bc: h2: mem: ti cket-mo nster and in both the User Name and P asswo rd fields type sa. These settings are defined in the ti cket-mo nster-d s. xml file in the ti cket-mo nster/src/mai n/webapp/web-inf directory. Figure 2.16. Completed H2 Login Web Page 9. Click C o nnect to connect to the database. The Event, Member and Venue entities created in the TicketMonster project are displayed under jbd c: h2: mem: ti cket-mo nster. Expanding the entities shows the fields associated with each. The records stored in the database are viewed using SQL search statements. For example, to display all the Event records stored in the database, click Event, which creates a SQL search statement based on Event in the SQ L statement field, and click R un. The details of the Event sample records you added to i mpo rt. sq l earlier in the tutorial are visible in the table below the SQ L statement field. 17

Red Hat JBoss Developer St udio 8.0 St art Developing Figure 2.17. Event Records Stored in the H2 Database 2.10. Add a REST ful Web Service For the TicketMonster application to be able to access the information stored in the database, web services are needed. The procedure below creates a RESTful web service that returns all the events in the database. It generates a POJO (plain old Java object) and adds JAX-RS annotations to create an endpoint. Procedure 2.10. Add a RESTful Web Service 1. In the P ro ject Expl o rer view, expand ti cket-mo nster Java R eso urces src/mai n/java. 2. Right-click o rg. jbo ss. jd f. exampl e. ti cketmo nster. rest and click New Class. 3. In the Name field, type EventServi ce and click Fi ni sh. This creates a EventServi ce. java file that is automatically opened in a Java editor. 18

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Figure 2.18. Completed Name Field in Java Class Wiz ard 4. Add the following lines immediately above publ i c cl ass EventServi ce { @ Path("/events") @ RequestScoped and add the following lines in between the braces of the EventServi ce class @ Inject private EntityManager em; @ GET 19

Red Hat JBoss Developer St udio 8.0 St art Developing @ Produces(MediaType.APPLICATION_JSON) public List<Event> getallevents() { final List<Event> results = em.createquery("select e from Event e order by e.name").getresultlist(); return results; } 5. Save the EventServi ce. java file. 6. Resolve the errors relating to missing imports by right-clicking anywhere in the EventServi ce class and clicking Source O rganiz e Imports. 7. For each class name that is not unique, select the class to use as follows and click Next: For Med i at ype select javax. ws. rs. co re. Med i at ype For Event select o rg. jbo ss. jd f. exampl e. ti cketmo nster. mo d el. Event For P ro d uces select javax. ws. rs. P ro d uces For Li st select java. uti l. Li st For Inject select java. i nject. Inject For R eq uestsco ped select java. enterpri se. co ntext. R eq uestsco ped Figure 2.19. javax. ws. rs. co re. Med i at ype Selected for Med i at ype Class 8. When all the classes have been chosen, click Fi ni sh. The import statements corresponding to the class names selected in the previous step are added to the EventServi ce. java file. 9. Save the EventServi ce. java file. 10. In the Servers view expand jbo ss-eap-6. x, right-click ti cket-mo nster and click Full Publish to update the deployed version of the application. 11. Open a new Web Bro wser and in the address bar of the Web Bro wser enter http://localhost:8080/ticket-monster/rest/events. This shows the output of the new RESTful endpoint. 20

Chapt er 2. Creat ing t he T icket Monst er Applicat ion 2.11. Add a User Int erface Opt imiz ed for Mobile Devices The TicketMonster user interface displays on desktop and mobile clients but it is not optimized for the latter. The procedure below uses the jquery Mobile API to create a mobile optimized user interface. The mobile user interface created varies from the existing user interface by displaying the names of the events returned by the previously created web service rather than the Member Registration web page. Procedure 2.11. Add a User Interface O ptimiz ed for Mobile Devices 1. In the P ro ject Expl o rer view, expand ti cket-mo nster src mai n. 2. Right-click webapp and click New HTML file. 3. Complete the information about the file as follows: In the Enter o r sel ect the parent fo l d er field, type ti cketmo nster/src/mai n/webapp. In the Fi l e name field, type mo bi l e. html. Figure 2.20. New HTML File using the New HTML File Wiz ard 21

Red Hat JBoss Developer St udio 8.0 St art Developing 4. Click Next. 5. From the T empl ates list, select HT ML5 jq uery Mo bi l e P ag e (1. 4 ) and click Fi ni sh. This creates a mo bi l e. html file that is automatically opened in the Vi sual /So urce tab of the Visual Page Editor. Figure 2.21. Selected HT ML5 jq uery Mo bi l e P ag e (1. 4 ) Template in New HTML File Wiz ard 6. List the events returned by the web service in the mobile user interface by adding the following lines immediately after the al ert("r ead y T o G o "); line $.getjson("rest/events", function(events) { // console.log("returned are " + events); var listofevents = $("#listofitems"); listofevents.empty(); $.each(events, function(index, event) { // console.log(event.name); listofevents.append("<li><a href='#'>" + event.name + "</a>"); }); listofevents.listview("refresh"); }); 22

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Figure 2.22. Completed mo bi l e. html File 7. Save the mo bi l e. html file. View the mobile interface, by opening an external web browser and in the address bar entering http://localhost:8080/ticket-monster/mobile.html. At the R ead y T o G o prompt, click O K. The names of the events in the database are displayed. Note HTML pages are deployed immediately so there is no need to do a full publish of the TicketMonster application to see changes. 23

Red Hat JBoss Developer St udio 8.0 St art Developing Figure 2.23. Events Displayed via Mobile Interface in External Web Browser 2.12. T est t he Mobile User Int erface Using BrowserSim Mobile user interfaces are best tested on mobile devices and JBoss D eveloper Studio provides BrowserSim for this purpose. The procedure below guides you through viewing the TicketMonster application on simulated mobile devices using BrowserSim. Procedure 2.12. Test the Mobile User Interface Using BrowserSim 1. On the toolbar click the Bro wsersi m icon. A simulated device is displayed. 2. At the R ead y T o G o prompt, click C l o se. The names of the events in the database are displayed. Note If the names of the events in the database are not displayed, check the address bar of the simulated device. The address bar must state http://localhost:8080/ticketmonster/mobile.html. 3. To rotate the mobile device, click in any corner of the simulated device. 24

Chapt er 2. Creat ing t he T icket Monst er Applicat ion Figure 2.24. Rotated Simulated Device 4. Change the type of simulated device displayed by right-clicking anywhere on the simulated device, clicking Skin and selecting from the different skins listed. 5. Close BrowserSim by right-clicking anywhere on the simulated device and clicking C lo se. 25

Red Hat JBoss Developer St udio 8.0 St art Developing Revision History Revision 8.0.0-3 Fri Nov 21 2014 Michelle Murray TOOLSD OC-552: Section about using JBoss perspective added TOOLSD OC-553: Typo in Forge Tools procedure fixed Revision 8.0.0-2 Thu O ct 16 2014 Michelle Murray Generated for 8.0.0 release 26