-
Notifications
You must be signed in to change notification settings - Fork 2
infinitum.cfg.xml
The infinitum.cfg.xml file provides configuration settings for Infinitum. For information on how to set it up, see the Infinitum Core wiki page on it. This page provides information on how to configure it for use with the ORM module.
Infinitum ORM has a dependency on Infinitum Core and Infinitum Web.
The ORM makes use of some properties defined in the application node. One such property that is important to note is the mode setting, which is used to identify how object-relational mapping is done. Domain objects require some metadata for datastore mapping, which can come in the form of annotations or XML map files. By default, annotations are assumed.
<application>
<property name="mode">annotations</property> <!-- [annotations | xml] -->
</application>In order to make use of Infinitum's ORM, an application's domain model (i.e. entity classes) must be declared within infinitum.cfg.xml. An entity class is declared simply by identifying its package-qualified name.
<model resource="com.foo.bar.domain.Foo" /><domain>
<model resource="com.foo.bar.domain.Foo" />
<model resource="com.foo.bar.domain.Bar" />
<model resource="com.foo.bar.domain.Baz" />
</domain>If SQLite is being used as a datastore, a database name and version number must be provided. Optionally, a property indicating if the framework should create the database schema automatically and a property for indicating if autocommit is enabled can be provided as well. Both of these are enabled by default.
<sqlite>
<property name="dbName">myDatabase</property>
<property name="dbVersion">1</property>
<property name="generateSchema">true</property> <!-- [true | false] -->
<property name="autocommit">false</property> <!-- [true | false] -->
</sqlite>If RestfulSession is being utilized, it must be configured, at least minimally, in infinitum.cfg.xml. The only required property is the host, which designates the URL of the web service. Optional properties include connection timeout, response timeout, message type, and authentication.
Connection and response timeouts indicate the time, in milliseconds, the client will wait for a connection or response, respectively, before failing. If not specified, no timeout is used.
Message type indicates the message format to use, such as JSON or XML. JSON is used as a default if one is not specified.
If a web service uses some type of authentication, an AuthenticationStrategy can be registered. For example, if using a shared secret, a "token" strategy can be declared, indicating the name of the shared secret and the token itself (a token generator can also be used if an changing token is desirable).
AuthenticationStrategies sign an HTTP request with the information the web service needs for authorization. This is typically done by either appending data to the request URI's query string or by including the information as a request header.
<rest>
<property name="host">http://localhost/mywebservice</property>
<property name="connectionTimeout">5000</property>
<property name="responseTimeout">5000</property>
<authentication strategy="token" header="true">
<property name="tokenName">token</property>
<property name="token">52b353fb27267973cebb5e8566e0415d</property>
</authentication>
</rest>The getSession method in InfinitumOrmContext will attempt to resolve a Session implementation based on the provided message type. However, alternative implementations can be used by providing a bean, which will then be injected into the InfinitumOrmContext. In a similar manner, alternative AuthenticationStrategy implementations can be used by providing a bean also. Both of these notions are illustrated in the example below.
<rest ref="restSession">
<property name="host">http://localhost/mywebservice</property>
<property name="connectionTimeout">5000</property>
<property name="responseTimeout">5000</property>
<authentication ref="customAuthenticator" />
</rest>The bean restSession will be used as the RestfulSession implementation, while the customAuthenticator bean will be used as the Session's AuthenticationStrategy. These beans would be defined as follows:
<bean id="restSession"
class="com.foo.bar.rest.MyRestfulSession" />
<bean id="customAuthenticator"
class="com.foo.bar.rest.MyAuthenticator" />MyRestfulCSession must extend the RestfulSession abstract class, and MyAuthenticator must implement the AuthenticationStrategy interface.
An example of an infinitum.cfg.xml file, configured for using both REST and SQLite, is seen below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE infinitum-configuration PUBLIC
"-//Infinitum/Infinitum Configuration DTD 1.0//EN"
"http://infinitumframework.com/dtd/infinitum-configuration-1.0.dtd">
<infinitum-configuration>
<application>
<property name="debug">true</property>
<property name="mode">annotations</property> <!-- [annotations | xml] -->
</application>
<domain>
<model resource="com.foo.bar.domain.Foo" />
<model resource="com.foo.bar.domain.Bar" />
<model resource="com.foo.bar.domain.Baz" />
</domain>
<sqlite>
<property name="dbName">myDatabase</property>
<property name="dbVersion">1</property>
<property name="generateSchema">true</property> <!-- [true | false] -->
<property name="autocommit">false</property> <!-- [true | false] -->
</sqlite>
<rest ref="restSession">
<property name="host">http://localhost/mywebservice</property>
<property name="connectionTimeout">5000</property>
<property name="responseTimeout">5000</property>
<authentication ref="authenticator" />
</rest>
<beans>
<component-scan base-package="com.foo.bar" />
<bean id="restSession" class="com.foo.bar.rest.MyRestfulSession" />
<bean id="authenticator" class="com.foo.bar.rest.MyAuthenticator" />
</beans>
</infinitum-configuration>