Connecting
Connecting to a server requires the instantiation and configuration of a RETSConnection object. The RETSConnection object has three constructors. All require a URL to the target RETS server's login transaction.
/**
* Construct a connection factory to RETS server.
*/
public RETSConnection(String url)
/**
* Construct a connection factory to RETS server with a custom user agent
* string.
*/
public RETSConnection(String url, String userAgent);
/**
* Construct a connection factory to RETS server that requires user agent
* authentication.
*/
public RETSConnection(String url, String userAgent, String userAgentPassword);
The second form of the constructor allows your application to send a custom User Agent. The User Agent should be formatted as follows USERAGENT/VERSION, e.g. RETSIQ/1.0.
Some servers require User Agents to authenticate as well as actual users. This is possible through the the third constructor.Simply enter the User Agent and Password combination agreed with your MLS.
Once the RETSConnection has been created, Users can be authenticated. Successful authentication will create a RETSUserSession. A RETSUserSession maintains a login session and provides access to the target RETS server in a thread safe manner for a single session.
String loginurl = "http://rets.server.com/rets/login";
String username = "username";
String password = "password";
// Create the connection class
RETSConnection connection = new RETSConnection(loginurl);
// Authenticate the user and get session
RETSUserSession session = connection.getSession(username, password);
// Logout from the session
session.logout();
Once logged out the session should be discarded.
Auto-Login
The RETSConnection class provides a property for allowing auto-login. By default this is off. By turning it on sessions that expire will automatically be renewed.
It may also be used in some cases were servers have issues with authentication such as sending authentication requests before every transaction. Turning auto-login on will allow your application to work seemlessly with the target RETS server.
String loginurl = "http://rets.server.com/rets/login";
// Create the connection class
RETSConnection connection = new RETSConnection(loginurl);
// Turn auto-login on
connection.setAutoLogin(true);
Example
The example below demonstrates how to login and logout of a RETS server using the RETS IQ RETS Library.