Tuesday, February 19, 2008

Is Oracle 11g REST ready?

YES, if you have Oracle JVM installed!!
You only need to download an XMLDB REST adapter for Restlet framework and thats all.

But why users want to use REST stack inside Oracle databases if it comes with Native Web Services support using SOAP?

This is an open discussion over Internet, here one example at InfoQ web site - "Is REST winning?".
My personal list of benefits of REST over SOAP is:
  • Simplicity, from developer's perspective REST WS are quite straightforward.
  • Leverage of all HTTP features for caching, you can use Apache mod_cache or better than this Oracle Web Cache and ESI invalidation protocol to speed up your WS. Also the HTTP's 304 return code.
  • Less network traffic, a simple SOAP service requires 675 bytes at POST request and 306 bytes at response, similar REST WS only requires 79 bytes at GET request and 28 bytes at response. If you have a site with million of hits these differences are a lot wasted resources.
But anyway, you can implement now SOAP and REST WS inside your Oracle 11g database.
Performance result shows that you can get similar throughput (# request by second) either using SOAP native stack or REST Java stack, see this Google sheet with a preliminary result done using my notebook and Apache Benchmark.
Note that SOAP is 40% faster than REST, but SOAP example do not implement routing and many other things ready and used in Part12.java REST tutorial example, but look at a the performance improvement by simply using REST/Apache mod_cache combination.
- Requeriments
  • JDK 1.5 (included at your ORACLE_HOME/jdk directory)
  • Maven 2.0.x
  • an 11g target database
  • Internet connection to download public libraries into your local repository
- Install
XMLDB REST adapter for Oracle 11g database is build and deploy using Apache Maven tool, to install and test the code, open pom.xml file and edit section properties with your database parameter values.
Then in a command line execute:
mvn clean
mvn install
Maven will download all REST adapter libraries from public repositories (you need Internet connection at this point) except for Oracle libraries which are not in public sources. Maven will show that some dependency are not resolved satisfactorily. Using your ORACLE_HOME environment setting install it using for example:
mvn install:install-file -DgroupId=oracle -DartifactId=ojdbc5 \
-Dversion=11.1.0 -Dpackaging=jar -Dfile=$ORACLE_HOME/jdbc/lib/ojdbc5.jar
Repeat above process for each Oracle library required, all of them are at ORACLE_HOME directory, finally execute again install target.

- Test

Test your REST examples with your favorite browser using these URLs (they where configured as XMLDB Servlets by src/main/sql/registerServlet.sql script):

a POST example can be tested executing:
Tests using telnet
Some test can be tested using telnet to see which headers are sent and get as reponse from REST WS. At directory src/main/scripts there are two simple examples:
test_get.txt (similar to http://localhost:8080/users/scott/orders/300)
test_search.txt (similar to http://localhost:8080/search?kwd=marcelo+ochoa)
Use file information as follow:
[mochoa@mochoa ojvm-restlet]$ cat src/main/scripts/test_get.txt
GET /users/scott/orders/300 HTTP/1.0
Authorization: Basic c2NvdHQ6dGlnZXI=
[mochoa@mochoa ojvm-restlet]$ telnet localhost 8080
Connected to live.dbprism.mochoa.dyndns.org (
Escape character is '^]'.
GET /users/scott/orders/300 HTTP/1.0
Authorization: Basic c2NvdHQ6dGlnZXI=

HTTP/1.1 200 OK
MS-Author-Via: DAV
DAV: 1,2,
Date: Thu, 07 Feb 2008 18:25:13 GMT
Server: Noelios-Restlet-Engine/1.1.1
Content-Type: text/plain; charset=ISO-8859-1
Content-Length: 28

Order "300" for user "scott"

Well this is a jump start for XMLDB REST Adapter, many things can be implemented from now, for example a XDBDirectory class which inherit from org.restlet.Directory to browse XMLDB repository, REST WS implemented with XQuery pages stored inside XMLDB, a Variant for XMLType objects and others, also We have a plan to integrate this extension to Restlet project main trunk, I'll announce this in another post, stay connected ....


Kuassi Mensah said...

Marcelo, this is fabulous.
You have once again proven that the sky is the limit for the possibilities that Java in the database permits.

Kuassi http://db360.blogspot.com

Marcelo Ochoa said...

Hi Kuassi:
Thanks for your comment.
IMO Java in the database lets Oracle a competitive value against other database vendors to quickly implement and get ready new technologies like RESTful WS.
Users do not need to wait for the technology implemented into the next release, only need to choose the framework adapt them and start using it, reducing the time to market a lot.
Best regards, Marcelo.

Celular said...
This comment has been removed by a blog administrator.
tian said...


Thanks for your step by step information. However, when I followed the instruction and doing mvn install, I got this compile exception. Could you please give me some help.


[INFO] Compiling 28 source files to /opt/oracle/restletxmldb/ojvm-restlet/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

/opt/oracle/restletxmldb/ojvm-restlet/src/main/java/com/noelios/restlet/ext/xdb/ServletWarClientHelper.java:[21,33] cannot find symbol
symbol : class WarClientHelper
location: package com.noelios.restlet.local

/opt/oracle/restletxmldb/ojvm-restlet/src/main/java/com/noelios/restlet/ext/xdb/ServletWarClientHelper.java:[50,44] cannot find symbol
symbol: class WarClientHelper
public class ServletWarClientHelper extends WarClientHelper {

/opt/oracle/restletxmldb/ojvm-restlet/src/main/java/com/noelios/restlet/ext/xdb/ServletCall.java:[23,32] cannot find symbol
symbol : class ChunkedInputStream
location: package com.noelios.restlet.util
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Tue Aug 18 10:54:51 EDT 2009
[INFO] Final Memory: 11M/128M
[INFO] ------------------------------------------------------------------------

Marcelo Ochoa said...

Hi Tian:
Are you using latest CVS code of Lucene Restlet integration?
I didn't check the code with latest Restlet code (trunk) it seem be an error of using Restlet's deprecated API.
I'll check the code ASAP with latest Restlet SVN versiĆ³n.
Best regards, Marcelo.

tian said...

Hi Marcelo,

Thanks for your reply. Yeah, I guess the problem is in the api version. Could you please let me know when the version is compatible I can go ahead to install the adapter on our oracle db 11 environment.

I appreciate your help and time.

Thanks again.


XT said...


It has been a while since the last post. I am still waiting for your fix of version conflict. I still can not build it up. The exception is something like:

[INFO] Compilation failure

/opt/oracle/restletxmldb/ojvm-restlet/src/main/java/com/noelios/restlet/ext/xdb/ServerServlet.java:[21,38] cannot find symbol
symbol : class ApplicationContext
location: package com.noelios.restlet.application

Could you please send me an updated document to try it out.

Thanks a lot!

Marcelo Ochoa said...

Hi XT:
If you checkout latest SVN trunk version you can compile and generate all maven's artifact which are updated to latest Restlet refactoring.
I had tested latest SVN code and compile fine, I'll update Restlet wiki entry:
with updated instruction for compiling and installing from SVN sources.
In the meantime if you checkout the SVN code going to build directory and running ant without argument will do the job.
Best regards, Marcelo.

XT said...


Thanks for your quick message. I prepared and downloaded based on the following requirement:
* JDK 1.5 (included at your ORACLE_HOME/jdk directory)
* Ant 1.7.0+
* an 11g target database, tested with
* By now Oracle Restlet Adapter is only available through SVN access or using nightly builds, checkout SVN source or download an snapshop version.
svn checkout http://restlet.tigris.org/svn/restlet/trunk restlet --username guest

If I set Java version as 1.6 above, and I run ant at build directory, I got:
[mkdir] Created dir: /opt/oracle/restletxmldb/restlet/build/temp/gae/temp/cl
[mkdir] Created dir: /opt/oracle/restletxmldb/restlet/build/temp/gae/temp/cl
[javac] Compiling 249 source files to /opt/oracle/restletxmldb/restlet/build
[javac] /opt/oracle/restletxmldb/restlet/build/temp/gae/modules/org.restlet/
src/org/restlet/engine/io/ByteUtils.java:262: illegal start of expression
[javac] public static OutputStream getStream(WritableByteChannel writabl
eChannel) {
[javac] ^
[javac] 1 error

BUILD FAILED at 4 minutes.

If I use java version 1.5.0-04 version, I got:

[javadoc] Copying file /opt/oracle/restletxmldb/restlet/build/tmpl/javadocs/stylesheet.css to file /opt/oracle/restletxmldb/restlet/build/temp/jse/temp/docs/ext/stylesheet.css...
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...
[javadoc] Generating /opt/oracle/restletxmldb/restlet/build/temp/jse/temp/docs/ext/help-doc.html...
[javadoc] 1 warning



[junit] Running org.restlet.test.RestletTestSuite
[junit] Tests run: 125, Failures: 1, Errors: 0, Time elapsed: 26.212 sec

/opt/oracle/restletxmldb/restlet/build/build.xml:203: The following error occurred while executing this line:
/opt/oracle/restletxmldb/restlet/build/build.xml:142: The following error occurred while executing this line:
/opt/oracle/restletxmldb/restlet/build/build.xml:144: The following error occurred while executing this line:
/opt/oracle/restletxmldb/restlet/build/temp/jse/build.xml:1727: Test org.restlet.test.RestletTestSuite failed
at 2 minute 41 second.

So I am really looking forward to have it pass ant build and I can use it.

Please give me some suggestions how to successfully build it.

Thanks a lot


Marcelo Ochoa said...

Hi Tian:
There is typo on that code, I have reported the issue on restlet code list.
Apply this patch to solve the compilation error:
Index: io/ByteUtils.java
--- io/ByteUtils.java (revision 5351)
+++ io/ByteUtils.java (working copy)
@@ -251,7 +251,7 @@
public static InputStream getStream(final Representation representation) {
if (Edition.CURRENT != Edition.GAE) {
- // [ifndef gae] method
+ // [ifndef gae]
if (representation == null) {
return null;

If you have other problem feel free to drop me an email at marcelo.ochoa -at- gmail
Best regards, Marcelo.

XT said...

Hi, Marcello,

Thanks so much for your reply. I appreciated your time.

After I modified the code (typo error)as you suggested and rebuild by ant, the following error generated:

[javac] Compiling 249 source files to /opt/oracle/restletxmldb/restlet/build/temp/gae/temp/classes/org.restlet
[javac] /opt/oracle/restletxmldb/restlet/build/temp/gae/modules/org.restlet/src/org/restlet/engine/io/ByteUtils.java:136: cannot find symbol
[javac] symbol : method getTaskService()
[javac] location: class org.restlet.Application
[javac] application.getTaskService().execute(new Runnable() {
[javac] ^
[javac] /opt/oracle/restletxmldb/restlet/build/temp/gae/modules/org.restlet/src/org/restlet/engine/io/ByteUtils.java:189: cannot find symbol
[javac] symbol : method getTaskService()
[javac] location: class org.restlet.Application
[javac] application.getTaskService().execute(new Runnable() {
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 2 errors

Could you give me more suggestions? Thanks a lot.