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
- Log in to your host using valid credentials.
- Go to your app_server_root/bin directory.
Go to the /opt/IBM/WebSphere/AppServer/bin/ directory.
- 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
- In your preferred browser, go to the Integrated Solutions Console; for example:
http://hostname:9060/ibm/console/
- Log in with your user name and password.
- Select .
- Select the New Enterprise Application link.
- Using the Local file system option, click Browse, and select the file that you downloaded from GitHub.
- Click Next to follow the wizard using the default options until the Finish button is displayed.
- When the Confirm changes section is displayed, click Save.
- Click .
- Select the check box next to the sample application, and click Start.
- 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:
- Verify that a Derby JDBC Provider instance exists. In the administrative
console, click .
- 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
- Verify that a Default datasource instance is configured. Click .
- (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.
- (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 promptij>
, enter the following command:
The default Derby database is created in the following directory: ${WAS_INSTALL_ROOT}/derby/DefaultDBconnect 'jdbc:derby:DefaultDB;create=true';
- Add JVM arguments to the server running the batch sample. Click
- com.ibm.ws.batch.DB_SCHEMA
- Value: BATCH
- com.ibm.ws.batch.JNDI_NAME
- Value: DefaultDatasource
. Add the following custom properties: - After you configure the environment, install the application using the provided default values.
- 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/
.
- Verify that a Derby JDBC Provider instance exists. In the administrative
console, click .
- 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.
- 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
- 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
- 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:
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 Documentation navigation for the product edition that you are using.
- IBM Telephone Directory
- 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.