Hello RETS World
Below is a quick Java program that connects to a RETS server, logs in and then logs out. Create a file in the src directory of the distribution called HelloRetsWorld.java. Edit the file and enter the code below making sure to replace loginurl, username and password string values with a valid URL and RETS credentials.
import java.net.MalformedURLException;
import com.bigllc.retsiq.simpleclient.RETSClientException;
import com.bigllc.retsiq.simpleclient.RETSConnection;
import com.bigllc.retsiq.simpleclient.RETSUserSession;
public class HelloRetsWorld
{
public static void main(String[] args) throws MalformedURLException
{
String loginurl = "http://rets.server.com/rets/login";
String username = "username";
String password = "password";
// Create the connection class
RETSConnection connection = new RETSConnection(loginurl);
RETSUserSession session = null;
try {
// Authenticate the user and get session
session = connection.getSession(username, password);
System.out.println("Session ID: " + session.getSessionId());
System.out.println("Member Name: " + session.getMemberName());
System.out.println("Broker Key: " + session.getBrokerKey());
}
catch(RETSClientException e) {
System.err.println(e.getMessage());
}
finally {
if(session != null) {
try {
session.logout();
}
catch(RETSClientException e) {
System.err.println(e.getMessage());
}
}
}
}
}
Compiling
Compiling your code requires the following JDK version 5 or higher. It also requires the following jars in the classpath for the compiler:
- retsiq-rets-metadata.jar
- retsiq-rets-simpleclient.jar
From the src directory compile the code with the following command on Windows. This should be on one line. The line breaks below are just for presentation purposes.
javac -cp ..\lib\retsiq-rets-metadata.jar;..\lib\retsiq-rets-simpleclient.jar HelloRetsWorld.java
On a UNIX variant use the following command:
javac -cp ../lib/retsiq-rets-metadata.jar:../lib/retsiq-rets-simpleclient.jar HelloRetsWorld.java
Running HelloRetsWorld
Running HelloRetsWorld will require the following jars in the classpath:
- commons-codec-1.3.jar
- commons-httpclient-3.0-rc4.jar
- commons-logging.jar
- log4j-1.2.9.jar
- retsiq-rets-api.jar
- retsiq-rets-client.jar
- retsiq-rets-metadata.jar
- retsiq-rets-simpleclient.jar
From the src directory execute following command on Windows. This should be on one line. The line breaks below are just for presentation purposes.
java -cp .;..\lib\commons-codec-1.3.jar;..\lib\commons-httpclient-3.0-rc4.jar;..\lib\commons-logging.jar;
..\lib\log4j-1.2.9.jar;..\lib\retsiq-rets-api.jar;..\lib\retsiq-rets-client.jar;
..\lib\retsiq-rets-metadata.jar;..\lib\retsiq-rets-simpleclient.jar HelloRetsWorld
On a UNIX variant use the following command:
java -cp .:../lib/commons-codec-1.3.jar:../lib/commons-httpclient-3.0-rc4.jar:../lib/commons-logging.jar:
../lib/log4j-1.2.9.jar:../lib/retsiq-rets-api.jar:../lib/retsiq-rets-client.jar:
../lib/retsiq-rets-metadata.jar:../lib/retsiq-rets-simpleclient.jar HelloRetsWorld