Programmer : Mashup Programmer : Using the Mashup API : Using the Mashup API Java client
 
Using the Mashup API Java client
 
Where is the Mashup API endpoint?
How to configure a proxy
How to send security tokens to a secured Search API
How to configure failover
How to configure the max number of concurrent connections to the distant host
How to configure the stale connection check
How to configure a socket read timeout
You can access the Mashup API Java client in <INSTALLDIR>/sdk/java-clients
You interact with the Mashup API using the AccessClient java library (access-core.jar). The AccessClient library is a simple wrapper around the HTTP/Atom protocol. It delivers results in two different formats:
ResultFeed Object - using the getResultFeed(AccessRequest request) method
Atom XML as an InputStream - using the getResultStream(AccessRequest request) method
Note: The AccessClient object is thread safe. You should use only one instance of the AccessClient for your whole program. It will ensure that the HTTP connection is alive, to maintain request queueing without establishing useless connections to the service.
AccessClient example
ServerInfos serverInfos = new ServerInfos("http://host:10010/access");
AccessClient client = AccessClientFactory.createAccessClient(new ServerInfos[] {
serverInfos });
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
Note: SERVICE_URI is the Mashup API endpoint where the AccessClient should make the requests.
Where is the Mashup API endpoint?
For the default application: http://<HOSTNAME>:<BASEPORT+10>/access
For every other applications: http://<HOSTNAME>:<BASEPORT+10>/access.<applicationId>
How to configure a proxy
ServerInfos serverInfos = new ServerInfos("http://HOST:PORT/access");
serverInfos.setProxyHost("host");
serverInfos.setProxyPort(8080);
serverInfos.setProxyLogin("login");
serverInfos.setProxyPassword("password");
AccessClient accessClient = AccessClientFactory.createAccessClient(new ServerInfos[] {
serverInfos });
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
How to send security tokens to a secured Search API
Requirement: To send security tokens, you must first enable security on your Mashup UI pages. For more information, see "Adding Security to Your Application" in the Exalead CloudView Mashup Builder User's Guide.
You can then list security tokens as follows:
ServerInfos serverInfos = new ServerInfos("http://HOST:PORT/access");
AccessClient client = AccessClientFactory.createAccessClient(new ServerInfos[]
{serverInfos });
List<String> tokens = new ArrayList<String>(); tokens.add("Everybody");
AccessRequest request = new AccessRequest();
request.addParameters(AccessParameter.SECURITY, tokens);
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
How to configure failover
To enable failover, you must specify the isAlive path. Note that:
The higher the power the higher the request priority.
If they have the same power, requests will be uniformly distributed between the hosts.
ServerInfos host1 = new ServerInfos("http://HOST1:PORT/access");
host1.setIsAlivePath("/admin/isAlive");
host1.setPower(1);
ServerInfos host2 = new ServerInfos("http://HOST2:PORT/access");
host2.setIsAlivePath("/admin/isAlive");
host2.setPower(10);
AccessClient accessClient = AccessClientFactory.createAccessClient(new ServerInfos[] {
host1, host2 });
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
How to configure the max number of concurrent connections to the distant host
ServerInfos serverInfos = new ServerInfos("http://HOST:PORT/access");
Properties options = new Properties();
options.put("http.max_number_of_connections_per_server", 10);
AccessClient accessClient = AccessClientFactory.createAccessClient(new ServerInfos[] {
serverInfos }, options);
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
How to configure the stale connection check
See Apache documentation: http://hc.apache.org/httpclient-3.x/performance.html#Stale_connection_check
ServerInfos serverInfos = new ServerInfos("http://HOST:PORT/access");
Properties options = new Properties();
options.put("http.commons-httpclient.stale_checking_enabled", "true");
AccessClient accessClient = AccessClientFactory.createAccessClient(new ServerInfos[] {
serverInfos }, options);
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);
How to configure a socket read timeout
The following code snippet shows how to configure a socket read timeout to 5000 milliseconds (5 seconds). If set to 0, timeout is disabled.
ServerInfos serverInfos = new ServerInfos("http://HOST:PORT/access");
Properties options = new Properties();
options.put("http.socket.timeout", 5000); // 5 seconds timeout
AccessClient accessClient = AccessClientFactory.createAccessClient(new ServerInfos[] {
serverInfos }, options);
AccessRequest request = new AccessRequest();
request.setPage("search");
request.addParameter("q", "disney");
ResultFeed result = client.getResultFeed(request);