In this lab, you will create a new Intellij IDEA project and save/commit/push it as a sub-folder in your course repo for this unit.

Building a J2EE Application using GlassFish

Follow the instructions in the Jetbrains/Intellij J2EE application tutorial, which bundles the Web and EJB

Exercise 11.1

Run the Intellij IDEA J2EE tutorial: Developing a Java EE Application. Note the following as you go through the tutorial sections, saving answers to the questions in a notes.txt file in the root of your new project structure.

  1. Before you start — The lab has all the tools required for the tutorial.

    • Intellij IDEA — Find this under the Windows start menu.
    • Java 8 — C:\Program Files\Java\jdk1.8.build#
    • GlassFish 4.1 — C:\glassfish-4.1-web\glassfish4
  2. Creating a Project — Name your project Lab11 and store it in your class repo under cs342/11postrelational/Lab11/. This allows you to commit/push the full application as part of your course repo but also edit it individually using Intellij IDEA.

  3. Exploring the project structure — How do the external libraries (in the project pane) relate to J2SE and J2EE?

  4. Developing source code — Set the HTML title and body content to whatever you’d like. At what tier does this application run?

  5. Running the application &
    Modifying the code and observing the changes — What server does this step use to serve up your application? For a hint, look at what’s served up at the URL: /. How does it compare with a typical web server?

  6. Exploring a run configuration &
    Exploring an artifact configuration — Skim through these sections, making sure that you can find the application features they discuss. What is a WAR file?

  7. Packaging the application into a WAR file &
    Deploying an artifact onto a running server — Here, we run the app on a GlassFish server running on the local machine, called a “remote” server because it’s running outside of Intellij IDEA. Start the server as follows.

    1. Stop any GlassFish server you might still have running in Intellij.
    2. Run C:\glassfish-4.1-web\glassfish4\glassfish\bin\asadmin.bat and run the server command start-domain. You can stop it later using stop-domain.
    3. Visit the Glassfish administration console here: http://localhost:4848/ and make sure that you can find:
      • your running application (under “Applications”).
      • the server log (under “Monitoring Data”).

    You should now have a GlassFish server running to which Intellij can (“remotely”) deploy your WAR. What’s the difference between “exploded” and non-exploded WAR files?

  8. Packaging the application into an EAR: Using Java EE Application support &
    Looking at other features (tool windows and facets) — Skim these sections but don’t implement them. Compare and contrast EAR and WAR artifacts.

Save this new application to the your course repo by Git-adding the application source files (i.e., the files in the root folder and those in the .idea/, src/ and web/, but not out/, sub-directories) and git-commit/pushing them.

You’ll update this app in the next exercise.

Adding a RESTful Web Service

Now, add a RESTful service to the application you built in the previous exercise. This process is sufficiently similar to the J2EE tutorial used above that we can skip most of the steps in the Jetbrains tutorial.

Exercise 11.2

Run the Intellij IDEA REST tutorial: Creating and Running Your First RESTful Web Service on GlassFish Application Server. Note the following as you go through the tutorial sections, saving the answers to the questions in your existing notes.txt file.

  1. Before you start
    Configuring the GlassFish server in IntelliJ IDEA
    Configuring the JDK
    Creating a project &
    Exploring the project structure — These steps are mostly done already, but you must do the following to add JAX-RS/REST to your project.

    1. On the Settings→Application Servers→Additional Libraries for Servers pane, check “RESTful Web Service” (if it isn’t already checked).
    2. Check to make sure that “GlassFish 4.1 - RESTful Web Service” is listed as an “External Library”. If it isn’t, go to the Project Structure→Modules→Dependencies pane and add a new Library→Application Server Libraries→GlassFish 4.* - RESTful Web Service.
  2. Developing source code
    Examining the generated artifact configuration
    Exploring and completing the run configuration &
    Running the application — Do these steps as written. The application should run either locally or remotely. Modify it to support the URL /hello (rather than /helloworld). Note that you’ll need to stop the “remote” server (using stop-domain, see above) before deploying “locally” in Intellij. What library does this application use for REST support?

Git-add the new source files and git-commit/push the updated application.

For the next exercise, you need to add support for the other REST operations and test that it works. For this, you’ll need the following references.

Exercise 11.3 [Homework]

Add RESTful support for GET, PUT, POST and DELETE. Your implementations of these HTTP methods should use the URL http://localhost:8080/Lab11_war/hello/api and do the following.

Leave the original hello-world URL in place. Make sure that you can test your service using the Intellij RESTful test tool.

If there’s time, you can explore this application further.

Checking in

We will grade your work according to the following criteria: