Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Service Enabling IBM i Data using IBM Rational Application Developer By Nitin Raut ([email protected]) Certified Consulting IT Specialist IBM Corporation April 2010 Skill Level: Intermediate Service Enabling IBM i Data Scenario Page 1 Service Enabling IBM i Data using IBM Rational Application Developer By using the wizards and views in the relational database tools, you can define and work with databases; define and work with tables, views, and filters; create and work with SQL statements; create and work with DB2(R) routines (such as DB2 stored procedures and user-defined functions), and create and work with SQLJ files. You can also generate SQL DDL, DADX, and XML files. SQL Wizards and Java Bean generation wizards in Data Perspective help you to create SQL Statements and generate Java Beans from SQL statements. These Java Beans are then used to expose as web services with minimal modifications. This lab demonstrates how to connect to an IBM i database using a SQL Java Bean Web Service. Page 2 Service Enabling IBM i Data Scenario Service Enabling IBM i Data Scenario This lab demonstrates how to connect to an IBM i database using a SQL Java Bean Web Service. In this lab we define the SQL statement based upon our connection to an IBM i DB2 database and a query to the CITYINFO database which contains static weather information. • What you should be able to do: o At the end of the lab, you should be able to: Define Database Connection Create SQL Statement using SQL Statement creation Wizard Generate Java Bean Modify Java Bean Create web service using Java Bean. Test the web service using Web Service Explorer • The steps in this lab are: o Start Rational Application Developer o Setup the DB2 Connection and Create SQL statement o Generate and Modify Java Bean o Generate and Test the Web Service • Skill Prerequisites o High level understanding of IBM i Database and concepts o Understanding of Java programming language concepts and beginner Java programming skills Service Enabling IBM i Data Scenario Page 3 Required Materials o Client system requirements: IBM Rational Developer for Power Systems (RDp) V7.5 o Page 4 Lab information sheet: Variable Description Demonet IBM i <team_number> Team Number 99 <IBMi> IBM i hostname iseriesd.demos.ibm.com <IBMi_userid> IBM i user ID SOADEMO <IBMi_password> IBM i password demo4you <app_lib> Application library FLGHT400 <app_lib_modules> Application Library Modules FLGHT400M <workspace> Workspace C:\PoT\SOAiV75\workspace <team_dir_local> Team directory local C:\PoT\SOAiV75\teamxx Service Enabling IBM i Data Scenario 1.1 Start Rational Developer for Power Systems (RDp) Skip to next section if …. You are already in Rational Developer for Power Systems and you have started WebSphere Application Server Test Environment Start Rational Developer for Power Systems (RDp) __1. Go to Start => All Programs => IBM Software Development Platform => IBM Rational Developer for Power Systems Software V7.5 => IBM Rational Developer for Power Systems Software __2. In the workplace launcher window, enter <workspace> (shown by default) in the workspace field and press OK. (Please make sure that Use this as a default and do not ask again is NOT checked). Note: if not prompted for the workspace go to the next step Important! Please make sure that Use this as a default and do not ask again is NOT checked __3. On the Welcome page. Click X to close or press Workbench icon. Service Enabling IBM i Data Scenario Page 5 Start WebSphere Application Server Test Environment Start WebSphere Application Server Test Environment This is very important before invoking the web services wizard, as the wizard will fail. __4. In current perspective (Remote System Explorer by default). Select Window => Open Perspective => Other. Select Web Perspective and click OK. __5. In the Web Perspective, click on Servers tab (bottom of screen). Select WebSphere Application Server 7.0 and press Start button. __6. You should see console view with startup messages. Once WebSphere Application Server is started you will see Server view with status “Started”. Page 6 Service Enabling IBM i Data Scenario __7. Another way to make sure WebSphere Application Server Test Environment is started is to see the console view with message “Server server1 open for e-business”. Troubleshooting If the WebSphere Application Server Test Environment does not start. Please check server connection type and admin port. To check configuration, double click on WebSphere Application Server 7.0 under server view. You may manually provide the connections settings and select SOAP connector port instead of RMI port which is more compatible with firewalls. Click on X and save the configuration when prompted. Service Enabling IBM i Data Scenario Page 7 1.2 Set up the DB2 Connection and Create SQL Statement Define the connection __1. Go to Window => Open Perspective => Other. In the Open Perspective window, select Data and click OK. __2. In Data Perspective, click on Data Source Explorer view and click on New Connection Profile icon as shown below: Page 8 Service Enabling IBM i Data Scenario __3. In New Connection window, under select a database manager list, select DB2 for i5/OS. Enter following details: Host: Enter the full name of the IBM i <IBMi> where the database is located. (Please refer to lab information section of the lab) User name: enter <IBMi_userid> Password: enter <IBMi_password> Check Save password box. Click on Test Connection to verify that the setup is correct. Click OK on the Test Connection successful message. Click Next. Service Enabling IBM i Data Scenario Page 9 __4. In the filter window, uncheck disable filter check box. Check Selection button and select CITYINFO library and click Finish. __5. You will see a new connection defined under Database Explorer view. Database explorer view is available in various perspectives. This database connection is not associated with any project and it can be used in any project in this workspace. You may drill down in the connection to see various objects under the database schema CITYINFO. Page 10 Service Enabling IBM i Data Scenario Create Data Development Project __6. Select File -> New -> Data Development Project. __7. In the New Data Development Project window, enter project name: DataDevxx (Where xx is your team number) and click Next. __8. In the select connection window, select <IBMi> connection created in the previous step. Click Next. __9. In Default Application Process Settings dialog, take the defaults and click Finish. Service Enabling IBM i Data Scenario Page 11 Create SQL Statement __10. Right click on DataDevxx project in Data Project Explorer view and select New -> SQL or XQuery Script. __11. In script and tool window, enter script name: CityInfoQuery, select SQL Query Builder tool and SELECT for statement type. Click Finish. Page 12 Service Enabling IBM i Data Scenario __12. Next, you can either enter the SQL statement in CityInfoQuery.sql view or use the SQL builder tools to build it. Here is the SQL statement : SELECT WEATHER, TEMP FROM CITYINFO.TOCITY WHERE TOCINT = :airportcode Let us use the SQL builder to build this statement. First, we need to add table. Right click in the pane just below CityInfoQuery.sql view and select Add Table. Service Enabling IBM i Data Scenario Page 13 __13. In the Add table dialog, expand CITYINFO database schema and select TOCITY table and click OK. __14. Next select fields from the table. Select WEATHER and TEMP fields. See the SQL statement getting built in the CityInfoQuery.sql view. Page 14 Service Enabling IBM i Data Scenario __15. Next let us specify condition to query this table using a host variable. Click on Conditions tab. Select TOCINT column from the drop down list. Service Enabling IBM i Data Scenario Page 15 __16. Select ‘=’ under operator and select Build Expression under. __17. Click outside value field (or press enter key) to see the Expression Builder. Select Constant – numeric, string, or host variable and click Next. Page 16 Service Enabling IBM i Data Scenario __18. In the Constant Options window, select String Constant: and click Next. __19. In String Constant Builder window, Under string constant type: select Host Variable name Type variable name: airtportcode in the field and click Finish. Service Enabling IBM i Data Scenario Page 17 __20. Page 18 Back in Data Perspective, you will see the SQL statement built. Save the SQL statement by pressing floppy icon or File -> Save from menu. Service Enabling IBM i Data Scenario __21. Next, let us test the SQL statement. Right click in CityInfoQuery.sql view and select Run SQL. __22. In Host variable value window, Enter value for AIRPORTCODE variable: ATL and click Finish. Service Enabling IBM i Data Scenario Page 19 __23. Page 20 In SQL Results view, click on Succeeded message and then click on Result1 view to see the results. Close CityInfoQuery.sql view by pressing ‘X’. Service Enabling IBM i Data Scenario 1.3 Generating Java Bean from SQL Statement In this section you will use the SQL statement you created earlier and build a JavaBean interface using Data Perspective. Then you will use the Web service wizard to build a Web service interface to this JavaBean and then test it using the Web Service Explorer. Create dynamic web project. __1. Go to web perspective. Window -> Open Perspective -> Other and then select Web and click OK. __2. Select File -> New -> Dynamic Web Project. Service Enabling IBM i Data Scenario Page 21 In the Dynamic Web Project window, Enter Project Name : CIxxSQLService ( Where xx is your <team_number>) Select target runtime : WebSphere Application Server v7.0 Make sure the EAR project name is: CIxxSQLServiceEAR ( Where xx is your <team_number>) Click Finish. Page 22 Service Enabling IBM i Data Scenario Generate Java Bean __3. Go to Data perspective. (Window -> Open Perspective -> Other and then select Data and click OK). __4. Expand the DataDevxx data development project created earlier. Expand SQL Scripts node and right click on CityInfoQuery.sql statement and select Generate Java Bean. __5. In Java Class Specification screen, In the Name field enter CityInfoQuery Click browse next to source folder and select CIxxSQLService/src In package name field enter : com.ibm.cityinfoquery.bean Click Next. Service Enabling IBM i Data Scenario Page 23 __6. In specify runtime database connection information screen, under How will user authentication be provided? Select Inside the execute() method radio button and enter <IBMi_userid> and <IBMi_password> (Please refer to lab information section of the lab) and click Next. Note: This is not the most efficient or secured mechanism for connecting to the database. You should use the datasource connection option in a production environment. __7. Page 24 In review the specification window, it shows the methods which will be created. Click Finish. Service Enabling IBM i Data Scenario __8. Go to Web Perspective. Go to window -> Open Perspective -> Other. Select Web in the open perspective window and click OK. __9. Expand CIxxSQLService project -> Java Resources: src and com.ibm.cityinfoquery.bean package. You will see CityInfoQuery.java file. Service Enabling IBM i Data Scenario Page 25 Import jt400.jar file (JDBC Driver) __10. Go to WebContent -> WEB-INF -> lib folder. __11. Right click on lib folder and select Import. Page 26 Service Enabling IBM i Data Scenario __12. Expand General node, select File System and click Next. __13. Click browse next to From directory field and navigate to your <team_dir_local> and drill down to SQL_lab directory. Select jt400.jar file and click Finish. Service Enabling IBM i Data Scenario Page 27 __14. Next let’s import the Java class written to wrapper CityInfoQuery.java class and return appropriate parameters. Right click on com.ibm.cityinfoquery.bean package and select Import. __15. Expand General node, select File System and click Next. __16. Click browse next to From directory field and navigate to your <team_dir_local> and drill down to SQL_lab directory. Select CityInfoQueryWS.java file and click Finish. Page 28 Service Enabling IBM i Data Scenario __17. There should not be any errors after the import. If there are any errors, please do not proceed with the web service creation step. Service Enabling IBM i Data Scenario Page 29 1.4 Create Web Service from Java Bean using Web Services Wizard __1. Your next step will be to create a Web service interface to this component. Right click on CityinfoQueryWS JavaBean source file and select Web Services -> Create Web service. Page 30 Service Enabling IBM i Data Scenario __2. In Web Services screen, change the dial to Test Service option and make sure Web Service runtime: IBM WebSphere JAX-RPC is selected. Click Next. __3. On Service Endpoint Interface Selection screen, click Next. __4. On Web Service Java Bean Identity screen, click Next. It may take a few seconds for the code to generate, deployed and the Web project to start. Please be patient. __5. On the Test Web Service window, click Launch next to Web Service Explorer which will launched in the browser window. Service Enabling IBM i Data Scenario Page 31 __6. Page 32 Click on CIQueryService operation. Service Enabling IBM i Data Scenario __7. Enter Airport code: ATL and click Go. You should see the results in the Status pane. __8. Click on Source link in the status pane to look at the SOAP envelope data. __9. Close the browser window to go back to Rational Developer for Power Systems. __10. Back in web services wizard, click Finish. Service Enabling IBM i Data Scenario Page 33 Congratulations!!! You have completed this lab. Page 34 Service Enabling IBM i Data Scenario