Oracle APEX 4.2公布RESTful Webservice
- Access to an Oracle Database 11g database or above that has the sample schema installed.
- Installed Application Express Release 4.2 into your Oracle Database.
- Access to the OEHR tables. If necessary, download and install OEHR Sample Objects available from OTN at http://www.oracle.com/technetwork/testcontent/oehr-sample-objects-131098.zip
- Installed Java Development Kit 6 or later to consume the RESTful Web Service using a Java client.
- Downloaded and unzipped the files.zipinto your working directory.
Purpose
This tutorial covers creating a RESTful Web Service and accessing the Web Service through an application in Application Express 4.2. This tutorial also covers consuming the Web Service using a Java client.
Time to Complete
Approximately 40 minutes
Introduction
Web Services enable applications to interact with one another over the web in a platform-neutral, language independent environment. In a typical Web Services scenario, a business application sends a request to a service at a given URL by using the protocol
over HTTP. The service receives the request, processes it, and returns a response. Web Services are typically based on Simple Object Access Protocol (SOAP) or Representational State Transfer (REST) architectures. RESTful Web Services are result oriented. The
scope of the Web Service is found in the URI and the method of the service is described by the HTTP method that is used such as GET, POST, PUT,
and DELETE.
This tutorial covers creating a RESTful Web Service declaratively using Oracle Application Express's SQL Workshop tool, and then consuming the same service by creating an application and adding a Web Service Reference to the RESTful Web Service. The RESTful
Web Service is also consumed using a Java client.
Prerequisites
Before starting this tutorial, you should have:
Creating
a RESTful Web Service
In this topic, you create a RESTful Web Service using RESTful Services tool in SQL Workshop. The RESTful Web Service Wizard is a set of pages in SQL Workshop that help you to create a RESTful Web Service declaratively. The RESTful Web Service calls a specific
SQL statement in your database.
Log into the Application Express Login page using your login credentials. Enter the following credentials and click Login.
Note: Here, the Workspace, Username and Password used are obe.
Workspace: OBE
Username: OBE
Password: obe

Click SQL Workshop.

Select RESTful Services.

Click Create to create a RESTful Service.

Enter Employees as the Name for the RESTful Service module. Enter the URI Template as employees to identify your Uniform Resource Identifier (URI). Select GET as the method. Select CSV for Format.
This identifies the HTTP method to be used for the Resource Handler. For Source, enter the following SQL query. This is responsible for handling the selected HTTP method. Click Create Module.
select * from oehr_employees

Click the GET method Resource Handler.

Change the Require Secure Access option from Yes to No. Click Apply Changes.

Click Test to test the behavior of the RESTful Service Handler.

You are prompted to save the file which you can then view using a CSV editor. The CSV format resultset is displayed. Make a note of the URI which is used later while creating a client service.


Click Create Handler to create a Resource Handler for the POST method.

Select POST for Method, Source Type as PL/SQL, Mime Types Allowed as application/json. Select No for Requires Secure Access. In the Source section enter the following PL/SQL
code to create a row by inserting values into the employees table. Click Create.
declare
id oehr_employees.employee_id%TYPE;
begin
id := oehr_employees_seq.nextval;
insert into oehr_employees (employee_id,first_name, last_name, email, hire_date, job_id)
values (id, :first_name, :last_name, :email, to_date(:hire_date, 'DD-MM-YYYY'), :job_id); :employee_id := id;
end;

Scroll down the page and click Create Parameter to add an OUT parameter to the handler that will return the newly created employee’s ID.

Enter employee_id for Name and employee_id for Bind Variable Name. Select OUT for Access Method, HTTP Header for Source Type, and String for Parameter Type. Click Create.

You will next create a new template to retrieve JSON resultset based on Query One Row with a Bind Variable. Create a new template by clicking Create Template.

Enter employees/{id} for URI template. Click Create.

Click Create Handler.

Select Query One Row for Source Type and select No for Requires Secure Access. Enter the following SQL statement for Source and click Create.
select * from oehr_employees where employee_id = :id

Click Create Parameter.

Enter id for Name and Bind Variable Name. Select Source Type as HTTP Header. Click Create.

The Source Type URI is not being displayed and hence you want to edit the Resource Handler Parameter that you just created. Select id from the Parameter list and select URI for Source Type. Click Apply Changes.


Click Set Bind Variables.

Enter 103 or any Employee ID for the Value of the :ID Bind Variable and click Test.

Open the file. All the information for employee_id is displayed, which is the variable passed as the final portion of the URI. Close this window.

You create a new template for Retrieving JSON Result Set Based on a Feed. Here, you create the employeesfeed/ RESTful service, which selects the employee_id and the first_name values in the employees table and displays them as a feed. Create
a new template by clicking Create Template.

Enter employeesfeed/ for URI template. Click Create.

Click Create Handler.

Select Feed for Source Type and select No for Requires Secure Access. Enter the following SQL statement for Source and click Create.
select employee_id, first_name from oehr_employees order by employee_id, first_name

Click Create Template.

Enter employeesfeed/{id} for URI template. Click Create.

Click Create Handler.

Select Feed for Source Type and select No for Requires Secure Access. Enter the following SQL statement for Source and click Create.
select employee_id, first_name from oehr_employees where employee_id = :id

Click GET method of the employeesfeed/ URI template type

Click Test .

The data returned is displayed for all employees in the OEHR_EMPLOYEES table. The URI contains the link to the individual record. This link is actually using the employeesfeed/{id} Resource Template.

Copy the link and execute it in the browser. This will display the details of the individual employee's record.


Creating
a RESTful Web Service Reference in Application Express
In this topic, you consume the RESTful Web Service in Apex by creating a database application and by creating a Web Service Reference in the application. You create a form and report page that uses the web service.
Note: Make sure you have granted the connect privileges by executing the APEX_ACL.sql script from the files.zip that you have unzipped in the Prerequisites section of this
tutorial.
Navigate to your workspace home page and create a new application by selecting Application Builder > Database Applications > Create.


Enter the Name of the application as RESTful Web Services App and click Create Application.

Click Create Application.

On the application home page, click Shared Components.

Under Logic, click Web Service References.

Click Create.

Select REST for Web Reference and click Next.

Enter Employees for Name, enter the URL for URL. In this case enter http://localhost:8888/apex/obe/employees . Since the REST Web Service does not require an HTTP Header parameter, click the Delete
Header icon. Click Next.

Delete the input parameter by clicking the Delete Parameter icon. Click Next.

Select Text for Output Format. Enter the names of the parameters like Employee ID, Name, Hire Date, and Job ID by mapping them to the response. Click Test.


Select Test.

Scroll down to view the response. Click Close.


Click Create.

Click Create Form & Report on Web Service.

Select Web Service Reference as Employees. Click Next.

Accept the default values and click Next.

Click Next.

Select the check box next to Name to select all the parameters and click Next.

Click Next.

Click Create.

Click Run Page.

Enter your login credentials if prompted as OBE for Username and obe for Password. Click Login.

Click Submit.

The resultset is displayed.

Consuming
the RESTful Web Service Created in Application Express Using a Java Client
In this topic, you consume the Web Service that you have created in Application Express using a Java Client.
Open Command Prompt.

Execute the following command to navigate to the directory where you extracted the files available in the Prerequisites of this tutorial. Navigate to where the RESTemp java code resides. If you have extracted it in the Downloadsdirectory
then, you can find the RESTemp file in the C:\Downloads\files\RESTemp directory.
cd Downloads
cd files\RESTemp

To fetch the details of an employee, enter the following command. Pass a value for employee_id. Note: Here, the command line parameter 'S' indicates that you want to do a select. Also, you have to edit the run.cmd file that you have downloaded
to replace the URL for your RESTful Web Service.
run.cmd S [employee_id]

The values for the employee are displayed.

To insert new values into the employees table, enter the following command to invoke the POST Method which will insert a new row into the table. Note: Here, the command line parameter 'I' indicates that you want to insert a new row.
run.cmd I

Enter the first name, last name, email address, hire date, and job ID. You will notice that a new row is created with a new employee ID.

You can verify if this new row entry was created in the table by navigating to SQL Workshop to check for the new row values.
Summary
- Create a RESTful Web Service in Application Express
- Create a RESTful Web Service Reference in Application Express
- Consume the Web Service created in Application Express using a Java Client
- APEX OTN Home Page
- To learn more about Application Express 4.2, refer to additional OBEs in the Oracle Learning Library
dc=D67259GC20&intcmp=WWOU11042424MPP032C002" style="text-decoration:none">Oracle Application Express: Developing Web Applications
- Oracle University
- Lead Curriculum Developer: Anupama Mandya
In this tutorial, you have learned how to:
Resources
Credits
Put credits here
Oracle APEX 4.2公布RESTful Webservice的更多相关文章
- SOAP Webservice和RESTful Webservice
http://blog.sina.com.cn/s/blog_493a845501012566.html REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的 ...
- Restful是什么,SOAP Webservice和RESTful Webservice
首先,应该怀着这样一种心态来学习Restful——Restful你可以将其理解一种软件架构风格,并且诠释了Http协议的设计初衷,所以不要把他理解的那么神秘,Restful风格有好处,当然也是有坏处的 ...
- RESTful WebService入门(转)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lavasoft.blog.51cto.com/62575/229206 REST ...
- Jersey框架一:Jersey RESTful WebService框架简介
Jersey系列文章: Jersey框架一:Jersey RESTful WebService框架简介 Jersey框架二:Jersey对JSON的支持 Jersey框架三:Jersey对HTTPS的 ...
- CXF发布restful WebService的入门例子(客户端)
上篇说了怎么用cxf发布restful webservice,由于浏览器只能对该service发送http的GET请求,所以如果想对服务器上的数据,还需要实现客户端. 客户端的实现方式有无数种...可 ...
- CXF发布restful WebService的入门例子(服务器端)
研究了两天CXF对restful的支持. 现在,想实现一个以 http://localhost:9999/roomservice 为入口, http://localhost:9999/roomse ...
- RESTful Webservice (一) 概念
Representational State Transfer(表述性状态转移) RSET是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩 ...
- 使用CXF与Spring集成实现RESTFul WebService
以下引用与网络中!!! 一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...
- RESTful WebService入门
RESTful WebService入门 RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状 ...
随机推荐
- php异常处理的深入
引出 如果你调一个类,调用时数据验证时报了个错,你会以什么方式返回 数组,布尔值? 数组这个可以带错误原因回来,那布尔值呢? 返回了个 false, 报错时把错误放在类变量里?还是专门用一个获取错误的 ...
- Python解析Socket数据流异常bytes问题
Python解析Socket数据流异常bytes问题 -- 2019-03-12 python在通过socket发送数据时,英文字符转义后为原来本身的字符,占一个字节(如:s转移后为s),而中文字符在 ...
- P3168 [CQOI2015]任务查询系统(主席树)
题目描述 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第Ei ...
- ORA-12514: TNS: 监听程序当前无法识别连接描写叙述符中请求的服务
不指定数据库能够正常连接: 指定数据库和使用PL/SQL Developer都出现错误: 在此说明一下我的环境:Oralce装的是64位的在使用PL/SQL Developer时曾出现过初始化错误,解 ...
- cocos2d-x 3.0正式版 vs2013配置
cocos2d-x 3.0正式版与之前的版本号差异较大,曾经的教程非常多都不使用了. 1.从cocos2d-x官网http://www.cocos2d-x.org下载3.0版的压缩包,随便解压一个位置 ...
- hadoop集群中动态添加新的DataNode节点
集群中现有的计算能力不足,须要另外加入新的节点时,使用例如以下方法就能动态添加新的节点: 1.在新的节点上安装hadoop程序,一定要控制好版本号,能够从集群上其它机器cp一份改动也行 2.把name ...
- 三段式状态机 [CPLD/FPGA]
状态机的组成其实比较简单,要素大致有三个:输入,输出,还有状态. 状态机描述时关键是要描述清楚前面提高的几个状态机的要素,即如何进行状态转移:每个状态的输出是什么:状态转移是否和输入条件相关等. 有人 ...
- 浏览器Console创建canvas base64 png图片
火狐中运行:console.log var canvas = document.createElement('canvas'); canvas.width =1 canvas.height =1 ca ...
- Android自定义组件系列【16】——最帅气的自动滚动广告条
前一段时间要实现一个滚动的广告条,参考了一下网上许多实现,发现实现都很麻烦,所以我决定自己使用ViewFlipper来实现一个,在此将代码贴出来,与大家共享. 转载请说明出处:http://blog. ...
- Android 使用Retrofit请求API数据
概览 Retrofit 是一个Square开发的类型安全的REST安卓客户端请求库.这个库为网络认证.API请求以及用OkHttp发送网络请求提供了强大的框架 .理解OkHttp 的工作流程见 这个 ...