USRE-88 Change the file structure for better access and more readable
This commit is contained in:
parent
42e924952d
commit
61b824d657
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.ossez.usreio.client;
|
||||
|
||||
import com.ossez.usreio.common.rets.RetsVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* The search request sent from search() in RetsSession
|
||||
|
|
|
@ -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.)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 <code>BasicConfigurator.configure()</code> 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;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.ossez.usreio.client;
|
||||
package com.ossez.usreio.common.rets;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -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 <code>BasicConfigurator.configure()</code> only once */
|
||||
static public void configure() {
|
||||
if (!configured) {
|
||||
// BasicConfigurator.configure();
|
||||
configured = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue