com.idilia.services.kb.Client Maven / Gradle / Ivy
/**
* Copyright (c) 2011 Idilia Inc, All rights reserved.
* Description:
* This file implements a client for communicating with Idilia's
* document server for sense analysis.
*
* Both the queries and responses use multipart messaging.
*
* This is a singleton object that can use up to "maxConnectionsPerRoute"
* for each destination Url. This parameter can be set prior to calling
* getInstance().
*/
package com.idilia.services.kb;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import com.idilia.services.base.IdiliaClientException;
import com.idilia.services.base.IdiliaCredentials;
import com.idilia.services.base.SyncClientBase;
/**
* Client for accessing the servers that return annotated document.
*
* This is a synchronous client that blocks until the server returns a
* response. Only one instance is needed and is obtained through a singleton
* interface.
*
* Internally the class uses an HttpClient that supports multiple simultaneous operations.
* The number of requests is controlled using member "maxConnectionsPerRoute".
*/
public class Client extends SyncClientBase {
/**
* Constructs a client for requesting text services provided at the default service URL.
*
* This is a lightweight object. Allocated instances share an underlying HTTP client.
* Multithread safe.
*
* @param creds Idilia API credentials for a project
*/
public Client(IdiliaCredentials creds) {
this(creds, defaultApiUrl);
}
/**
* Constructs a client for requesting text services provided at the given service URL.
*
* This is a lightweight object. Allocated instances share an underlying HTTP client.
* Multithread safe.
*
* @param creds Idilia API credentials for a project
* @param url URL to reach the API. Normally http://api.idilia.com
*/
public Client(IdiliaCredentials creds, URL url) {
super(creds, url);
}
/**
* Sends a request to the kb server.
*
* @param req Request message. One concrete implementation of {@link QueryRequest}
* @return {@link QueryResponse}
* @throws IdiliaClientException when the request is not successful for any reason
*/
public QueryResponse