14 Sample Applications and Code Examples

WebLogic Server provides a rich set of code examples and sample applications that show several approaches to learning about and working with WebLogic Server. These examples and sample applications are available through performing a custom installation and selecting to install the Server Examples.

This chapter includes the following topics:

Installing and Running the Examples

You can create a complete WebLogic domain that is configured with the full set of deployed code examples by selecting them in the installation program.

This section contains the following topics:

Installing the WebLogic Server Code Examples

When performing an installation of WebLogic Server, select Complete with Examples to obtain the WebLogic Server and Coherence examples. For more information about installing WebLogic Server, see Installing the Oracle WebLogic Server and Coherence Software. To set up the WebLogic Server samples domain, launch the Quick Start Configuration Wizard when prompted after installation.

If you do not automatically launch the Quick Start Configuration Wizard from the installation program, but instead choose to configure the code examples and sample domains later, you can run the Quick Start Configuration Wizard manually. See Running the Quick Start Configuration Wizard in Creating WebLogic Domains Using the Configuration Wizard.

Starting the WebLogic Server Samples Domain

Start the examples server using one of the following procedures. In these procedures, DOMAIN_HOME represents the location where the samples domain is configured on your machine; for example, C:\ORACLE_HOME\user_projects\domains.

On Windows: Use a command shell and navigate to the DOMAIN_HOME\wl_server directory. Enter the following command:

startWebLogic.cmd

On UNIX Bourne Shell: Navigate to the DOMAIN_HOME/wl_server directory. Enter the following command:

sh ./startWebLogic.sh

Note:

By default, the examples server uses port 7001 to listen for incoming connections. The MedRec server also uses the same listen port by default, which means that you cannot run both domains at the same time without changing one of the listen ports. If you want to run both domains at the same time, use the Oracle WebLogic Server Administration Console to change the listen port of the examples server to something other than 7001, and then restart it. You can then run the MedRec server using its default listen port at the same that you run the examples server.

Running the WebLogic Server Code Examples

Review the instructions provided with the code examples for information about building, deploying and running the code examples. When you start the WebLogic Server samples domain, a browser is automatically launched that displays a web page from which you can browse the samples and obtain instructions for building, deploying, and running them.

Conventions

The instructions for building, deploying, and running the WebLogic Server code examples include a number of typographical conventions for indicating the path names for entities such as the WebLogic Server installation directory, the samples domain home directory, Apache Derby, and so on, in a platform-neutral way.

The following conventions are used:

  • The instructions generally are for Windows command shells. If you are using a UNIX or Linux-based shell, substitute / for \ in path names.

  • ORACLE_HOME represents the directory you specified as the Oracle Home when you installed WebLogic Server; for example, C:\Oracle\Middleware\Oracle_Home.

  • WL_HOME represents the top-level installation directory for Oracle WebLogic Server. The default path is ORACLE_HOME/wlserver. (However, you are not required to install WebLogic Server in the Oracle Home directory.)

  • EXAMPLES_HOME represents the directory in which the WebLogic Server code examples are configured. The default path is ORACLE_HOME\wlserver\samples\server.

  • DOMAIN_HOME represents the directory in which the WebLogic Server sample domains are configured. The default path is ORACLE_HOME\user_projects\domains.

Source files for the code examples are separated from the domain configuration files, just as they should be in a real-world scenario. They are installed in the EXAMPLES_HOME directory.

The DOMAIN_HOME\wl_server directory contains the WebLogic Server examples domain; it contains your applications and the XML configuration files that define how your applications and Oracle WebLogic Server will behave, as well as startup and environment scripts.

The EXAMPLES_HOME\examples\build directory contains client and server classes required by the examples and Derby database.

The WL_HOME\common\derby directory contains Derby, a demonstration database that the examples are configured to use. It also contains scripts that start and stop the database. For more information about Derby, see http://db.apache.org/derby.

Java EE 8 Examples

Oracle WebLogic Server fully supports the Java Platform, Enterprise Edition (Java EE) 8 specification. The Java EE 8 examples that are included demonstrate how to implement Java EE 8 APIs and Oracle WebLogic Server-specific features.

The Java EE 8 examples are grouped into the following categories:

  • JSON Binding 1.0—Use the Java API for JSON Binding (JSON-B) with JAX-RS.

  • Java EE Security 1.0—Configure a DatabaseIdentityStore to point to a backend database and then use it as an IdentityStore.

  • JSON Processing 1.1—Use JSON Patch, JSON Merge Patch, and JSON Pointer to update a JSON document.

  • Servlet 4.0—Use the Servlet Mapping API, HTTP/2 Server Push, and the HTTP Trailer headers API.

  • JAX-RS 2.1—Use the new Server-Sent Events (SSE) and the new REST Reactive Client API.

  • JSF 2.3—Use the new features of JSF 2.3 such as direct support for WebSockets, class-level bean validation, CDI-compatible @ManagedProperty annotation feature, and Java date and time.

  • JPA 2.2—Use injection in @AttributeConverter annotation, new Java EE 8 Date and Time, and also use support for retrieving the results of Query and TypedQuery as streams.

  • CDI 2.0—Use asynchronous events, observer ordering, and also use interception factory.

