Monday May 11, 2015

My First Oracle Documents REST API Sample

Here is my first sample. It is very simple. It calls the User resource to get a list of users that match a search. The documentation says that it uses a fuzzy search on user names and email addresses to determine the list of users to return. I found that if I put my first name or last name in the search I would get a list of all the other Kevins or Smiths defined in our Oracle Documents instance. I tried searching on email and received the same result as if I had used Kevin.

Here is the entire java program. It sends the request and just prints the result to standard output.

import org.glassfish.jersey.client.*;
import org.glassfish.jersey.client.authentication.*;
import javax.ws.rs.client.*;

public class docsSample1 {

  static String m_user = "USER";
  static String m_pass = "PASS";
  static String m_docs_base_url = "https://DOCSURL/documents/api/1.1";

  public static void main(String[] args) {
    try {

      ClientConfig clientConfig = new ClientConfig();

      HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(m_user, m_pass);
      clientConfig.register(feature) ;

      Client client = ClientBuilder.newClient(clientConfig);

      WebTarget target = client.target(m_docs_base_url + "/users/items?info=smith");

      Invocation.Builder builder = target.request("text/plain");
      Invocation invocation = builder.buildGet();

      String responseData = invocation.invoke(String.class);

      System.out.println(responseData);

    } catch (Exception e) {
      e.printStackTrace();
    }

  }
}

I will go through some of important parts of the code.

To pass the authentication information you need to add a HttpAuthenticationFeature to your Jersey client. Oracle Documents only support Basic Authentication. These two lines of code adds the basic authentication information to the client.

HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(m_user, m_pass);
clientConfig.register(feature);

The URL that you use to submit the request will be based on your Oracle Documents instance URL which contains your service and identity domain.

static String m_docs_base_url = "https://DOCSURL/documents/api/1.1";

In this sample I am passing all the information to invoke the user resource in the URL.

WebTarget target = client.target(m_docs_base_url + "/users/items?info=smith");

You can also pass in the resource and parameters uisng other methods. I will cover those in later samples.

I use Invocation.Builder to set up for the call. In this get we are doing a GET.

Invocation.Builder builder = target.request("text/plain");
Invocation invocation = builder.buildGet();

I then submit the request and get the results back as a string.

String responseData = invocation.invoke(String.class);

Since I have not specified a result format the result will be returned using the default JSON format.

{
"count": "10",
"errorCode": "0",
"items": [
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "Kevin Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
},
{
"type": "user",
"id": "XXX",
"displayName": "XXX Smith"
}
]
}

I have replaced all the actual first names and ids with XXX. The id will be a 36 long character string representing the users unique ID. You can use this ID is you are going to share a folder with a user.

Sunday May 10, 2015

Oracle Documents REST API

Over the next few days and weeks I am going to be working on some sample code for integrating with Oracle Documents using the REST API. I will post the samples as I create them.

For details on the Oracle Documents REST API, see the Developing for Oracle Documents Cloud Service Book.

I will be using the Jersey framework in my code. For more details on the Jersey framework see https://jersey.java.net/. You can find the documentation on the Jersey framework and download the Jersey jar files.

For other examples of integrating with Oracle Documents see these pages.

Calling Oracle Documents Cloud Service REST APIs from WebCenter Content Custom Components by Peter Flies.

JDeveloper REST Connection for Oracle Documents Cloud by Justin Paul.

Tuesday Sep 25, 2012

A Generic RIDC Test Program

Many times I have found it useful to use a java program that communicates with WebCenter Content (WCC) using RIDC for testing. I might not have access to the web GUI or need to test a service running as a specific user. In the past I had created a number of "one off" programs that submitted specific services, e.g GET_SEARCH_RESULTS, DOCINFO, etc. Recently I decided to create a generic RIDC test program that could submit any service with the desired parameters based on a configuration file.

The programs gets the following information from the configuration file:

  • WCC connection information (host, port)
  • User to use to run service
  • Service to run
  • Any parameters for the service

The program will make a connection to the WCC server, send the service request, and print the results of the service call using the getResponseAsString() method.

Here is a sample configuration file:

ridc.host=localhost
ridc.port=4444
ridc.user=sysadmin
ridc.idcservice=GET_SEARCH_RESULTS
idcservice.QueryText=dDocType <matches> `Document`
idcservice.SortField=dDocName
idcservice.SortDesc=ASC

There is a readme file included in the zip with instructions for how to configure and run the program. The program takes one command line argument, the configuration file name. The configuration file name is optional and defaults to config.properties.

If you have any suggestions for improvements let me know. Right now it only submits a single service call each time you run it. One enhancement I have already thought about would be to allow you to specify multiple services to tun in the configuration file. You can do that with the current program by having multiple configuration files and running the program multiple times, each with a different configuration file.

You can download the program here.

About

Kevin Smith is a Technical Director in Oracle Consulting's WebCenter practice. He has been working with content management products since 2004 when he joined Stellent.

Search

Archives
« May 2015
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
12
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      
Today