14 Sample Applications and Code Examples

This chapter describes code examples and sample applications that offer several approaches to learning about and working with WebLogic Server 12.1.3. These examples and sample applications are available through performing a custom installation and selecting to install the Server Examples.

This chapter includes the following sections:


This section provides an overview of installing and using the WebLogic Server code examples.

This section contains the following topics:

Installing the WebLogic Server Code Examples

When performing an installation of WebLogic Server, select the Complete Installation type to obtain the WebLogic Server and Coherence examples. For more information about installing WebLogic Server, see Installing and Configuring Oracle WebLogic Server and Coherence.

If you do not automatically launch the Quickstart Configuration Wizard from the installation program, but instead choose to configure the code examples and sample domains later, you can run the QuickStart Configuration Wizard manually. For more information, see "Running the QuickStart 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:


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

sh ./startWebLogic.sh


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.


The following conventions are used throughout the instructions for the WebLogic Server code examples:

  • 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\user_projects\applications.

  • 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\wl_server\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 New Examples

These code examples demonstrate new features for JAX-RS 2.0, JPA 2.1, and WebSocket 1.0. The examples are grouped in the following categories:

  • JAX-RS 2.0: Uses and introduces asynchronous processing, filter and interceptor, and Server-Sent Events (SSE) Jersey support.

  • JPA 2.1: Uses the Criteria Update and Criteria Delete API and the Stored Procedures API

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

Java EE 6 Examples

Oracle WebLogic Server fully supports the Java Platform, Enterprise Edition (Java EE) 6 specification. The Java EE 6 examples demonstrate how to implement Java EE 6 APIs and Oracle WebLogic Server-specific features. The examples are grouped in the following categories:

  • Bean Validation: Use bean validation with JPA entities, JPA from Java SE, and JSF managed beans.

  • Context and Dependency Injection (CDI): Introduces CDI with type-safe dependency injection, interceptors, and producers.

  • Data Source: Use the @DataSourceDefinition annotation.

  • EJB 3.1: Use asynchronous methods, a calendar-based timer, simplified programming model and packaging in a WAR file, portable global JNDI names, and singleton session beans.

  • Java API for RESTful Web Services (JAX-RS) 1.1: Build RESTful Web services with JAX-RS.

  • Java EE Connector Architecture 1.6: Use the Java EE Connector Architecture to connect two applications together using a stock trading application.

  • JPA 2.0: Use the JPA Criteria Query API and the @ElementCollection mapping type.

  • JSF 2.0: Incorporate Ajax in Web applications, create bookmarkable Web applications, and use Facelets and templating.

  • Servlet 3.0: Use annotations for servlets, filters, and listeners, handle file uploads with multipart files, and use asynchronous servlet and request handling, programmatic security, and servlet Web fragments.

Additional API Examples

These examples demonstrate how to implement additional Java EE APIs and Oracle WebLogic Server-specific features. The examples are grouped in the following categories:

  • Database Connectivity: Use DataSources, MultiDataSources, 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 WebLogic Administration Server.

  • 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 (or "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 3.0.x application development practices.

Derby Open-Source Database

Derby is an open source relational database management system based on Java, JDBC, and SQL standards. It 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.