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.