Java EE 7 Examples

Oracle WebLogic Server fully supports the Java Platform, Enterprise Edition (Java EE) 7 specification. The Java EE 7 examples that are included demonstrate how to implement Java EE 7 APIs and Oracle WebLogic Server-specific features.

The Java EE 7 examples are grouped into the following categories:

  • Batch Application Processing 1.0—Submit batch jobs and obtain information about submitted jobs using the JobOperator interface, and use the batch parallelization model to run partitioned job steps.

  • Bean Validation 1.1—Use the bean validation group constraint and method level validation APIs.

  • Context and Dependency Injection (CDI) 1.1—Use CDI events and the @TransactionScoped and @Transactional  annotations.

  • Concurrency Utilities 1.0—Create dynamic proxy objects using the ContextService interface, submit tasks using the ManagedExecutorService interface, submit delayed or periodic tasks using the ManagedScheduledExecutorService interface, and obtain a managed thread from the Java EE container using the ManagedThreadFactory interface.

  • Enterprise JavaBeans 3.2—Use the new session bean life cycle callback interceptor methods API and also use a message-driven bean to implement a listener interface with no methods.

  • Expression Language 3.0—Use new EL features, including support for a standalone environment, static field or method references, new operators, Lambda expressions, and collection constructions and operations.

  • Java API for RESTful Web Services (JAX-RS) 2.0—Use asynchronous processing, filters and interceptors, and server-sent events (SSE) Jersey support.

  • Java EE Connector Architecture 1.7—Develop a resource adapter and deploy connector resources with annotations defined in the Java EE Connector Architecture 1.7 specification.

  • Java Message Service API 2.0—Use the JMS API in EJBs and servlets.

  • Java Persistence 2.1—Use JPA criteria update and criteria delete APIs, and the stored procedures API.

  • JSF 2.2—Use Java Server Faces (JSF) resource library contracts, file upload, faces flows, and HTML5 features.

  • JSON Processing 1.0—Use the Java API for JSON processing with JAX-RS.

  • Servlet 3.1—Use the HTTP protocol upgrade API, use non-blocking I/O for asynchronous reads and writes, change a session ID, and handle uncovered HTTP methods.

  • WebSocket—Process JSON-format data, using CDI and EJBs in WebSocket endpoints, enable a server to echo text sent by a client, and enable fallback to HTTP long polling as an alternative for WebSocket messaging.

Additional API Examples

Oracle WebLogic Server also includes a set of examples that demonstrate how to implement additional Java EE APIs and Oracle WebLogic Server-specific features. These examples are grouped in the following categories:
  • Database Connectivity—Use Data Sources, Multi Data Sources, and Rowsets.

  • EJB—Create stateless, stateful, entity, and message-driven EJBs, and more.

  • Internationalization—Internationalize an application using simple message catalogs.

  • Messaging—Use JMS topics, queues, and message-driven beans.

  • Resource Adapter—Use an entity EJB to interact with a Java EE Connector Architecture resource adapter.

  • Security—Use the Java Authentication and Authorization Service, SAML, and outbound and two-way SSL.

  • Transactions—Use JTA to perform distributed transactions using the two phase commit protocol across two XA resources.

  • Web Application—Create simple servlets and JSPs, use the HTTP Publish-Subscribe server, and more.

  • Web Services—Create a variety of web services using JWS annotations.

  • XML—Use the STAX API and XMLBeans

  • Cluster—Cluster an EJB and use HTTP session state replication.

  • Coherence—Use the Coherence container to host Coherence applications

  • WebLogic Scripting Tool—Use the WebLogic Scripting Tool (WLST) to configure and manage a running Administration Server instance.

  • Split Development—Use the WebLogic split development directory structure to build, package, and deploy Enterprise Applications.

  • Service Component Architecture—Use WebLogic SCA, a lightweight Spring 2.5 (or higher) container, in a shopping cart application that demonstrates many of its key features.

  • Spring—Use Spring-simplified configuration in a Spring-based web application.

Avitek Medical Records

Avitek Medical Records (also known as MedRec) is a comprehensive educational sample application that demonstrates WebLogic Server and Java EE features, as well as best practices. Avitek Medical Records is optionally installed with the WebLogic Server installation.

You can start MedRec from the ORACLE_HOME/user_projects/domains/medrec directory, where ORACLE_HOME is the directory you specified as the Oracle Home when you installed Oracle WebLogic Server.

The sample application, MedRec (Spring) demonstrates Spring Framework application development practices.

Derby Open-Source Database

Derby is an open source relational database management system based on Java, JDBC, and SQL standards. Derby is bundled with WebLogic Server for use by the sample applications and code examples as a demonstration database.

For more information about Derby, see http://db.apache.org/derby.