Assumptions and Comments
This article assumes the following.
- You already have a functioninginstallation of ORDS.
- The paths for the ORDS configuration match those from the ORDS installation article listed above.
- You have an Oracle database available. In this article I will be using a 12c database,but it works just the same with an 11g database.
- You have a way to call the web services. Some GET web services can be called from a browser,but the other methods require some coding,or a REST client. I used "curl" and the "Advanced REST client" extension for Chrome.
- You already have an understanding of the varIoUs pieces of ORDS functionality. This article will not teach you about this,but the linked articles will.
Enable ORDS for a Schema
Right-click on the connection and select the "REST Services > Enable REST Services..." menu option.
Check the "Enable schema" checkBox and alter the schema alias if you don't want to expose the schema name in the URL. In this case we will ignore authorization. Click the "Next >" button.
If you want to see the code that will run to enable ORDS for the schema,click the "sql" tab.
Click the "Finish" button.
Click the "OK" button.
Enable AutoREST for an ObjectRight-click on the object and select the "Enable REST Service..." menu option.
Check the "Enable object" checkbox and specify an object alias if you don't want to expose the object name in the URL. In this case we will ignore authorization. Click the "Next >" button.
If you want to see the code that will run to enable AutoREST for the object,sans-serif; font-size: 16px;">
Create Basic RESTful Web ServiceTo let SQL Developer connect to your ORDS server,you will need to create a user through ORDS with the "SQL Developer" role.
cd /u01/ords $JAVA_HOME/bin/java -jar ords.war user tim_hall "SQL Developer"
The credentials are stored on the ORDS server in the following location.
cat /u01/ords/conf/ords/credentials
With the ORDS user in place,you can now proceed to develop web services using SQL Developer.
Select the "View > REST Data Service > Development" menu option.
On the resulting "REST Development" pane,click the connect button.
If you don't already have a connection,click the "+" button.
Enter the connection details,including the "Username" configured on the ORDS server,then click the "OK" button.
Enter the ORDS credentials and click the "OK" button.
Right-click on the "Modules" tree node and select the "New Module..." menu option.
Enter the module details and click the "Next >" button.
Enter the template details and click the "Next >" button.
Enter the handler details and click the "Next >" button.
Expand the tree and click on the GET handler. Click on the "Worksheet" tab. Enter the query associated with the GET handler.
All changes are performed locally,so changes need to be uploaded to the server to take effect. Right-click on the module and select the "Upload..." menu option.
The web service should now be available from your ORDS.
http://ol7-121.localdomain:8080/ords/pdb1/testuser2/testmodule1/emp/
If you want to save a local copy of the configuraton,right-click on the tree and select the "Save As..." menu option,then name and save the zip file. At the time of writing,this configuration is only a XML representation of the configuration,not the SQL used to create it.
ORDS AdministrationYou will need to create an ORDS user with the "Listener Administrator" role to let SQL Developer connect to your ORDS server for administration.
cd /u01/ords $JAVA_HOME/bin/java -jar ords.war user tim_hall "SQL Developer","Listener Administrator"
cat/u01/ords/conf/ords/credentials
Select the "View > REST Data Service > Administration" menu option.
Connect as you did for the developer pane. All configuration changes are local and need to be uploaded to the ORDS server for them to take effect.
SQLcl REST CommandTheSQLclutility includes aREST
command that can be quite useful.
$ ./sql testuser1/testuser1@pdb1 sqlcl: Release 4.2.0.16.175.1027 RC on Fri Jul 01 16:13:22 2016 Copyright (c) 1982,2016,Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning,OLAP,Advanced Analytics and Real Application Testing options sql> rest help REST ------ REST allows to export ORDS 3.X services. REST export - All modules REST export- Export a specific module REST export - Export a specific module related to the given prefix REST modules - List the available modules REST privileges - List the existing privileges REST schemas - List the available schemas sql>
Let's get a list of the REST modules.
sql> rest modules NAME PREFIX STATUS ITEMS_PER_PAGE ----------- ------------- --------- -------------- testmodule1 /testmodule1/ PUBLISHED 0 sql>
Now we know the module name,we can export the definition.
sql> rest export testmodule1 declare l_module_id number; l_template_id number; l_handler_id number; l_parameter_id number; begin l_module_id := ORDS_MetaDATA.ORDS_SERVICES.create_module( p_name => 'testmodule1',p_uri_prefix => '/testmodule1/',p_items_per_page => 0,p_status => 'PUBLISHED' ); l_template_id := ORDS_MetaDATA.ORDS_SERVICES.add_template( p_module_id => l_module_id,p_uri_template => 'emp/:empno',p_priority => 0,p_etag_type => 'HASH' ); l_handler_id := ORDS_MetaDATA.ORDS_SERVICES.add_handler( p_template_id => l_template_id,p_source_type => 'json/query',p_method => 'GET',p_source => 'SELECT * FROM emp WHERE empno = :empno'); commit; end; sql>原文链接:https://www.f2er.com/oracle/208597.html