Developer Materials

helloworld-html5

  • Author:
    Original Author
    Jay Balunas, Burr Sutter, Douglas Campos, Bruno Olivera
  • Published: 2017-12-14
  • Level:
    Difficulty Level
    Beginner
  • Technologies:
    Technologies Used
    CDI, JAX-RS, HTML5
  • Target Product:

    Body
    The helloworld-html5 quickstart demonstrates the use of CDI 1.2 and JAX-RS 2.0 using the HTML5 architecture and RESTful services on the backend.

    What is it?

    The helloworld-html5 quickstart demonstrates the use of CDI 1.2 and JAX-RS 2.0 in JBoss Enterprise Application Platform Server 7.2 or later using the HTML5 + REST architecture.

    The application is basically a smart, HTML5, CSS3, and JavaScript front-end using RESTful services on the backend.

    • HelloWorld.java: Establishes the RESTful endpoints using JAX-RS.

    • web.xml: Maps RESTful endpoints to /hello.

    • index.html: Is a jQuery augmented plain old HTML5 web page.

    The example can be deployed using Maven from the command line or from Eclipse using JBoss Tools.

    System Requirements

    The application this project produces is designed to be run on JBoss Enterprise Application Platform Server 7.2 or later.

    All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.

    An HTML5 compatible browser such as Chrome, Safari 5+, Firefox 5+, or IE 9+ is required.

    With the prerequisites out of the way, you are ready to build and deploy.

    Use of EAP_HOME

    In the following instructions, replace EAP_HOME with the actual path to your JBoss EAP installation. The installation path is described in detail here: Use of EAP_HOME and JBOSS_HOME Variables.

    Start the JBoss EAP Standalone Server

    1. Open a terminal and navigate to the root of the JBoss EAP directory.

    2. Start the JBoss EAP server with the default profile by typing the following command.

      $ EAP_HOME/bin/standalone.sh 
      Note
      For Windows, use the EAP_HOME\bin\standalone.bat script.

    Build and Deploy the Quickstart

    1. Make sure you start the JBoss EAP server as described above.

    2. Open a terminal and navigate to the root directory of this quickstart.

    3. Type the following command to build the artifacts.

      $ mvn clean package wildfly:deploy

    This deploys the helloworld-html5/target/helloworld-html5.war to the running instance of the server.

    You should see a message in the server log indicating that the archive deployed successfully.

    Access the Application

    The application will be running at the following URL http://localhost:8080/helloworld-html5/.

    You can also test the REST endpoint by sending an HTTP POST request to the URLs below. Replace YOUR_NAME with a name of your choosing.

    Test the XML Content

    You can test The XML content by sending an HTTP POST to the following URL: http://localhost:8080/helloworld-html5/hello/xml/YOUR_NAME

    Type the following cURL command in terminal to issue the POST command:

    curl -i -X POST http://localhost:8080/${project.artifactId}/hello/xml/__YOUR_NAME__

    You will see the following response:

    Connection: keep-alive
    HTTP/1.1 200 OK
    X-Powered-By: Undertow/1
    Server: JBoss-EAP/7
    Content-Type: application/xml
    Content-Length: 44
    Date: Tue, 13 Oct 2015 18:40:04 GMT
    
    <xml><result>Hello YOUR_NAME!</result></xml>

    Test the JSON Content

    You can test the JSON content by sending an HTTP POST to the following URL: http://localhost:8080/helloworld-html5/hello/json/YOUR_NAME

    Type the following cURL command in terminal to issue the POST command:

    curl -i -X POST http://localhost:8080/${project.artifactId}/hello/json/YOUR_NAME

    You will see the following response:

    HTTP/1.1 200 OK
    Connection: keep-alive
    X-Powered-By: Undertow/1
    Server: JBoss-EAP/7
    Content-Type: application/json
    Content-Length: 29
    Date: Tue, 13 Oct 2015 06:32:20 GMT
    
    {"result":"Hello YOUR_NAME!"}

    Undeploy the Quickstart

    When you are finished testing the quickstart, follow these steps to undeploy the archive.

    1. Make sure you start the JBoss EAP server as described above.

    2. Open a terminal and navigate to the root directory of this quickstart.

    3. Type this command to undeploy the archive:

      $ mvn wildfly:undeploy

    Run the Arquillian Functional Tests

    This quickstart provides Arquillian functional tests. They are located under the functional-tests/ directory. Functional tests verify that your application behaves correctly from the user’s point of view and simulate clicking around the web page as a normal user would do.

    Note
    The Arquillian functional tests deploy the application, so make sure you undeploy the quickstart before you begin.

    Follow these steps to run the functional tests.

    1. Start the JBoss EAP server as described above.

    2. Build the quickstart archive.

      1. Open a terminal and navigate to the root directory of this quickstart.

      2. Build the quickstart archive using the following command:

        $ mvn clean package
    3. Navigate to the functional-tests/ directory in this quickstart.

    4. Type the following command to run the verify goal with the arq-remote profile activated.

      $ mvn clean verify -Parq-remote
    Note

    You can also let Arquillian manage the JBoss EAP server by using the arq-managed profile, meaning the tests will start the server for you. This profile requires that you provide Arquillian with the location of the JBoss EAP server, either by setting the JBOSS_HOME environment variable, or by setting the jbossHome property in the arquillian.xml file. For more information, see Run the Arquillian Tests.

    Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse

    You can also start the server and deploy the quickstarts or run the Arquillian tests in Red Hat JBoss Developer Studio or from Eclipse using JBoss tools. For general information about how to import a quickstart, add a JBoss EAP server, and build and deploy a quickstart, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts.

    Debug the Application

    If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.

    $ mvn dependency:sources
    $ mvn dependency:resolve -Dclassifier=javadoc