Create an AciService
All communication with ACI Servers goes through an implementation of the AciService
interface. To allow for the usage of different HTTP clients, the default implementation of the AciService
interface requires an implementation of the AciHttpClient
interface. The default implementation of the AciHttpClient
interface uses the Apache HTTP Components HttpClient
, which is included in the distribution.
NOTE: OpenText recommends that you use version 5 of Apache HTTP Components.
Apache HTTP Components version 4 is supported, but deprecated, and will be removed in a future release.
When creating an AciService
, you can either specify connection details for a particular server and tie the implementation to that server, or you can specify connection details every time you send an action. Connection details that you specify on a per action basis override those set on the default AciService
implementation.
The following example shows the simplest way to create an AciService
implementation:
// Create an AciService...
final AciService aciService = new AciServiceImpl(
new AciHttpClientImpl(HttpClients.createDefault()),
new AciServerDetails(host, port)
);
For more control over how the Apache HttpClient
is configured, the API contains a factory class, HttpClient5Factory
, for creating and configuring the HttpClient
. For information about how to configure and use this class, refer to the JavaDocs.
The only way to switch between GET and POST HTTP methods, is to set a flag on the AciHttpClientImpl
class. The way that this class is normally created means that an AciService
implementation is normally set to either send everything as GET or everything as POST.
The AciServerDetails
class allows you to set the HTTP protocol (HTTP or HTTPS), as well as the host, port, character set and any encryption details. It supports only ACI servers secured via the BTEA algorithm. OpenText recommends that you use SSL by HTTPS.
The following examples show how to configure an AciServer
instance when you are using a dependency injection container like Spring. The following example uses Spring Java Configuration:
@Configuration
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
@Autowired
private Environment env;
@Bean
public ResourceBundle idolProperties() {
return ResourceBundle.getBundle("/idol");
}
@Bean
public HttpClient httpClient() {
final HttpClient5Factory factory = new HttpClient5Factory();
factory.setMaxTotalConnections(toInt(env.getProperty(
"aci.maxTotalConnections"), 30));
factory.setMaxConnectionsPerRoute(toInt(env.getProperty(
"aci.maxConnectionsPerRoute"), 15));
factory.setConnectionTimeout(toInt(env.getProperty(
"aci.connectionTimeout"), 10000));
factory.setLinger(toInt(env.getProperty("aci.linger"), -1));
factory.setSocketBufferSize(toInt(env.getProperty(
"aci.socketBufferSize"), 8192));
factory.setSoTimeout(toInt(env.getProperty("aci.soTimeout"), 30000));
factory.setStaleCheckingEnabled(toBoolean(env.getProperty(
"aci.staleChecking", "true")));
factory.setTcpNoDelay(toBoolean(env.getProperty(
"aci.tcpNoDelay", "true")));
factory.setUseCompression(toBoolean(env.getProperty(
"aci.useCompression", "false")));
return factory.createInstance();
}
@Bean
public AciService aciService() {
final ResourceBundle idolProperties = idolProperties();
final AciServerDetails serverDetails = new AciServerDetails();
serverDetails.setHost(idolProperties.getString("idol.host"));
serverDetails.setPort(NumberUtils.toInt(
idolProperties.getString("idol.aciPort"), 9030));
return new AciServiceImpl(
new AciHttpClientImpl(httpClient()), serverDetails);
}
}
Alternatively, you can use Spring XML configuration:
<beans xmlns="...">
<context:property-placeholder location="classpath:idol.properties" />
<bean id="httpClientFactory"
class="com.autonomy.aci.client.transport.impl.HttpClient5Factory"
p:maxConnectionsPerRoute="20"
p:maxTotalConnections="120"
p:staleCheckingEnabled="true" />
<bean id="httpClient" factory-bean="httpClientFactory"
factory-method="createInstance" />
<bean id="aciService"
class="com.autonomy.aci.client.services.impl.AciServiceImpl">
<constructor-arg>
<bean class="com.autonomy.aci.client.transport.impl.AciHttpClientImpl"
p:httpClient-ref="httpClient" />
</constructor-arg>
<constructor-arg>
<bean class="com.autonomy.aci.client.transport.AciServerDetails"
p:host="${idol.host}"
p:port="${idol.aciPort}" />
</constructor-arg>
</bean>
</beans>