OSB - JCA DB Transport Tutorial
OSB - JCA DB Transport Tutorial
Abstract:
This document describes the steps for using the JCA DB Adapter with OSB
1. Introduction .................................................................................................................................3 2. Software Requirements..............................................................................................................4 3. Pre-requisites..............................................................................................................................5 4. High level Steps..........................................................................................................................6 5. Use Case 1 DB Business Service.............................................................................................7 5.1 Step 1 Generate WSDL for DB operations in JDeveloper...................................................7 5.2 Step 2 - Create OSB Business Service with Non-Managed Connection Mode....................19 5.3 Step 3 - Test OSB Business Service with Non-Managed connection mode........................23 5.4 WLS Console Configuration ................................................................................................24 5.4.1 Configure Data Source.................................................................................................25 5.4.2 Configure DB Adapter Connection Factory..................................................................28 5.5 Step 4 Test OSB Business Service with Managed connection mode...............................32 6. Use Case 2 DB Proxy Service................................................................................................34 Page 1 Oracle Corporation - PROPRIETARY Use pursuant to Company Instructions
Page 2 of 48 6.1 Generate WSDL for DB Poll operation in JDeveloper..........................................................34 6.2 Create OSB Proxy Service to poll the database..................................................................41 6.2.1 Implement proxy services message flow.....................................................................45 6.3 Deploy and test OSB Proxy Service....................................................................................47
Page 3 of 48
1. Introduction
This document provides step by step instructions for creating Oracle Service Bus (OSB) configuration to update and retrieve application data residing in a database. In the first use case OSB Business Service, with JCA (DB) transport protocol, performs database operations such as select, insert, update, delete, invoking a stored procedure, or executing any custom SQL against the database. Hence, OSB acts as a proxy between the client that needs to perform database operations and the database. Client invokes the proxy service, which uses Route, Service Callout, or Publish to invoke the JCA business service.
Clie nt
In the second use case OSB Proxy Service, with JCA (DB) transport protocol, polls a database table for new or changed records. Hence, OSB acts as a proxy between the database and the backend service that intends to receive changes from the database. Proxy service polls for database table changes. Proxy service then uses Route, Service Callout, or Publish to propagate the changes to the backend service.
Database
Poll or
New
Backen dServic e
OSB
10/15/01
Page 4 of 48
2. Software Requirements
Oracle Database Express Edition 10g (Oracle XE) OSB 10gR3 MP1 (10.3.1) JDeveloper 10.1.3.x
Page 5 of 48
3. Pre-requisites
1. All required software installed 2. Create a backup of JDEV_HOME\integration\lib\DBAdapter.jar 3. Copy OSB_HOME\eclipse\plugins\com.bea.alsb.transports.jca_<version>\DBAdapter.jar to JDEV_HOME\integration\lib 4. Create a Customer table with following columns in Oracle XE database. This document assumes the table is created in the system schema and the database username/passwd is system/welcome1. Use the appropriate database schema and credentials as your case might be.
5. Document assumes some level of familiarity with a. Installing Oracle XE database, OSB, JDeveloper b. Creating tables using Oracle XE database. c. Using OSB proxy and business services, deployment, and testing d. Using JDeveloper to create projects, and Database Adapter instances
10/15/01
Page 6 of 48
Page 7 of 48
b. Name: DBContent
10/15/01
Page 8 of 48
Page 9 of 48
3. Create Database Adapter a. Select Project ->Right Click ->New ->Business Tier ->Web Services ->Database Adapter->click OK (DB adapter wizard comes up)
10/15/01
Page 10 of 48
Page 11 of 48
5. Step 2 of 2 Service Connection a. Click New to create a new connection (or pick a connection if one already exists) Create Database Connection wizard comes up
10/15/01
Page 12 of 48
ii. Step 2 of 4 (Authentication) provide Database username/passwd 1. Username: system 2. Password: welcome1
Page 13 of 48
iii. Step 3 of 4 (Connection) provide Database connection information 1. Driver: thin 2. Hostname: localhost 3. JDBC Port: 1521 4. SID: XE
10/15/01
Page 14 of 48
Page 15 of 48 b. Select the connection created in a c. JNDI Name: eis/DB/DBConnection2 (NOTE: Remember this JNDI Name as you will require it when configuring managed connection factory in WLS Console for Managed connection mode)
6. Step 3 of 3: Operation Type a. Select Perform an Operation on a Table: leave default (all operations Insert or Update, Insert Only, Update Only, Delete, Select)
10/15/01
Page 16 of 48
7. Select Table a. Click Import Tables - Select the appropriate table you want to work with
Page 17 of 48 i. Provide appropriate Schema and Name filter and click on Query to query the tables. For e.g. use Customer% as the Name filter and select the appropriate schema.
ii. Select Customer table that was created earlier using Oracle XE) to Selected.
iii. Click Next 8. Step 5 of 7: Relationships Page 17 Oracle Corporation - PROPRIETARY Use pursuant to Company Instructions 10/15/01
Page 18 of 48 a. Click Next 9. Step 6 of 7: Object Filtering a. Leave defaults for Object Filtering and Click Next 10. Step 7 of 7: Define Selection Criteria a. Check Return Single Result Set b. Click Finish
Following files are created: DatabaseOutbound.wsdl DBAdapterOutboundHeader.wsdl DatabaseOutbound_table.xsd DatabaseOutbound_toplink_mappings.xml NOTE: Remember the file system location for these files. You have to browse the WSDL (DatabaseOutbound.wsdl) and the top link mapping file (DatabaseOutbound_toplink_mappings.xml) when creating JCA business service in OSB.
Page 19 of 48
5.2 Step 2 - Create OSB Business Service with NonManaged Connection Mode
1. Create OSB configuration project followed by OSB Project 2. Create new business service a. Select Project->Right click->New->Business Service
3. Configure business service a. Service Type: WSDL Web Service b. Click Browse->Click Consume c. Select Service Resource as File System
d. Specify WSDL location by clicking Browse for WSDL Location and point to the wsdl file above (DatabaseOutbound.wsdl)
10/15/01
Page 20 of 48
NOTE: If you did not replace DBAdapter.jar in JDeveloper with the DBAdapter.jar from OSB, the imported WSDL has an error. You can fix this by deleting the DatabaseOutboundSelect operation and its corresponding entry under <binding>. See step 3 of Pre-requisites. If you run into the above error, fix the error as detailed earlier. e. Next, on the business service select the WSDL port from the WSDL that is already imported into the workspace.
Page 21 of 48 f. You will notice the Transport Protocol defaults to jca and Endpoint URI points to the JNDI name specified in JDeveloper during Database Adapter configuration (See figure below).
NOTE: The JNDI name is used by the business service to look up the connection factory if the Connection mode is Managed.
Figure 1: Transport configuration 4. Configure JCA Transport specific configuration on Business Service a. Leave all properties as default except i. Connection Mode: Non-Managed NOTE: Setting Connection Mode to Non-Managed helps quickly testing the business service. In this mode, connection information can be specified in two ways: One, in the WSDL. This is the case when the property Always use configuration from JCA WSDL is checked. Two, in the JCA Transport specific properties, - Connection Factory Properties & Connection Factory Authentication Properties. In this example, we use the connection information present in the WSDL. NOTE: In production, it is recommended to use Connection Mode as Managed.
ii. Specify Toplink file 1. You will notice an error message shown below for the Toplink file Page 21 Oracle Corporation - PROPRIETARY Use pursuant to Company Instructions 10/15/01
Page 22 of 48 2. Toplink File property -> Click Browse and select the top link mappings xml file (DatabaseOutbound_toplink_mappings.xml).
5. Finish You will see the error message go away and the Non-Managed Connection Mode.
Page 23 of 48
5.3 Step 3 - Test OSB Business Service with NonManaged connection mode
1. Start Weblogic server for OSB 2. Create Server connection in Workshop
4. Select Operation as Insert and specify the test data (id must be unique)
10/15/01
Page 24 of 48
Figure 4: Test console - Response 5. Look at the database to see the row inserted
Figure 5: Row inserted in the database Before we move to the next step to test the business service in Managed mode we must create the Data Source and the Connection Factory using WLS Console.
Page 25 of 48
Figure 5: WLS Console Home Page 2. Click New to create a new Data Source
3. Configure JDBC properties for the data source a. Name: MyDB b. JNDI Name: MyDB c. Database Type: Oracle
d. Database Driver: Oracles Driver (Thin XA) versions: 9.0.1, 9.2.0, 10, 11 e. Click Next NOTE: Remember the JNDI name for the data source. This is required when you create Connection Factory for the DB adapter.
10/15/01
Page 26 of 48
9. You will see the following message. You are done with configuring the Data Source.
10/15/01
Page 28 of 48
2. Click Customize this table on the right and set number of rows displayed to 100. Click Apply.
4. Create New Connection Factory a. Click on Configuration tab, followed by Outbound Connection Pools tab b. Select javax.resource.cci.ConnectionFactory and Click New
Page 29 of 48
6. Specify the JNDI Name for outbound connection instance. Next, click Finish NOTE: The JNDI Name here MUST match the JNDI Name specified in JDeveloper. The JNDI Name specified in JDeveloper also becomes the Endpoint URI of the business service (eis/DB/DBConnection2). See Step 5c in Configuring Database Adapter in JDeveloper and Step 3 in Creating business service in OSB.
7. You see the following messages. NOTE: Two important steps: one, update the deployment plan with the changes and two; update the deployment with the deployment plan (See Step 9 for updating deployment with the deployment plan). If you havent yet created a deployment plan for the DB Resource Adapter you will be asked to create one. In this case, you MUST create the deployment plan and then save the changes to the deployment plan. If you already created a deployment plan, it is updated with the changes.
10/15/01
Page 30 of 48 8. Update connection factorys Data Source property a. Select the connection you just created by clicking it (eis/DB/DBConnection2). You will see the following page
b. Click in the Property Value cell for xaDataSourceName, type the JNDI Name of the Data Source (MyDB) in the text field that appears, and then press ENTER. NOTE: Hitting ENTER after typing the data source name is critical. Otherwise, the value will NOT be saved. Tab will NOT work either. NOTE: The JNDI Name of the Data Source is the JNDI Name specified in Step 3 of the section on Creating a Data Source. c. Select xaDataSourceName (by clicking on the Check box on the left) and click Save. You will again see the messages to update the deployment with the content saved in the deployment plan.
NOTE: In some cases, saving changes to the deployment plan might generate errors. Just ignore the errors!
Page 31 of 48 a. Click on Deployments (on the left side) under Domain Structure b. Select the DBAdapter by clicking on the check box on the first column for the DBAdapter row c. Click Update.
d. You will see the following page. Leave the default (Redeploy application using following deployment plans). Click Next and then Click FINISH
NOTE: If you encounter an error by choosing the second option. Please select the first option (Update this application in place) and then click Next. e. You will see the following message. You are now done with configuring and updating the DBAdapter connection factory along with the Data Source
10/15/01
Page 32 of 48
5.5 Step 4 Test OSB Business Service with Managed connection mode
1. Complete steps in Section 5.4 to configure Data Source and DB Adapter Connection Factory. 2. In Eclipse, go to the Business Service definition and set the Connection Mode JCA Transport specific property to Managed
3. Right click on the business service->Run As->Run on server 4. Select Operation as Insert and specify the test data (id must be unique)
Page 33 of 48
Figure 7: Test console - Response 5. Look at the database to see the row inserted
10/15/01
Page 34 of 48
Page 35 of 48
5. Step 2 of 2 Service Connection. If service connection already exists (see Section 5.1) simply select the service connection (DbConnection2) and skip this step. a. Click New to create a new connection (or pick a connection if one already exists) Create Database Connection wizard comes up i. Step 1 of 4 (Type) 1. Connection Name: DbConnection2 2. Connection Type: Oracle JDBC ii. Step 2 of 4 (Authentication) provide Database username/passwd 1. Username: system 2. Password: welcome1 iii. Step 3 of 4 (Connection) provide Database connection information 1. Driver: thin 2. Hostname: localhost Page 35 Oracle Corporation - PROPRIETARY Use pursuant to Company Instructions 10/15/01
Page 36 of 48 3. JDBC Port: 1521 4. SID: XE iv. Step 4 of 4 (Testing) - Click Test connection b. Select the connection created in a c. JNDI Name: eis/DB/DBConnection2 (NOTE: Remember this JNDI Name as you will require it when configuring managed connection factory in WLS Console for Managed connection mode)
6. Step 3 of 3: Operation Type a. Select Poll for New or Changed Records in a table
Page 37 of 48
7. Select Table a. Click Import Tables - Select the appropriate table you want to work with
i.
Provide appropriate Schema and Name filter and click on Query to query the tables. For e.g. use Customer% as the Name filter and select the appropriate schema.
10/15/01
Page 38 of 48
ii.
Select Customer table that was created earlier using Oracle XE) to Selected.
iii.
Click Next
Page 39 of 48
8. Step 5 of 9: Relationships a. Click Next 9. Step 6 of 9: Object Filtering a. Leave defaults for Object Filtering and Click Next 10. Step 7 of 9: After Read a. Leave default: Delete the Row(s) that were Read b. Click Next
10/15/01
Page 40 of 48
11. Step 8 of 9: Polling Options a. Leave Polling Frequency at the default - 5 seconds. b. Set Database Rows per XML Document to 5
12. Step 9 of 9: Define Selection Criteria a. Check Single Result Set. Update select query if required. I left it to be the default. b. Click Finish
Page 41 of 48
Following files are created (see under DBContent/DBProject/Resources): DatabaseInbound.wsdl DatabaseInbound_table.xsd DatabaseInbound_toplink_mappings.xml NOTE: Remember the file system location for these files. You have to browse the WSDL (DatabaseInbound.wsdl) and the top link mapping file (DatabaseInbound_toplink_mappings.xml) when creating JCA proxy service in OSB.
10/15/01
Page 42 of 48
3. Configure proxy service b. Service Type: WSDL Web Service c. Click Browse->Click Consume
d. Select Service Resource as File System Specify WSDL location by clicking Browse for WSDL Location and point to the wsdl file above (DatabaseInbound.wsdl)
Page 43 of 48
e. Next, on the business service select the WSDL port from the WSDL that is already imported into the workspace.
f.
You will notice the Transport Protocol defaults to jca and Endpoint URI points to the JNDI name specified in JDeveloper during Database Adapter configuration (See figure below).
NOTE: The JNDI name is used by the business service to look up the connection factory if the Connection mode is Managed.
4. Configure JCA Transport specific configuration on Business Service a. Leave all properties as default Connection Mode is Managed
10/15/01
Page 44 of 48 b. Specify Toplink file i. You will notice an error message shown below for the Toplink file ii. Toplink File property -> Click Browse and select the top link mappings xml file (DatabaseInbound_toplink_mappings.xml).
5. Finish You will see the error message go away and the Managed Connection Mode.
Page 45 of 48
10/15/01
Page 46 of 48
NOTE: Make sure logging is turned on at Debug level from the WLS Console. Follow instructions in the next section (6.2.1.1). 6.2.1.1 Setting Log level to Debug from WLS Console From WLS Console 1. Click on Environment->Servers
4. Click Advanced
5. Set Minimum severity to Log, Log File Severity Level and Standard Out - Severity Level to Debug.
Page 47 of 48
3. You must see the following log on the server console. The two records created in the Customer table by executing the business service (DatabaseOutbound) in earlier sections will be picked up by the proxy service and logged. <Apr 25, 2009 12:47:39 PM PDT> <Info> <ALSB Logging> <BEA-000000> < [PipelinePairNode1, PipelinePairNode1_request, stage1, REQUEST] <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <dat:CustomerCollection xmlns:xsi=http://www.w3.org/2001/XMLSchemainstance xmlns:dat="http://xmlns.oracle.com/pcbpel/adapter/db/top/DatabaseInboun d"> Page 47 Oracle Corporation - PROPRIETARY Use pursuant to Company Instructions 10/15/01
Page 48 of 48 <dat:Customer> <dat:name>Pradeep</dat:name> <dat:id>1</dat:id> <dat:address>5470 Great America Pkwy, Santa Clara, CA</dat:address> </dat:Customer> <dat:Customer> <dat:name>Kiran</dat:name> <dat:id>2</dat:id> <dat:address>5470 Great America Pkwy, Santa Clara, CA</dat:address> </dat:Customer></dat:CustomerCollection></soapenv:Body>> 4. You can execute the business service (DatabaseOutbound) created earlier multiple times. This will create multiple records in the Customer table. The proxy service (DatabaseInbound) will pick up these records at 5 second intervals and log them to the server console. Each XML document received by the proxy service will contain maximum of 5 records as we set the number of rows per XML Document to 5 during DatabaseInbound adapter configuration in JDeveloper. NOTE: The db adapter uses one thread (The activation spec property, NumberOfThreads, is set to 1 by default) to poll the database. This thread is never released to the pool and hence appears as being stuck to the work manager which can result in stack trace in the system out and server log like the following: ####<Jun 9, 2009 8:13:08 AM CDT> <Error> <WebLogicServer> <jbayer-lap> <xbusServer> <[ACTIVE] ExecuteThread: '21' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1244553188484> <BEA-000337> <[STUCK] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "610" seconds working on the request "weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl@3a11b5c", which is more than the configured time (StuckThreadMaxTime) of "600" seconds. Stack trace: Thread-17 "[STUCK] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'" <alive, in native, suspended, waiting, priority=1, DAEMON> { -- Waiting for notification on: oracle.tip.adapter.db.InboundWork@3a11a7d[fat lock] java.lang.Object.wait(Object.java:???) oracle.tip.adapter.db.InboundWork.run(InboundWork.java:403) oracle.tip.adapter.db.inbound.InboundWorkWrapper.run(InboundWorkWrapper.java:43) weblogic.work.ContextWrap.run(ContextWrap.java:39) weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerI mpl.java:516) weblogic.work.ExecuteThread.execute(ExecuteThread.java:198) weblogic.work.ExecuteThread.run(ExecuteThread.java:165)
Page 49 of 48 You can ignore this error log. One can configure a new work manager and set Ignore Stuck Threads to true to not see the stuck thread logged at all. The proxy service can be configured to use this work manager by setting the Dispatch Policy.
10/15/01