WASdev/sample.appclient.basiccalc

Name: sample.appclient.basiccalc

Owner: WASdev

Description: A Java EE 7 EJB application client sample that makes calls to a remote EJB implementation of a calculator. #JavaEE7

Created: 2015-06-10 12:56:45.0

Updated: 2017-11-09 07:12:55.0

Pushed: 2016-05-31 15:14:27.0

Homepage:

Size: 28

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

sample.appclient.basiccalc

The Java EE application client is a Java application program that accesses Java EE services such as enterprise beans, Java Database Connectivity (JDBC) databases, and Java Message Service (JMS) message queues. The Java EE application client program runs on client machines. This program follows the same Java programming model as other Java programs. However, the Java EE application client depends on the application client runtime to configure its execution environment, and uses the Java Naming and Directory Interface (JNDI) name space to access resources.

The Basic Calculator client sample communicates directly with a stateless session bean on a Liberty server. This sample shows how to use a simple stateless session enterprise bean from a Java EE 7 application client.

Building with maven

This sample can be built using Apache Maven.

n install

In addition to publishing the ear to the local maven repository, the built ear file is copied into the apps directory of the server and client configurations located in the basiccalc-wlpcfg directory:

ccalc-wlpcfg
clients
 +- basiccalcClient                        <-- specific client configuration
    +- client.xml                          <-- client configuration
    +- apps                                <- directory for applications
       +- basiccalc.ear                    <- sample application
    +- logs                                <- created by running the client locally
    +- workarea                            <- created by running the client locally
servers
 +- basiccalcServer                        <-- specific server configuration
    +- server.xml                          <-- server configuration
    +- apps                                <- directory for applications
       +- basiccalc.ear                    <- sample application
    +- logs                                <- created by running the server locally
    +- workarea                            <- created by running the server locally
Downloading WAS Liberty

There are lots of ways to get your hands on WAS Liberty. Note that you will need a version of Liberty that has support for javaeeClient-7.0, ejb-3.2, and appClientSupport-1.0 for this sample (or javaee-7.0 will do as well for the server).

To download just the WAS Liberty runtime, go to the wasdev.net Downloads page, and choose between the latest version of the runtime or the latest beta. You can also download Liberty via Eclipse and WDT

There are a few options to choose from (especially for the beta drivers): choose the one that is most appropriate.

Eclipse / WDT

The WebSphere Development Tools (WDT) for Eclipse can be used to control the server (start/stop/dump etc.). The tools also support incremental publishing with minimal restarts and works with a debugger to allow you to step through your applications plus many more features including:

Installing WDT on Eclipse is a simple drag and drop process as explained on wasdev.net. Note that WDT support for client is not available yet but coming soon.

Clone Git Repo

If the sample git repository hasn't been cloned yet, WDT has git tools integrated into the IDE:

  1. Open the Git repositories view
  2. Window -> Show View -> Other
  3. Type “git” in the filter box, and select “Git Repositories”
  4. Copy Git repo url by finding the textbox under " HTTPS clone URL” at the top of this page, and select “Copy to clipboard”
  5. In the Git repositories view, select the hyperlink “Clone a Git repository”
  6. The git repo url should already be filled in. Select “Next “-> “Next” -> “Finish”
  7. The “sample.appclient.basiccalc [master]” repo should appear in the view
Import Maven projects into WDT

TBD

Create a Runtime Environment and a Liberty Server

For the purposes of this sample, we will create the Liberty server (step 3 in the wasdev.net instructions) a little differently:

  1. Create a Runtime Environment in Eclipse
    1. Open the 'Runtime Explorer' view:
      • Window -> Show View -> Other
      • type runtime in the filter box to find the view (it's under the Server heading).
    2. Right-click in the view, and select New -> Runtime Environment
    3. Give the Runtime environment a name, e.g. wlp-2015.6.0.0 if you're using the June 2015 beta.
    4. Either:
      • Select an existing installation (perhaps what you downloaded earlier, if you followed those instructions), or
      • select Install from an archive or a repository to download a new Liberty archive.
    5. Follow the prompts (and possibly choose additional features to install) until you Finish creating the Runtime Environment
  2. Add the User directory from the maven project
    1. Right-click -> Edit the Runtime Environment created above
    2. Click the Advanced Options... link
    3. If the basiccalc-wlpcfg directory is not listed as a User Directory, we need to add it:
    4. Click New
    5. Select the basiccalc-wlpcfg project
    6. Select Finish, OK, Finish
    7. You should see the basiccalc-wlpcfg listed under the Runtime Environment in the Runtime Explorer view.
  3. Create a Server to represent our application and maven configuration in Eclipse
    1. From the Runtime Explorer view, Right-click on the basiccalc-wlpcfg user directory associated with the target runtime, and select New Server.
    2. The resulting dialog should be pre-populated with the websocketSample Liberty profile server.
    3. Click Finish
Create a Runtime Environment and a Liberty application client

Currently, application client is not supported in WDT, so We will create the Liberty client from command line. In the following steps, “wlp” is the root directory of the Liberty installation.

  1. Create a Liberty client from command line
  2. From the command-line window, go to wlp/bin
  3. Enter the command “client create basiccalcClient”
  4. Configure the client
  5. Copy basiccalc-ear-1.0-SNAPSHOT.ear to wlp/usr/clients/basiccalcClient/apps
  6. Add config element to wlp/usr/clients/basiccalcClient/client.xml like below:
  7. The client is ready to run. See “Running application client” below
Running server application from WDT
  1. Select the “basiccalc-ear” project
  2. Right-click -> “Run As…” -> “Run On Server”
  3. Select the “WebShere Application Server under localhost” folder, and select “Finish”
Running application client

The following steps will run both client and server on the same computer.

  1. Make sure the server and the basic calc application is up and running
  2. Enter the command “client run basiccalcClient – add 1 2” from the command-line
  3. Verify that the result 3 is printed on the command line window
Running application client from a remote computer

For more common scenarios where the client and the server run on different hosts, the following config elements need to be added to server.xml and client.xml:

TBD

Tips
Notice

© Copyright IBM Corporation 2015.

License
nsed under the Apache License, Version 2.0 (the "License");
may not use this file except in compliance with the License.
may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

ss required by applicable law or agreed to in writing, software
ributed under the License is distributed on an "AS IS" BASIS,
OUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
the License for the specific language governing permissions and
tations under the License.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.