Introduction
With Elixir Repertoire Server 7.x onwards, all resources ( *.rml, *.ds, *.job ) are accessible via the REST API. All resources, at first attempt, will be prompted to enter a valid username and password. This ensure that all resources are secure and not easily accessible from the web.
REST Calls in Repertoire Server
Q: How can I call a resource ( i.e. rml/ds/pml ) directly to render a report / load data and show a dashboard ?
A: In order to issue a direct REST Calls from Java, you will need to know how to create a HTTP Request to be sent to Repertoire Server
Creating HTTP Request in Java
A suitable package to use in Java for easy creation of a Http Request is
See http://hc.apache.org/httpclient-3.x/index.html
Once you have make available the necessary packages in Httpclient, you will be able to construct Http Requests.
For example,
…
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url+“login.html”);
post.addParameter(“username”,username);
post.addParameter(“password”,password);
int ret = client.executeMethod(post);
if (ret==200 || ret==302)
…
Refer to HttpClient Package official documentation on furthur details.
Adding Credentials on Http Requests
Since all resources within the Repertoire Server are protected, a set of credentials needs to be sent together with the Http Request. This can be done by inserting the credentials directly into the Http Header Information.
...
HttpClient client = new HttpClient();
Credentials defaultCreds = new UsernamePasswordCredentials("admin","sa");
client.getState().setCredentials(new AuthScope(host,port,AuthScope.ANY_REALM), defaultCreds);
HttpClientParams params = client.getParams();
params.setCredentialCharset(CredentialCharset);
params.setAuthenticationPreemptive(true);
...
In this approach, a single Http REST Call will be able to gain access to the Repertoire Server Resources to render a report / load data and load a dashboard.
A sample java source file is attached to illustrate the above approach.
Please rename the file to .java
RestGenerateData.txt (2.1 KB)