01 package com.bigllc.retsiq.examples;
02
03 import java.net.MalformedURLException;
04
05 import com.bigllc.retsiq.simpleclient.RETSClientException;
06 import com.bigllc.retsiq.simpleclient.RETSConnection;
07 import com.bigllc.retsiq.simpleclient.RETSUserSession;
08
09 /**
10 * Example to demonstrate how to login and logout of a RETS server.
11 *
12 * @author Marc G. Smith
13 */
14 public class CreateSession
15 {
16 public static void main(String[] args) throws MalformedURLException
17 {
18 String loginurl = "http://rets.server.com/rets/login";
19 String username = "username";
20 String password = "password";
21
22 // Create the connection class
23 RETSConnection connection = new RETSConnection(loginurl);
24 RETSUserSession session = null;
25
26 try {
27 // Authenticate the user and get session
28 session = connection.getSession(username, password);
29 System.out.println("Session ID: " + session.getSessionId());
30 System.out.println("Member Name: " + session.getMemberName());
31 System.out.println("Agent Code: " + session.getAgentCode());
32 System.out.println("User ID: " + session.getUserId());
33 System.out.println("Broker Key: " + session.getBrokerKey());
34 }
35 catch(RETSClientException e) {
36 System.err.println(e.getMessage());
37 }
38 finally {
39 if(session != null) {
40 try {
41 session.logout();
42 }
43 catch(RETSClientException e) {
44 System.err.println(e.getMessage());
45 }
46 }
47 }
48 }
49 }
|