diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/KeyValueResponse.java b/rets-io-client/src/main/java/com/ossez/usreio/client/KeyValueResponse.java
index 2ea6bd2..8b96fbe 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/KeyValueResponse.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/KeyValueResponse.java
@@ -1,5 +1,6 @@
package com.ossez.usreio.client;
+import com.ossez.usreio.common.rets.RetsVersion;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/LoginResponse.java b/rets-io-client/src/main/java/com/ossez/usreio/client/LoginResponse.java
index 4002463..a6a558e 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/LoginResponse.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/LoginResponse.java
@@ -1,5 +1,6 @@
package com.ossez.usreio.client;
+import com.ossez.usreio.common.rets.RetsVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.logging.Log;
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsHttpRequest.java b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsHttpRequest.java
index f954583..e1feae7 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsHttpRequest.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsHttpRequest.java
@@ -8,6 +8,7 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.common.util.CaseInsensitiveTreeMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsSession.java b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsSession.java
index 6e91e1e..1406cdd 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsSession.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsSession.java
@@ -2,6 +2,7 @@ package com.ossez.usreio.client;
import java.util.Map;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.tests.common.metadata.Metadata;
import com.ossez.usreio.tests.common.metadata.MetadataException;
import org.apache.commons.logging.Log;
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsTransport.java b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsTransport.java
index dbe9775..92d32d2 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsTransport.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/RetsTransport.java
@@ -5,6 +5,7 @@ import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.tests.common.metadata.JDomCompactBuilder;
import com.ossez.usreio.tests.common.metadata.JDomStandardBuilder;
import com.ossez.usreio.tests.common.metadata.Metadata;
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/SearchRequest.java b/rets-io-client/src/main/java/com/ossez/usreio/client/SearchRequest.java
index 9cbc3fa..4b14e44 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/SearchRequest.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/SearchRequest.java
@@ -1,5 +1,7 @@
package com.ossez.usreio.client;
+import com.ossez.usreio.common.rets.RetsVersion;
+
/**
*
* The search request sent from search() in RetsSession
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/VersionInsensitiveRequest.java b/rets-io-client/src/main/java/com/ossez/usreio/client/VersionInsensitiveRequest.java
index 3b72ee6..cb35fa9 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/VersionInsensitiveRequest.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/VersionInsensitiveRequest.java
@@ -1,5 +1,7 @@
package com.ossez.usreio.client;
+import com.ossez.usreio.common.rets.RetsVersion;
+
public abstract class VersionInsensitiveRequest extends RetsHttpRequest {
/**
* Abstract class of subclasses where the Version of RETS is not needed (Password Request, Login Request, etc.)
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/retsapi/RETSConnection.java b/rets-io-client/src/main/java/com/ossez/usreio/client/retsapi/RETSConnection.java
index 793e3ea..98c8451 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/retsapi/RETSConnection.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/client/retsapi/RETSConnection.java
@@ -7,7 +7,7 @@ package com.ossez.usreio.client.retsapi;
//import com.aftexsw.util.bzip.CBZip2InputStream;
-import com.ossez.usreio.common.util.RETSConfigurator;
+import com.ossez.usreio.common.rets.RetsConfigurator;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -32,7 +32,7 @@ public class RETSConnection extends java.lang.Object {
private final static Logger logger = LoggerFactory.getLogger(RETSConnection.class);
static {
- RETSConfigurator.configure();
+ RetsConfigurator.configure();
}
//Key value pairs for request header.
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/util/SessionUtils.java b/rets-io-client/src/main/java/com/ossez/usreio/util/SessionUtils.java
index 2305a3f..67afcb9 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/util/SessionUtils.java
+++ b/rets-io-client/src/main/java/com/ossez/usreio/util/SessionUtils.java
@@ -1,6 +1,8 @@
package com.ossez.usreio.util;
import com.ossez.usreio.client.*;
+import com.ossez.usreio.common.rets.RetsConfigurator;
+import com.ossez.usreio.common.rets.RetsVersion;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -19,6 +21,44 @@ public final class SessionUtils {
}
+ /**
+ * @param retsConfigurator
+ * @return
+ * @throws RetsException
+ */
+ public static RetsSession retsLogin(RetsConfigurator retsConfigurator) throws RetsException {
+ logger.debug("RETS Session Login URL: [{}]", retsConfigurator.getServerUrl());
+
+ LoginResponse loginResponse = new LoginResponse();
+
+ //Create a RetsHttpClient (other constructors provide configuration i.e. timeout, gzip capability)
+ RetsHttpClient httpClient = new CommonsHttpClient();
+
+ // SET RETS VERSION
+ if (ObjectUtils.isEmpty(retsConfigurator.getRetsVersion()))
+ retsConfigurator.setRetsVersion(RetsVersion.DEFAULT);
+
+ //Create a RetesSession with RetsHttpClient
+ RetsSession session = new RetsSession(retsConfigurator.getServerUrl(), httpClient, retsConfigurator.getRetsVersion());
+
+ //Set method as GET or POST
+ session.setMethod("POST");
+ try {
+ //Login
+ loginResponse = session.login(retsConfigurator.getServerUsername(), retsConfigurator.getServerPassword());
+ } catch (RetsException ex) {
+ throw ex;
+ }
+
+ // SESSION NULL CHECK
+ if (!(!ObjectUtils.isEmpty(session) && StringUtils.isNotEmpty(loginResponse.getSessionId()))) {
+ session = null;
+ }
+
+ logger.info("Session ID :[{}]", loginResponse.getSessionId());
+ return session;
+ }
+
/**
* Login to Server and return session Object
*
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LoginResponseTest.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LoginResponseTest.java
index 7cb0092..0b945de 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LoginResponseTest.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LoginResponseTest.java
@@ -4,7 +4,7 @@ package com.ossez.usreio.tests.client;
import com.ossez.usreio.client.CapabilityUrls;
import com.ossez.usreio.client.LoginResponse;
import com.ossez.usreio.client.RetsException;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
import org.junit.Test;
public class LoginResponseTest extends RetsTestCase {
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LogoutResponseTest.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LogoutResponseTest.java
index 24860e7..34c9234 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LogoutResponseTest.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/LogoutResponseTest.java
@@ -2,7 +2,7 @@ package com.ossez.usreio.tests.client;
import com.ossez.usreio.client.LogoutResponse;
import com.ossez.usreio.client.RetsException;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
public class LogoutResponseTest extends RetsTestCase {
/*
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectExample.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectExample.java
index b3aa08c..05890fd 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectExample.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectExample.java
@@ -15,7 +15,7 @@ import com.ossez.usreio.client.GetObjectRequest;
import com.ossez.usreio.client.RetsException;
import com.ossez.usreio.client.RetsHttpClient;
import com.ossez.usreio.client.RetsSession;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.client.SingleObjectResponse;
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectURLExample.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectURLExample.java
index 5c1739f..59449e5 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectURLExample.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsGetObjectURLExample.java
@@ -10,7 +10,7 @@ import com.ossez.usreio.client.GetObjectRequest;
import com.ossez.usreio.client.RetsException;
import com.ossez.usreio.client.RetsHttpClient;
import com.ossez.usreio.client.RetsSession;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.client.SingleObjectResponse;
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java
index e8d9833..9d63ea3 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java
@@ -1,11 +1,11 @@
package com.ossez.usreio.tests.client;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.util.Properties;
import com.ossez.usreio.client.retsapi.RETSConnection;
import com.ossez.usreio.client.retsapi.RETSGetMetadataTransaction;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.tests.common.metadata.types.MClass;
import com.ossez.usreio.tests.common.metadata.types.MResource;
import com.ossez.usreio.tests.common.metadata.types.MSystem;
@@ -27,7 +27,7 @@ public class RetsMetadataTest extends RetsTestCase {
RetsSession session = null;
try {
- session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
+ session = SessionUtils.retsLogin(retsConfigurator);
MSystem system = session.getMetadata().getSystem();
System.out.println(
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSearchExample.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSearchExample.java
index 8b7693f..e2b19a9 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSearchExample.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSearchExample.java
@@ -7,7 +7,7 @@ import com.ossez.usreio.client.CommonsHttpClient;
import com.ossez.usreio.client.RetsException;
import com.ossez.usreio.client.RetsHttpClient;
import com.ossez.usreio.client.RetsSession;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.client.SearchRequest;
import com.ossez.usreio.client.SearchResultImpl;
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java
index be9839a..83cc175 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java
@@ -2,7 +2,7 @@ package com.ossez.usreio.tests.client;
import com.ossez.usreio.client.RetsException;
import com.ossez.usreio.client.RetsSession;
-import com.ossez.usreio.client.RetsVersion;
+import com.ossez.usreio.common.rets.RetsVersion;
import com.ossez.usreio.util.SessionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.junit.jupiter.api.Test;
@@ -30,7 +30,7 @@ public class RetsSessionTest extends RetsTestCase {
logger.debug("Test Rets Session Login by URL: [{}]", retsLoginUrl);
try {
- RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
+ RetsSession session = SessionUtils.retsLogin(retsConfigurator);
assertNotNull(session.getSessionId());
} catch (RetsException ex) {
logger.debug("Session Login Error", ex);
diff --git a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsTestCase.java b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsTestCase.java
index 0c001f4..c913d3b 100644
--- a/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsTestCase.java
+++ b/rets-io-client/src/test/java/com/ossez/usreio/tests/client/RetsTestCase.java
@@ -1,5 +1,6 @@
package com.ossez.usreio.tests.client;
+import com.ossez.usreio.common.rets.RetsConfigurator;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
@@ -18,6 +19,8 @@ import java.util.Properties;
public abstract class RetsTestCase {
public Properties props = new Properties();
+ public RetsConfigurator retsConfigurator = new RetsConfigurator();
+
public String retsLoginUrl;
public String retsUsername;
public String retsPassword;
@@ -27,9 +30,9 @@ public abstract class RetsTestCase {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
props.load(loader.getResourceAsStream("rets.properties"));
- retsLoginUrl = props.getProperty("rets_server");
- retsUsername = props.getProperty("rets_username");
- retsPassword = props.getProperty("rets_password");
+ retsConfigurator.setServerUrl(props.getProperty("rets_server"));
+ retsConfigurator.setServerUsername(props.getProperty("rets_username"));
+ retsConfigurator.setServerPassword(props.getProperty("rets_password"));
}
/**
diff --git a/rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsConfigurator.java b/rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsConfigurator.java
new file mode 100644
index 0000000..160426d
--- /dev/null
+++ b/rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsConfigurator.java
@@ -0,0 +1,60 @@
+// $Header: /usr/local/cvsroot/rets/commons/src/main/java/org/realtor/rets/util/RETSConfigurator.java,v 1.2 2003/12/04 15:27:03 rsegelman Exp $
+package com.ossez.usreio.common.rets;
+
+
+/**
+ * RETSConfigurator
+ * Singleton to limit number of times BasicConfigurator.configure is called.
+ */
+public class RetsConfigurator {
+ static boolean configured = false;
+ private String serverUrl;
+ private String serverUsername;
+ private String serverPassword;
+ private RetsVersion retsVersion = RetsVersion.DEFAULT;
+
+ public RetsConfigurator() {
+ }
+
+ /**
+ * calls BasicConfigurator.configure()
only once
+ */
+ static public void configure() {
+ if (!configured) {
+// BasicConfigurator.configure();
+ configured = true;
+ }
+ }
+
+ public String getServerUrl() {
+ return serverUrl;
+ }
+
+ public void setServerUrl(String serverUrl) {
+ this.serverUrl = serverUrl;
+ }
+
+ public String getServerUsername() {
+ return serverUsername;
+ }
+
+ public void setServerUsername(String serverUsername) {
+ this.serverUsername = serverUsername;
+ }
+
+ public String getServerPassword() {
+ return serverPassword;
+ }
+
+ public void setServerPassword(String serverPassword) {
+ this.serverPassword = serverPassword;
+ }
+
+ public RetsVersion getRetsVersion() {
+ return retsVersion;
+ }
+
+ public void setRetsVersion(RetsVersion retsVersion) {
+ this.retsVersion = retsVersion;
+ }
+}
diff --git a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsVersion.java b/rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsVersion.java
similarity index 98%
rename from rets-io-client/src/main/java/com/ossez/usreio/client/RetsVersion.java
rename to rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsVersion.java
index e7f7fdf..9b58198 100644
--- a/rets-io-client/src/main/java/com/ossez/usreio/client/RetsVersion.java
+++ b/rets-io-common/src/main/java/com/ossez/usreio/common/rets/RetsVersion.java
@@ -1,4 +1,4 @@
-package com.ossez.usreio.client;
+package com.ossez.usreio.common.rets;
import java.io.Serializable;
diff --git a/rets-io-common/src/main/java/com/ossez/usreio/common/util/RETSConfigurator.java b/rets-io-common/src/main/java/com/ossez/usreio/common/util/RETSConfigurator.java
deleted file mode 100644
index 02c27e1..0000000
--- a/rets-io-common/src/main/java/com/ossez/usreio/common/util/RETSConfigurator.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// $Header: /usr/local/cvsroot/rets/commons/src/main/java/org/realtor/rets/util/RETSConfigurator.java,v 1.2 2003/12/04 15:27:03 rsegelman Exp $
-package com.ossez.usreio.common.util;
-
-
-
-
-/**
- * RETSConfigurator
- * Singleton to limit number of times BasicConfigurator.configure is called.
- */
-public class RETSConfigurator {
- static boolean configured = false;
-
- private RETSConfigurator() {
- }
-
- /** calls BasicConfigurator.configure()
only once */
- static public void configure() {
- if (!configured) {
-// BasicConfigurator.configure();
- configured = true;
- }
- }
-}