Access container and server services from enterprise components

This page discusses - Access container and server services from enterprise components

Access container and server services from enterprise components

Access container and server services from enterprise components

Setting up a server to test Data source

  1. In the Servers view, double-click the TitanServer server. The server editor opens.

  2. Select the Data source tab at the bottom of the editor.

  3. To test data sources at the node level, expand Node Settings. To test data sources at the server level, expand Server Settings.

    Expand Server Settings.

  4. A JDBC provider for DB2 and for Cloudscape will already be created for you (in the Server Settings section only). Before using the predefined JDBC provider, verify that the Class path field specified in the JDBC provider is the correct class path that contains the database driver. Select the JDBC provider from the JDBC provider list and click Edit to edit the JDBC class path.

  5. Define a data source and resource properties. Beside Data sources defined in the JDBC provider selected above list, click Add.

  6. Select the type of JDBC provider, for example Cloudscape JDBC Provider.

    JDBC Provider

    Select Version 5.0 data source and click Next.

  7. On the Modify Data source page, specify the details of the data source that you want to create. For more information about any of the fields on this wizard, select the field and then press F1.

    Name - TitanDS.

    JNDI name - jdbc/TitanDS.

    Select the Use this data source in container managed persistence (CMP) check box.

    Modify Data source

    Click Next.

  8. In the Resource Properties list table, select databaseName.

    In the Value field, type the following: c:/titandb.

    Modify Data source
  9. Click Finish. You associated a pooled database connection to a JNDI name that can be used by the application.

    Data source

Adding Datasource references to enterprise bean

You can add different types of references to an enterprise bean, including resource references.

To add resource references to an enterprise bean:

  1. In the J2EE Hierarchy view, right-click the desired EJB module and select Open With > Deployment Descriptor Editor from the pop-up menu.

  2. On the References page of the editor select the enterprise bean that you want to add a reference to (the referencing bean) - Ship, and click the Add button. The Add Reference wizard opens.

  3. Select the type of reference that you want to create (Resource reference), and click Next.

    References
  4. Complete these fields:

    • Name - Specifies the name of the reference (jdbc/TitanDS).

    • Type - The expected type of the resource manager connection factory (javax.sql.DataSource).

    • Authentication - Specifies the authentication method (container or application) for the resource manager (Container).

    • Sharing Scope - Specifies whether connections can be shareable or unshareable. This option is available for J2EE 1.3-compliant application client modules (Shareable).

    • Description - Text that describes the reference (Titan application Data Source).

  5. Click Finish. 0

    References

The reference is added to the bean that you selected and is displayed on the References page of the EJB deployment descriptor editor.

Add WebSphere Binding information (the JNDI (Java Naming and Directory Interface) name that the bean code uses to get a reference to a data source) - jdbc/TitanDS

WebSphere Binding information

The Data source reference is added to the ejb-jar.xml deployment descriptor:


<entity id="Ship">
	<ejb-name>Ship</ejb-name>
	...
	<resource-ref id="ResourceRef_1122305703058">
		<description>Titan application Data Source</description>
		<res-ref-name>jdbc/TitanDS</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
		<res-sharing-scope>Shareable</res-sharing-scope>
	</resource-ref>
</entity>
					
					

Defining JNDI bindings (CMP connection factory) 1

You can define JNDI bindings, or CMP connection factory bindings, for EJB 2.0 beans.

The CMP factory connection binding is a setting specific to WebSphere Application Server. See the WebSphere Application Server documentation for more detailed information about component-managed authentication and container-managed authentication.

To define CMP connection factory bindings: 2

  1. Switch to the J2EE perspective.

  2. In the J2EE Hierarchy view, right-click the desired EJB 2.0 module, and select Open With > Deployment Descriptor Editor from the pop-up menu.

  3. On the Overview page of the editor, in the WebSphere Bindings section, go to the CMP Connection Factory Binding section. 3

  4. Type a JNDI name - jdbc/TitanDS

  5. Select one of the following container authentication types:

    • Per_Connection_Factory - Select this option for component-managed authentication. 4

    • Container - Select this option for container-managed authentication.

JNDI name

Tutorials

  1. Appendix A. Additional materials
  2. WSAD 5.0 Practicing for IBM Test 000-287 Mind Map
  3. Deploy enterprise applications into servers
  4. Chapter 6. Assemble enterprise applications and deploy them in IBM WebSphere Application Server
  5. Configure resource and security-role references
  6. Design and develop custom tags
  7. Chapter 4. Demonstrate understanding of database connectivity and messaging within IBM WebShpere Application Server
  8. Chapter 5. EJB transactions
  9. Design and develop message-driven EJBs
  10. Design and develop entity EJBs
  11. Validate operational parameters of application server to support the enterprise application
  12. Chapter 1. Design, build and test reusable enterprise components
  13. Access container and server services from enterprise components
  14. Part I. Exam Objectives
  15. Explain implications of resource management on application design and implementation
  16. Manage end-user state and understand performance tradeoffs of using HTTP sessions
  17. Chapter 7. Validate, tune and troubleshoot an application within an IBM WebSphere Application Server environment
  18. Implement mechanisms for efficient inter-component calls
  19. IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide
  20. Chapter 3. Develop clients that access the enterprise components
  21. Implement Java clients calling Web Services
  22. Configure JMS connection factories and destinations
  23. Design, develop and test JSPs
  24. Use JTA to control transaction demarcation
  25. Manipulate transactional behavior of EJBs using deployment descriptors
  26. Implement mechanisms which support loose coupling between clients and components
  27. Identify misbehaving application components
  28. Preface
  29. WSAD 5.0 Practicing for IBM Test 000-287
  30. Part II. Appendixes
  31. Interact with connection pools to obtain and release connections
  32. Describe the effects of a server failure on the application
  33. Test and debug enterprise components
  34. Chapter 2. Design, build and test web components
  35. Chapter 2. Design, build and test web components