14 Sample Applications and Code Examples

This chapter describes WebLogic Server code examples and sample applications that offer 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 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 Complete with Examplesto obtain the WebLogic Server and Coherence examples. For more information about installing WebLogic Server, see Installing and Configuring Oracle WebLogic Server and Coherence. To set up the WebLogic Server samples domain, launch the Quickstart Configuration Wizard when prompted after installation.

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\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 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:

  • Batch 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.

  • CDI 1.1: Use CDI events and the @TransactionScoped and @Transactional annotations.

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

  • EJB 3.2: Use the new session bean lifecycle 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.

  • JAX-RS 2.0: Use asynchronous processing, filters and interceptors, and server-sent events (SSE) Jersey support.

  • Java Connector Architecture 1.6: Develop a mail connector resource adapter and deploy connector resources with annotations defined in Java Connector Architecture 1.6.

  • JMS 2.0: Use JMS 2.0 in EJBs and servlets.

  • JPA 2.1: Use JPA criteria update and delete and stored procedures.

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

  • JSON-P: 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.

Java EE 7 Examples

The Java EE 7 examples demonstrate how to implement Java EE 7 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.2: 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 EE Connector Architecture 1.7: 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 Framework 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.