Accessing the samples

The product offers samples that demonstrate common enterprise application tasks. Many samples also provide instructions for deployment and coding examples.

Deploying the samples using the command line

To deploy the samples using the command line, complete the following steps:
  1. Log in to your host using valid credentials.
  2. Go to your app_server_root/bin directory.

    [Linux]Go to the /opt/IBM/WebSphere/AppServer/bin/ directory.

  3. Run wsadmin to install the application; for example:
    ./wsadmin.sh -profileName AppSrv01 -lang jython -c "AdminApp.install('/opt/sample.javaee7.websocket.war', '[ -MapWebModToVH [[ .* .* default_host ]]  -appname sample.javaee7.websocket]')"

Deploying the samples using the Integrated Solutions Console

To deploy the samples using the Integrated Solutions Console, complete the following steps:
  1. In your preferred browser, go to the Integrated Solutions Console; for example: http://hostname:9060/ibm/console/
  2. Log in with your user name and password.
  3. Select Applications > New Application.
  4. Select the New Enterprise Application link.
  5. Using the Local file system option, click Browse, and select the file that you downloaded from GitHub.
  6. Click Next to follow the wizard using the default options until the Finish button is displayed.
  7. When the Confirm changes section is displayed, click Save.
  8. Click Applications > Application Types > WebSphere enterprise applications.
  9. Select the check box next to the sample application, and click Start.
  10. Use your browser to access the home page; for example:
    http://hostname:9080/sample_name/

Available samples

Access the following selected samples in GitHub.

sample.javaee7.websocket
These web socket samples on GitHub show how to set up WebSocket Endpoints using annotations or programmatically. These samples exercise opening, reading from, writing to, and closing a WebSocket connection. Also shown is the use of encoders, decoders, the PathParam annotation, and Pong message processing.
sample.javaee7.el30
This application on GitHub shows how to use some of the new EL 3.0 (Expression Language) functions. Examples are provided for using lambda expressions, concatenation, and new operators. In addition, it provides a simple sample of a stand-alone servlet that shows EL in use without JavaServer Pages (JSP).
sample.javaee7.servlet.nonblocking

This application on GitHub demonstrates how to use non-blocking I/O by using new APIs added to ServletInputStream and ServletOutputStream. The example includes usage of ReadListener and WriteListener interface APIs.

sample.javaee7.sleepybatchlet
The sleepy batchlet sample on GitHub uses the JSR 352 batch reference implementation in the product. The application is composed of a batchlet and one batch job that sleeps for a user-defined number of seconds. Every second, the batchlet prints to the console to show that it is working. Wrapped around the batch application is a web page that is designed to provide an easier, more intuitive mechanism to manage batch executions.
This sample requires that you create resources before you deploy the application. Complete the following steps to create the required resources:
  1. Verify that a Derby JDBC Provider instance exists. In the administrative console, click Resources > JDBC > JDBC providers.
    1. If that provider does not exist, create one with a Connection pool datasource implementation type, and point to the Derby .jar file; for example: ${WAS_INSTALL_ROOT}/derby/lib
  2. Verify that a Default datasource instance is configured. Click Resources > JDBC > Data sources.
    1. (Administrative console) If that datasource does not exist, create one with the name Default datasource and the JNDI name DefaultDatasource that points to the Derby JDBC Provider and "${WAS_INSTALL_ROOT}/derby/DefaultDB" database.
    2. (Command line) Remotely connect your virtual machine with the WebSphere environment using SSH. Navigate to ${WAS_INSTALL_ROOT}/derby/bin/embedded/.
      Run ./ij.sh. When you see the prompt ij>, enter the following command:
      connect 'jdbc:derby:DefaultDB;create=true';
      The default Derby database is created in the following directory: ${WAS_INSTALL_ROOT}/derby/DefaultDB
  3. Add JVM arguments to the server running the batch sample. Click Servers > Server Types > WebSphere application servers > server_name > Java and Process Management > Process definition > Java Virtual Machine > Custom properties. Add the following custom properties:
    com.ibm.ws.batch.DB_SCHEMA
    Value: BATCH
    com.ibm.ws.batch.JNDI_NAME
    Value: DefaultDatasource
  4. After you configure the environment, install the application using the provided default values.
  5. After the application starts, open the SystemOut.log file in /.../IBM/WebSphere/Profiles/DefaultAppSrv01/logs/server1, and look for the following URL: http://hostname:9080/sample.javaee7.sleepybatchlet/.
sample.javaee7.concurrency
This application on GitHub demonstrates how to use managed executors, managed scheduled executors and context service to perform tasks in parallel in a simple application.
sample.javaee7.jta
This application on GitHub demonstrates the use of @Transactional annotations to declaratively control transaction boundaries, along with using the @TransactionScoped annotation to scope a bean lifecycle to a transaction.
sample.javaee7.jsonp
JSONP follows the JSR 353 specification.  The application on GitHub is composed of five servlets that parse and display JSON data based on different implementations for getting the JSON code. A web UI page provides an easier, more intuitive way to try out JSON-P functions. The different tests in the JSONP sample are based on special JSON objects that facilitate JSON-based capabilities, including the construction of complex structures of data that readily convert to the JSON format.
sample.javaee7.jms
This JMS sample on GitHub uses the simplified API of JMS 2.0. The sample contains two servlets for performing Point to Point and Publish/Subscribe messaging. The JMS Servlet provides an implementation example to send or receive messages to a queue and also to publish and subscribe messages from a topic.
You must create some resources before deploying the application. You can create resources using configuration scripts published with the sample.
  1. Run the createSIBusResources.py script from the app_server_root/bin directory to create the required resources. Provide cell_name, node_name, and server_name values and the path to the sample.javaee7.jms.war file in the command:
    ./wsadmin.sh -f createSIBusResources.py cell_name node_name server_name path_to_file/sample.javaee7.jms.war
  2. If security is enabled in the server, run the addAuthAlias.py script from the app_server_root/bin directory. Provide your user name and password in the command:
    ./wsadmin.sh -f addAuthAlias.py user_name password

Downloading samples code

You can download the source code for samples from the GitHub repository.

Limitations of the samples

The samples are for demonstration purposes only.

The code that is provided is not intended to run in a secured production environment. The samples support Java 2 Security, therefore the samples implement policy-based access control that checks for permissions on protected system resources, such as file I/O.

The samples also support administrative security.

More samples and examples

Samples in tutorials
Many product tutorials rely on sample code. To find tutorials that demonstrate specific technologies, browse the links in Tutorials.
Examples in the product documentation
The product documentation contains many code snippets and examples. To locate these examples easily, see the developer examples in the Reference section of the IBM Knowledge Center navigation for the product edition that you are using.
[IBM i]IBM Telephone Directory
[IBM i]The IBM Telephone Directory business application is shipped separately from the product. For information about obtaining and using the IBM Telephone Directory application, see IBM Telephone Directory V5.2 in the topic on e-business and web serving in the IBM i product documentation.