1 Reply Latest reply: Jul 23, 2013 3:19 PM by NeerajGirolkar RSS

    RESTful Services through Java Program


      We are trying to access RESTful Services exposed by Oracle database cloud through our Java code, with authentication enabled for a particular user.


      Till now, we have completed below steps:


      1) We have a working account with Oracle database cloud (Username – xxx.xxx)

      2) We log in using the credentials for above account, and navigate to Oracle Apex ? SQL Workshop ? RESTful Services

      3) We create a new “RESTful Service Module” by filling out the details as below:

           Name:                                  SampleTest 

           URI Prefix:                            test

           URI Template:                       /getallemp

           Pagination Size:                    25 (kept to default)

           Required Privilege:                 TestGroupPrivilege

           Resource Handler Details:

                      Method:              GET

                      Source Type:      Query

                      Format:               JSON

                      Source:               select * from emp


      After creating the above module and testing it, it works fine and the data is retrieved in JSON successfully.


      The resulting URL for above RESTful Service Module is: https://<HOST_URL>/apex/test/getallemp


      Note that “TestGroupPrivilege” is a privilege assigned to the user group “RESTful Services” and the user “xxx.xxx” is a member of “RESTful Services” user group.


      4) We are unable to call the RESTful services from Java program. We are passing username and password in request header as basic authentication. But, we are getting: Error 500--Internal Server Error


      5) If we change the “Required Privilege” to default i.e. no privileges present on the module, we can get the response through Java code and everything works perfectly fine.



      Please suggest us in: How to access RESTful Services through Java code by passing user credentials in HTTP header for authentication. Also let us know if we have to do any settings through Apex, in case we are missing any.

        • 1. Re: RESTful Services through Java Program

          - When we are logging in to Oracle cloud on browser and execute the Oracle cloud RESTful service in another tab of same browser, we are able to get the result. But when executed the same RESTful service from a different browser or java program we get internal server error.

          - After investigation, we found that when user logs in to oracle database cloud, a cookie is set in browser with name s “OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443” and value as some random token. This cookie is passed in the subsequent requests to the RESTful Service calls when using same browser and as a result, we are able to get the results

          - In the Java program, we copied the same cookie with random token in the HTTP Request header and we got the proper response from REST APIs.

          - It seems that this cookie is created by an Oracle Middleware tool/server called as OAM – Oracle Accounts Manager, which sends the authentication token after successful authentication and creates the cookie.

          - We found that the cookie that OAM creates on authentication is exactly in the same format i.e. ‘OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443’. So, we are guessing that Oracle cloud uses OAM for authentication. Please refer to following link for same : http://docs.oracle.com/cd/E14571_01/doc.1111/e15478/sso.htm

          Can anyone please suggest:

          1.     How to provide authentication to Oracle Cloud REST APIs from java program?

          2.     How to pass the username and password in Java code to OAM (or how to communicate with OAM using Java) so that we can receive the unique token from OAM. We can use the token in the further requests? 3.     Also in Oracle cloud white papers , it is mentioned that they support OAuth2.0. But we didn’t find any URLs for same. Can anyone please confirm?


          ~ Neeraj Girolkar