Oracle ORDS使用SQL Developer发布Webservice
Assumptions and CommentsThis article assumes the following.
Enable ORDS for a SchemaRight-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 a $ ./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 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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |