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.

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(new DefaultHttpClient()),
      new AciServerDetails(host, port)
);

For more control over how the Apache HttpClient is configured, the API contains a factory class, HttpClientFactory, 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 example shows how to configure an AciServer instance when you are using a dependency injection container like Spring, you can configure an AciServer instance:

<beans xmlns="...">

  <context:property-placeholder location="classpath:idol.properties" />

  <bean id="httpClientFactory" 
      class="com.autonomy.aci.client.transport.impl.HttpClientFactory"
      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>

Alternatively, if you are using Spring Java Configuration, you can use something similar to the following example:

@Configuration
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private Environment env;
    
    @Bean
    public ResourceBundle idolProperties() {
        return ResourceBundle.getBundle("/idol");
    }

    @Bean
    public HttpClient httpClient() {
        final HttpClientFactory factory = new HttpClientFactory();
        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);
    }
}