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 examples/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 JDK version 6 or higher. retsiq-simpleclient.jar must be on the classpath to compile. If using the alternative retsiq-simpleclient-nodeps.jar, the libraries found in the lib/ subdirectory must also be on the compilation classpath.
From the examples/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 ..\..\retsiq-simpleclient.jar HelloRetsWorld.java
On a UNIX variant use the following command:
javac -cp ../../retsiq-simpleclient.jar HelloRetsWorld.java
Running HelloRetsWorld
Running HelloRetsWorld will require the retsiq-simpleclient.jar (or alternatively, retsiq-simpleclient-nodeps.jar and all jars found in the lib/ subdirectory) on the runtime classpath.
From the examples/src directory where you built the example program, execute following command on Windows. This should be on one line.
java -cp .;..\..\retsiq-simpleclient.jar HelloRetsWorld
On a UNIX variant use the following command:
java -cp .:../../retsiq-simpleclient.jar HelloRetsWorld