USRE-72 pull more metadata info back to session object
This commit is contained in:
parent
c6848ad66a
commit
70bc9f025f
|
@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.interfaces.IRetsHttpResponse;
|
||||||
import com.ossez.usreio.common.util.CaseInsensitiveTreeMap;
|
import com.ossez.usreio.common.util.CaseInsensitiveTreeMap;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -88,12 +89,12 @@ public class CommonsHttpClient extends RetsHttpClient {
|
||||||
this.httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
|
this.httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public RetsHttpResponse doRequest(String httpMethod, RetsHttpRequest request) throws RetsException {
|
public IRetsHttpResponse doRequest(String httpMethod, RetsHttpRequest request) throws RetsException {
|
||||||
return "GET".equals(StringUtils.upperCase(httpMethod)) ? this.doGet(request) : this.doPost(request);
|
return "GET".equals(StringUtils.upperCase(httpMethod)) ? this.doGet(request) : this.doPost(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------method implementations
|
//----------------------method implementations
|
||||||
public RetsHttpResponse doGet(RetsHttpRequest request) throws RetsException {
|
public IRetsHttpResponse doGet(RetsHttpRequest request) throws RetsException {
|
||||||
String url = request.getUrl();
|
String url = request.getUrl();
|
||||||
String args = request.getHttpParameters();
|
String args = request.getHttpParameters();
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
|
@ -103,7 +104,7 @@ public class CommonsHttpClient extends RetsHttpClient {
|
||||||
return execute(method, request.getHeaders());
|
return execute(method, request.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
public RetsHttpResponse doPost(RetsHttpRequest request) throws RetsException {
|
public IRetsHttpResponse doPost(RetsHttpRequest request) throws RetsException {
|
||||||
String url = request.getUrl();
|
String url = request.getUrl();
|
||||||
String body = request.getHttpParameters();
|
String body = request.getHttpParameters();
|
||||||
if (body == null) body = ""; // commons-httpclient 3.0 refuses to accept null entity (body)
|
if (body == null) body = ""; // commons-httpclient 3.0 refuses to accept null entity (body)
|
||||||
|
@ -118,7 +119,7 @@ public class CommonsHttpClient extends RetsHttpClient {
|
||||||
return execute(method, request.getHeaders());
|
return execute(method, request.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RetsHttpResponse execute(final HttpRequestBase method, Map<String,String> headers) throws RetsException {
|
protected IRetsHttpResponse execute(final HttpRequestBase method, Map<String,String> headers) throws RetsException {
|
||||||
try {
|
try {
|
||||||
// add the default headers
|
// add the default headers
|
||||||
if (this.defaultHeaders != null) {
|
if (this.defaultHeaders != null) {
|
||||||
|
@ -142,7 +143,7 @@ public class CommonsHttpClient extends RetsHttpClient {
|
||||||
if (status.getStatusCode() != HttpStatus.SC_OK) {
|
if (status.getStatusCode() != HttpStatus.SC_OK) {
|
||||||
throw new InvalidHttpStatusException(status);
|
throw new InvalidHttpStatusException(status);
|
||||||
}
|
}
|
||||||
return new CommonsHttpClientResponse(response, getCookies());
|
return new CommonsHttpClientResponseI(response, getCookies());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RetsException(e);
|
throw new RetsException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.interfaces.IRetsHttpResponse;
|
||||||
import com.ossez.usreio.common.util.CaseInsensitiveTreeMap;
|
import com.ossez.usreio.common.util.CaseInsensitiveTreeMap;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -13,12 +14,12 @@ import org.apache.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
public class CommonsHttpClientResponse implements RetsHttpResponse {
|
public class CommonsHttpClientResponseI implements IRetsHttpResponse {
|
||||||
private HttpResponse response;
|
private HttpResponse response;
|
||||||
private Map<String,String> headers;
|
private Map<String,String> headers;
|
||||||
private Map<String,String> cookies;
|
private Map<String,String> cookies;
|
||||||
|
|
||||||
public CommonsHttpClientResponse(HttpResponse response, Map<String,String> cookies) {
|
public CommonsHttpClientResponseI(HttpResponse response, Map<String,String> cookies) {
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.cookies = new CaseInsensitiveTreeMap<String,String>(cookies);
|
this.cookies = new CaseInsensitiveTreeMap<String,String>(cookies);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client;
|
||||||
|
|
||||||
public class NullNetworkEventMonitor implements NetworkEventMonitor {
|
import com.ossez.usreio.client.interfaces.INetworkEventMonitor;
|
||||||
|
|
||||||
|
public class NullINetworkEventMonitor implements INetworkEventMonitor {
|
||||||
|
|
||||||
public Object eventStart(String message) {
|
public Object eventStart(String message) {
|
||||||
return null;
|
return null;
|
|
@ -1,6 +1,8 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.interfaces.IRetsHttpResponse;
|
||||||
|
|
||||||
public abstract class RetsHttpClient {
|
public abstract class RetsHttpClient {
|
||||||
|
|
||||||
public static final String SESSION_ID_COOKIE = "RETS-Session-ID";
|
public static final String SESSION_ID_COOKIE = "RETS-Session-ID";
|
||||||
|
@ -16,7 +18,7 @@ public abstract class RetsHttpClient {
|
||||||
* @return
|
* @return
|
||||||
* @throws RetsException
|
* @throws RetsException
|
||||||
*/
|
*/
|
||||||
public abstract RetsHttpResponse doRequest(String httpMethod, RetsHttpRequest request) throws RetsException;
|
public abstract IRetsHttpResponse doRequest(String httpMethod, RetsHttpRequest request) throws RetsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,39 +2,50 @@ package com.ossez.usreio.client;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.interfaces.IRetsHttpResponse;
|
||||||
|
import com.ossez.usreio.client.interfaces.INetworkEventMonitor;
|
||||||
|
import com.ossez.usreio.client.models.request.LoginRequest;
|
||||||
|
import com.ossez.usreio.client.models.response.LoginResponse;
|
||||||
import com.ossez.usreio.common.rets.RetsVersion;
|
import com.ossez.usreio.common.rets.RetsVersion;
|
||||||
import com.ossez.usreio.tests.common.metadata.Metadata;
|
import com.ossez.usreio.tests.common.metadata.Metadata;
|
||||||
import com.ossez.usreio.tests.common.metadata.MetadataException;
|
import com.ossez.usreio.tests.common.metadata.MetadataException;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RetsSession is the core class of the rets.client package.
|
* RetsSession is the core class of the rets.client package.
|
||||||
*/
|
*/
|
||||||
public class RetsSession {
|
public class RetsSession {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(RetsSession.class);
|
||||||
|
|
||||||
public static final String METADATA_TABLES = "metadata_tables.xml";
|
public static final String METADATA_TABLES = "metadata_tables.xml";
|
||||||
public static final String RETS_CLIENT_VERSION = "1.5";//change default version
|
public static final String RETS_CLIENT_VERSION = "1.5";//change default version
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(RetsSession.class);
|
|
||||||
private static String sUserAgent = "crt-rets-client/" + RETS_CLIENT_VERSION;
|
private static String sUserAgent = "crt-rets-client/" + RETS_CLIENT_VERSION;
|
||||||
|
|
||||||
private CapabilityUrls capabilityUrls;
|
|
||||||
private RetsHttpClient httpClient;
|
private RetsHttpClient httpClient;
|
||||||
private RetsTransport transport;
|
private RetsTransport transport;
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
private CapabilityUrls capabilityUrls;
|
||||||
|
private String metadataVersion;
|
||||||
|
private String metadataTimestamp;
|
||||||
|
private String minMetadataVersion;
|
||||||
|
private String minMetadataTimestamp;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>RetsSession</code> instance.
|
* Creates a new <code>RetsSession</code> instance.
|
||||||
* You must call login(user, pass) before attempting any other
|
* You must call login(user, pass) before attempting any other
|
||||||
* transactions.
|
* transactions.
|
||||||
*
|
* <p>
|
||||||
* Uses a default implementation of RetsHttpClient based on
|
* Uses a default implementation of RetsHttpClient based on
|
||||||
* apache commons http client.
|
* apache commons http client.
|
||||||
*
|
* <p>
|
||||||
* Uses the RetsVersion.RETS_DEFAULT as the RetsVersion for
|
* Uses the RetsVersion.RETS_DEFAULT as the RetsVersion for
|
||||||
* this session.
|
* this session.
|
||||||
*
|
* <p>
|
||||||
* Uses sAgent at the User-Agent setting for this RetsSession.
|
* Uses sAgent at the User-Agent setting for this RetsSession.
|
||||||
*
|
*
|
||||||
* @param loginUrl URL of the Login transaction.
|
* @param loginUrl URL of the Login transaction.
|
||||||
|
@ -47,10 +58,10 @@ public class RetsSession {
|
||||||
* Creates a new <code>RetsSession</code> instance.
|
* Creates a new <code>RetsSession</code> instance.
|
||||||
* You must call login(user, pass) before attempting any other
|
* You must call login(user, pass) before attempting any other
|
||||||
* transactions.
|
* transactions.
|
||||||
*
|
* <p>
|
||||||
* Uses the RetsVersion.RETS_DEFAULT as the RetsVersion for
|
* Uses the RetsVersion.RETS_DEFAULT as the RetsVersion for
|
||||||
* this session.
|
* this session.
|
||||||
*
|
* <p>
|
||||||
* Uses sAgent at the User-Agent setting for this RetsSession.
|
* Uses sAgent at the User-Agent setting for this RetsSession.
|
||||||
*
|
*
|
||||||
* @param loginUrl URL of the Login transaction
|
* @param loginUrl URL of the Login transaction
|
||||||
|
@ -65,7 +76,7 @@ public class RetsSession {
|
||||||
* Creates a new <code>RetsSession</code> instance.
|
* Creates a new <code>RetsSession</code> instance.
|
||||||
* You must call login(user, pass) before attempting any other
|
* You must call login(user, pass) before attempting any other
|
||||||
* transactions.
|
* transactions.
|
||||||
*
|
* <p>
|
||||||
* Uses sAgent at the User-Agent setting for this RetsSession.
|
* Uses sAgent at the User-Agent setting for this RetsSession.
|
||||||
*
|
*
|
||||||
* @param loginUrl URL of the Login transaction
|
* @param loginUrl URL of the Login transaction
|
||||||
|
@ -99,7 +110,7 @@ public class RetsSession {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the current RetsVersion being used in this session.
|
* Query the current RetsVersion being used in this session.
|
||||||
*
|
* <p>
|
||||||
* Initially, this will be the value passed to the RetsTransport.
|
* Initially, this will be the value passed to the RetsTransport.
|
||||||
* However, if during auto-negotiation the RetsTransport changes
|
* However, if during auto-negotiation the RetsTransport changes
|
||||||
* the RetsSession, this value may change throughout the session.
|
* the RetsSession, this value may change throughout the session.
|
||||||
|
@ -111,28 +122,15 @@ public class RetsSession {
|
||||||
return this.transport.getRetsVersion();
|
return this.transport.getRetsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current RETS Session ID
|
|
||||||
*
|
|
||||||
* @return the current RETS Session ID or null is the server has
|
|
||||||
* not specified one
|
|
||||||
*/
|
|
||||||
public String getSessionId() {
|
|
||||||
return this.sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSessionId(String sessionId) {
|
public void setMonitor(INetworkEventMonitor monitor) {
|
||||||
LOG.debug("setting Session-ID to: " + sessionId);
|
|
||||||
this.sessionId = sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMonitor(NetworkEventMonitor monitor) {
|
|
||||||
this.transport.setMonitor(monitor);
|
this.transport.setMonitor(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStrict(boolean strict) {
|
public void setStrict(boolean strict) {
|
||||||
this.transport.setStrict(strict);
|
this.transport.setStrict(strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStrict() {
|
public boolean isStrict() {
|
||||||
return this.transport.isStrict();
|
return this.transport.isStrict();
|
||||||
}
|
}
|
||||||
|
@ -164,14 +162,15 @@ public class RetsSession {
|
||||||
* Get the complete RETS metadata.
|
* Get the complete RETS metadata.
|
||||||
*
|
*
|
||||||
* @return The RETS metadata object for these credentials.
|
* @return The RETS metadata object for these credentials.
|
||||||
*
|
|
||||||
* @throws RetsException
|
* @throws RetsException
|
||||||
*/
|
*/
|
||||||
public Metadata getMetadata() throws RetsException {
|
public Metadata getMetadata() throws RetsException {
|
||||||
return this.transport.getMetadata("null");
|
return this.transport.getMetadata("null");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ability to download the raw metadata to a location
|
* Ability to download the raw metadata to a location
|
||||||
|
*
|
||||||
* @param location
|
* @param location
|
||||||
* @return
|
* @return
|
||||||
* @throws RetsException
|
* @throws RetsException
|
||||||
|
@ -184,13 +183,11 @@ public class RetsSession {
|
||||||
* Perform a low level GetMetadatRequest. To retrieve
|
* Perform a low level GetMetadatRequest. To retrieve
|
||||||
* structured metadata,
|
* structured metadata,
|
||||||
*
|
*
|
||||||
* @see #getMetadata()
|
|
||||||
*
|
|
||||||
* @param req GetMetadataRequest
|
* @param req GetMetadataRequest
|
||||||
* @return GetMetadataResponse, containing all MetaObjects
|
* @return GetMetadataResponse, containing all MetaObjects
|
||||||
* returned
|
* returned
|
||||||
*
|
|
||||||
* @throws RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
|
* @see #getMetadata()
|
||||||
*/
|
*/
|
||||||
public GetMetadataResponse getMetadata(GetMetadataRequest req) throws RetsException {
|
public GetMetadataResponse getMetadata(GetMetadataRequest req) throws RetsException {
|
||||||
return this.transport.getMetadata(req);
|
return this.transport.getMetadata(req);
|
||||||
|
@ -199,12 +196,12 @@ public class RetsSession {
|
||||||
/**
|
/**
|
||||||
* Fetches the action (MOTD) from the server.
|
* Fetches the action (MOTD) from the server.
|
||||||
*
|
*
|
||||||
* @exception RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
*/
|
*/
|
||||||
private void getAction() throws RetsException {
|
private void getAction() throws RetsException {
|
||||||
String actionUrl = this.capabilityUrls.getActionUrl();
|
String actionUrl = this.capabilityUrls.getActionUrl();
|
||||||
if (actionUrl == null) {
|
if (actionUrl == null) {
|
||||||
LOG.warn("No Action-URL available, skipping");
|
logger.warn("No Action-URL available, skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GenericHttpRequest actionRequest = new GenericHttpRequest(actionUrl) {
|
GenericHttpRequest actionRequest = new GenericHttpRequest(actionUrl) {
|
||||||
|
@ -213,11 +210,11 @@ public class RetsSession {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RetsHttpResponse httpResponse = this.httpClient.doRequest("GET", actionRequest);
|
IRetsHttpResponse httpResponse = this.httpClient.doRequest("GET", actionRequest);
|
||||||
try {
|
try {
|
||||||
httpResponse.getInputStream().close();
|
httpResponse.getInputStream().close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Action URL weirdness", e);
|
logger.error("Action URL weirdness", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,20 +224,19 @@ public class RetsSession {
|
||||||
*
|
*
|
||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
* @exception RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
*/
|
*/
|
||||||
public GetObjectResponse getObject(GetObjectRequest req) throws RetsException {
|
public GetObjectResponse getObject(GetObjectRequest req) throws RetsException {
|
||||||
return this.transport.getObject(req);
|
return this.transport.getObject(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param resource
|
* @param resource
|
||||||
* @param type
|
* @param type
|
||||||
* @param entity
|
* @param entity
|
||||||
* @param id
|
* @param id
|
||||||
* @return response
|
* @return response
|
||||||
* @exception RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
*/
|
*/
|
||||||
public GetObjectResponse getObject(String resource, String type, String entity, String id) throws RetsException {
|
public GetObjectResponse getObject(String resource, String type, String entity, String id) throws RetsException {
|
||||||
GetObjectRequest req = new GetObjectRequest(resource, type);
|
GetObjectRequest req = new GetObjectRequest(resource, type);
|
||||||
|
@ -255,7 +251,7 @@ public class RetsSession {
|
||||||
* @param userName Username to authenticate
|
* @param userName Username to authenticate
|
||||||
* @param password Password to authenticate with
|
* @param password Password to authenticate with
|
||||||
* @return LoginResponse if success.
|
* @return LoginResponse if success.
|
||||||
* @exception RetsException if authentication was denied
|
* @throws RetsException if authentication was denied
|
||||||
*/
|
*/
|
||||||
public LoginResponse login(String userName, String password) throws RetsException {
|
public LoginResponse login(String userName, String password) throws RetsException {
|
||||||
return login(userName, password, null, null);
|
return login(userName, password, null, null);
|
||||||
|
@ -273,7 +269,7 @@ public class RetsSession {
|
||||||
* branches. May be null. brokerCode is required if you want
|
* branches. May be null. brokerCode is required if you want
|
||||||
* brokerBranch to work.
|
* brokerBranch to work.
|
||||||
* @return LoginResponse if success.
|
* @return LoginResponse if success.
|
||||||
* @exception RetsException if authentication was denied
|
* @throws RetsException if authentication was denied
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public LoginResponse login(String userName, String password, String brokerCode, String brokerBranch) throws RetsException {
|
public LoginResponse login(String userName, String password, String brokerCode, String brokerBranch) throws RetsException {
|
||||||
|
@ -286,6 +282,8 @@ public class RetsSession {
|
||||||
this.capabilityUrls = response.getCapabilityUrls();
|
this.capabilityUrls = response.getCapabilityUrls();
|
||||||
this.transport.setCapabilities(this.capabilityUrls);
|
this.transport.setCapabilities(this.capabilityUrls);
|
||||||
this.setSessionId(response.getSessionId());
|
this.setSessionId(response.getSessionId());
|
||||||
|
this.setMetadataVersion(response.getMetadataVersion());
|
||||||
|
this.setMetadataTimestamp(response.getMetadataTimestamp());
|
||||||
this.getAction();
|
this.getAction();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -314,7 +312,7 @@ public class RetsSession {
|
||||||
*
|
*
|
||||||
* @param req Contains parameters on which to search.
|
* @param req Contains parameters on which to search.
|
||||||
* @return a completed SearchResult
|
* @return a completed SearchResult
|
||||||
* @exception RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
*/
|
*/
|
||||||
public SearchResult search(SearchRequest req) throws RetsException {
|
public SearchResult search(SearchRequest req) throws RetsException {
|
||||||
SearchResultImpl res = new SearchResultImpl();
|
SearchResultImpl res = new SearchResultImpl();
|
||||||
|
@ -330,7 +328,7 @@ public class RetsSession {
|
||||||
* @param collector SearchResult object which will be informed of the results
|
* @param collector SearchResult object which will be informed of the results
|
||||||
* as they come in. If you don't need live results, see the other
|
* as they come in. If you don't need live results, see the other
|
||||||
* search invocation.
|
* search invocation.
|
||||||
* @exception RetsException if an error occurs
|
* @throws RetsException if an error occurs
|
||||||
*/
|
*/
|
||||||
public void search(SearchRequest req, SearchResultCollector collector) throws RetsException {
|
public void search(SearchRequest req, SearchResultCollector collector) throws RetsException {
|
||||||
this.transport.search(req, collector);
|
this.transport.search(req, collector);
|
||||||
|
@ -349,7 +347,7 @@ public class RetsSession {
|
||||||
/**
|
/**
|
||||||
* The lowest level integration. This method is not recommened for general use.
|
* The lowest level integration. This method is not recommened for general use.
|
||||||
*/
|
*/
|
||||||
public RetsHttpResponse request(RetsHttpRequest request) throws RetsException{
|
public IRetsHttpResponse request(RetsHttpRequest request) throws RetsException {
|
||||||
return this.transport.doRequest(request);
|
return this.transport.doRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,13 +355,16 @@ public class RetsSession {
|
||||||
* switch to a specific HttpMethodName, POST/GET, where the
|
* switch to a specific HttpMethodName, POST/GET, where the
|
||||||
* method is supported. Where GET is not supported, POST
|
* method is supported. Where GET is not supported, POST
|
||||||
* will be used.
|
* will be used.
|
||||||
|
*
|
||||||
* @param method the HttpMethodName to use
|
* @param method the HttpMethodName to use
|
||||||
*/
|
*/
|
||||||
public void setMethod(String method) {
|
public void setMethod(String method) {
|
||||||
this.transport.setMethod(method);
|
this.transport.setMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make sure GC'd sessions are logged out. */
|
/**
|
||||||
|
* Make sure GC'd sessions are logged out.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
try {
|
try {
|
||||||
|
@ -372,9 +373,10 @@ public class RetsSession {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a search returning only the number of records resulting from a query.
|
* Performs a search returning only the number of records resulting from a query.
|
||||||
*
|
* <p>
|
||||||
* Convenience method to get number records from a query
|
* Convenience method to get number records from a query
|
||||||
*
|
*
|
||||||
* @param req the search request
|
* @param req the search request
|
||||||
|
@ -389,7 +391,7 @@ public class RetsSession {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the URL's of an Object request instead of object themselves
|
* Gives the URL's of an Object request instead of object themselves
|
||||||
*
|
* <p>
|
||||||
* Convenience method to get the URL's of the requeseted object only
|
* Convenience method to get the URL's of the requeseted object only
|
||||||
*
|
*
|
||||||
* @param req
|
* @param req
|
||||||
|
@ -401,4 +403,46 @@ public class RetsSession {
|
||||||
GetObjectResponse res = this.getObject(req);
|
GetObjectResponse res = this.getObject(req);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// GET AND SET
|
||||||
|
public String getSessionId() {
|
||||||
|
return this.sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionId(String sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMetadataVersion() {
|
||||||
|
return metadataVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataVersion(String metadataVersion) {
|
||||||
|
this.metadataVersion = metadataVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMetadataTimestamp() {
|
||||||
|
return metadataTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataTimestamp(String metadataTimestamp) {
|
||||||
|
this.metadataTimestamp = metadataTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMinMetadataVersion() {
|
||||||
|
return minMetadataVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinMetadataVersion(String minMetadataVersion) {
|
||||||
|
this.minMetadataVersion = minMetadataVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMinMetadataTimestamp() {
|
||||||
|
return minMetadataTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinMetadataTimestamp(String minMetadataTimestamp) {
|
||||||
|
this.minMetadataTimestamp = minMetadataTimestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,10 @@ import java.io.FileWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.interfaces.IRetsHttpResponse;
|
||||||
|
import com.ossez.usreio.client.interfaces.INetworkEventMonitor;
|
||||||
|
import com.ossez.usreio.client.models.request.LoginRequest;
|
||||||
|
import com.ossez.usreio.client.models.response.LoginResponse;
|
||||||
import com.ossez.usreio.common.rets.RetsVersion;
|
import com.ossez.usreio.common.rets.RetsVersion;
|
||||||
import com.ossez.usreio.tests.common.metadata.JDomCompactBuilder;
|
import com.ossez.usreio.tests.common.metadata.JDomCompactBuilder;
|
||||||
import com.ossez.usreio.tests.common.metadata.JDomStandardBuilder;
|
import com.ossez.usreio.tests.common.metadata.JDomStandardBuilder;
|
||||||
|
@ -31,7 +35,7 @@ public class RetsTransport {
|
||||||
private String method = "GET";
|
private String method = "GET";
|
||||||
private RetsVersion version;
|
private RetsVersion version;
|
||||||
private boolean strict;
|
private boolean strict;
|
||||||
private NetworkEventMonitor monitor;
|
private INetworkEventMonitor monitor;
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(RetsTransport.class);
|
private static final Log LOG = LogFactory.getLog(RetsTransport.class);
|
||||||
|
|
||||||
|
@ -73,7 +77,7 @@ public class RetsTransport {
|
||||||
this.doVersionHeader(version);
|
this.doVersionHeader(version);
|
||||||
this.strict = strict;
|
this.strict = strict;
|
||||||
this.client.addDefaultHeader("Accept", "*/*");
|
this.client.addDefaultHeader("Accept", "*/*");
|
||||||
this.monitor = new NullNetworkEventMonitor();
|
this.monitor = new NullINetworkEventMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,9 +103,9 @@ public class RetsTransport {
|
||||||
this.strict = strict;
|
this.strict = strict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonitor(NetworkEventMonitor monitor) {
|
public void setMonitor(INetworkEventMonitor monitor) {
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
monitor = new NullNetworkEventMonitor();
|
monitor = new NullINetworkEventMonitor();
|
||||||
}
|
}
|
||||||
this.monitor = monitor;
|
this.monitor = monitor;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +145,7 @@ public class RetsTransport {
|
||||||
/**
|
/**
|
||||||
* Available as an integration last resort
|
* Available as an integration last resort
|
||||||
*/
|
*/
|
||||||
public RetsHttpResponse doRequest(RetsHttpRequest req) throws RetsException {
|
public IRetsHttpResponse doRequest(RetsHttpRequest req) throws RetsException {
|
||||||
Object monitorobj = null;
|
Object monitorobj = null;
|
||||||
String msg = getMonitorMessage(req);
|
String msg = getMonitorMessage(req);
|
||||||
monitorobj = this.monitor.eventStart(msg);
|
monitorobj = this.monitor.eventStart(msg);
|
||||||
|
@ -149,7 +153,7 @@ public class RetsTransport {
|
||||||
req.setVersion(this.version);
|
req.setVersion(this.version);
|
||||||
req.setUrl(this.capabilities);
|
req.setUrl(this.capabilities);
|
||||||
|
|
||||||
RetsHttpResponse httpResponse;
|
IRetsHttpResponse httpResponse;
|
||||||
try {
|
try {
|
||||||
httpResponse = this.client.doRequest(this.method, req);
|
httpResponse = this.client.doRequest(this.method, req);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -179,9 +183,9 @@ public class RetsTransport {
|
||||||
* @see #setCapabilities
|
* @see #setCapabilities
|
||||||
*/
|
*/
|
||||||
public LoginResponse login(LoginRequest req) throws RetsException {
|
public LoginResponse login(LoginRequest req) throws RetsException {
|
||||||
RetsHttpResponse retsHttpResponse = this.doRequest(req);
|
IRetsHttpResponse IRetsHttpResponse = this.doRequest(req);
|
||||||
|
|
||||||
String versionHeader = retsHttpResponse.getHeader(RetsVersion.RETS_VERSION_HEADER);
|
String versionHeader = IRetsHttpResponse.getHeader(RetsVersion.RETS_VERSION_HEADER);
|
||||||
// may be null, which is fine, return null, dont throw
|
// may be null, which is fine, return null, dont throw
|
||||||
RetsVersion retsVersion = RetsVersion.getVersion(versionHeader);
|
RetsVersion retsVersion = RetsVersion.getVersion(versionHeader);
|
||||||
if( retsVersion == null && this.strict )
|
if( retsVersion == null && this.strict )
|
||||||
|
@ -191,10 +195,10 @@ public class RetsTransport {
|
||||||
|
|
||||||
LoginResponse response = new LoginResponse(this.capabilities.getLoginUrl());
|
LoginResponse response = new LoginResponse(this.capabilities.getLoginUrl());
|
||||||
|
|
||||||
String sessionId = retsHttpResponse.getCookie(RETS_SESSION_ID_HEADER);
|
String sessionId = IRetsHttpResponse.getCookie(RETS_SESSION_ID_HEADER);
|
||||||
response.setSessionId(sessionId);
|
response.setSessionId(sessionId);
|
||||||
response.setStrict(this.strict);
|
response.setStrict(this.strict);
|
||||||
response.parse(retsHttpResponse.getInputStream(), this.version);
|
response.parse(IRetsHttpResponse.getInputStream(), this.version);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +216,7 @@ public class RetsTransport {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
RetsHttpRequest req = new LogoutRequest();
|
RetsHttpRequest req = new LogoutRequest();
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
LogoutResponse response = new LogoutResponse();
|
LogoutResponse response = new LogoutResponse();
|
||||||
response.setStrict(this.strict);
|
response.setStrict(this.strict);
|
||||||
try {
|
try {
|
||||||
|
@ -235,7 +239,7 @@ public class RetsTransport {
|
||||||
* @param collector the result object that will store the data
|
* @param collector the result object that will store the data
|
||||||
*/
|
*/
|
||||||
public void search(SearchRequest req, SearchResultCollector collector) throws RetsException {
|
public void search(SearchRequest req, SearchResultCollector collector) throws RetsException {
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
new SearchResultHandler(collector).parse(httpResponse.getInputStream(), httpResponse.getCharset());
|
new SearchResultHandler(collector).parse(httpResponse.getInputStream(), httpResponse.getCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +251,7 @@ public class RetsTransport {
|
||||||
* @param processor the result object that will process the data
|
* @param processor the result object that will process the data
|
||||||
*/
|
*/
|
||||||
public SearchResultSet search(SearchRequest req, SearchResultProcessor processor) throws RetsException {
|
public SearchResultSet search(SearchRequest req, SearchResultProcessor processor) throws RetsException {
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
return processor.parse(httpResponse.getInputStream());
|
return processor.parse(httpResponse.getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +267,7 @@ public class RetsTransport {
|
||||||
throw new RetsException("Server does not support GetObject transaction.");
|
throw new RetsException("Server does not support GetObject transaction.");
|
||||||
}
|
}
|
||||||
req.setUrl(this.capabilities);
|
req.setUrl(this.capabilities);
|
||||||
RetsHttpResponse httpResponse = this.client.doRequest(this.method, req);
|
IRetsHttpResponse httpResponse = this.client.doRequest(this.method, req);
|
||||||
GetObjectResponse result = new GetObjectResponse(httpResponse.getHeaders(), httpResponse.getInputStream());
|
GetObjectResponse result = new GetObjectResponse(httpResponse.getHeaders(), httpResponse.getInputStream());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +279,7 @@ public class RetsTransport {
|
||||||
req.setCompactFormat();
|
req.setCompactFormat();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
Object monitorobj = null;
|
Object monitorobj = null;
|
||||||
monitorobj = this.monitor.eventStart("Parsing metadata");
|
monitorobj = this.monitor.eventStart("Parsing metadata");
|
||||||
try {
|
try {
|
||||||
|
@ -310,7 +314,7 @@ public class RetsTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetMetadataResponse getMetadata(GetMetadataRequest req) throws RetsException {
|
public GetMetadataResponse getMetadata(GetMetadataRequest req) throws RetsException {
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
Object monitorobj = null;
|
Object monitorobj = null;
|
||||||
monitorobj = this.monitor.eventStart("Parsing metadata");
|
monitorobj = this.monitor.eventStart("Parsing metadata");
|
||||||
try {
|
try {
|
||||||
|
@ -326,7 +330,7 @@ public class RetsTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changePassword(ChangePasswordRequest req) throws RetsException {
|
public boolean changePassword(ChangePasswordRequest req) throws RetsException {
|
||||||
RetsHttpResponse httpResponse = doRequest(req);
|
IRetsHttpResponse httpResponse = doRequest(req);
|
||||||
ChangePasswordResponse response = new ChangePasswordResponse(httpResponse.getInputStream());
|
ChangePasswordResponse response = new ChangePasswordResponse(httpResponse.getInputStream());
|
||||||
// response will throw an exception if there is an error code
|
// response will throw an exception if there is an error code
|
||||||
return (response != null);
|
return (response != null);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client.interfaces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client can register a monitor for network events
|
* A client can register a monitor for network events
|
||||||
*/
|
*/
|
||||||
public interface NetworkEventMonitor
|
public interface INetworkEventMonitor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* inform the client app that an event has started.
|
* inform the client app that an event has started.
|
|
@ -1,4 +1,6 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client.interfaces;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.RetsException;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -8,7 +10,7 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
* @author YuCheng Hu
|
* @author YuCheng Hu
|
||||||
*/
|
*/
|
||||||
public interface RetsHttpResponse {
|
public interface IRetsHttpResponse {
|
||||||
public int getResponseCode() throws RetsException;
|
public int getResponseCode() throws RetsException;
|
||||||
|
|
||||||
public Map getHeaders() throws RetsException;
|
public Map getHeaders() throws RetsException;
|
|
@ -1,4 +1,7 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client.models.request;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.CapabilityUrls;
|
||||||
|
import com.ossez.usreio.client.VersionInsensitiveRequest;
|
||||||
|
|
||||||
public class LoginRequest extends VersionInsensitiveRequest {
|
public class LoginRequest extends VersionInsensitiveRequest {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ossez.usreio.client;
|
package com.ossez.usreio.client.models.response;
|
||||||
|
|
||||||
|
import com.ossez.usreio.client.*;
|
||||||
import com.ossez.usreio.common.rets.RetsVersion;
|
import com.ossez.usreio.common.rets.RetsVersion;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
@ -84,7 +84,7 @@ public class RETSConnection extends java.lang.Object {
|
||||||
*/
|
*/
|
||||||
public RETSConnection() {
|
public RETSConnection() {
|
||||||
setRequestHeaderField("User-Agent", "Mozilla/4.0");
|
setRequestHeaderField("User-Agent", "Mozilla/4.0");
|
||||||
setRequestHeaderField("RETS-Version", "RETS/1.0");
|
setRequestHeaderField("RETS-Version", "RETS/1.7.2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ossez.usreio.util;
|
package com.ossez.usreio.util;
|
||||||
|
|
||||||
import com.ossez.usreio.client.*;
|
import com.ossez.usreio.client.*;
|
||||||
|
import com.ossez.usreio.client.models.response.LoginResponse;
|
||||||
import com.ossez.usreio.common.rets.RetsConfigurator;
|
import com.ossez.usreio.common.rets.RetsConfigurator;
|
||||||
import com.ossez.usreio.common.rets.RetsVersion;
|
import com.ossez.usreio.common.rets.RetsVersion;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.ossez.usreio.tests.client;
|
package com.ossez.usreio.tests.client;
|
||||||
|
|
||||||
import com.ossez.usreio.client.LoginRequest;
|
import com.ossez.usreio.client.models.request.LoginRequest;
|
||||||
|
|
||||||
public class LoginRequestTest extends RetsTestCase {
|
public class LoginRequestTest extends RetsTestCase {
|
||||||
public void testGetUrl() {
|
public void testGetUrl() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.ossez.usreio.tests.client;
|
||||||
|
|
||||||
|
|
||||||
import com.ossez.usreio.client.CapabilityUrls;
|
import com.ossez.usreio.client.CapabilityUrls;
|
||||||
import com.ossez.usreio.client.LoginResponse;
|
import com.ossez.usreio.client.models.response.LoginResponse;
|
||||||
import com.ossez.usreio.client.RetsException;
|
import com.ossez.usreio.client.RetsException;
|
||||||
import com.ossez.usreio.common.rets.RetsVersion;
|
import com.ossez.usreio.common.rets.RetsVersion;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
public class RetsSessionTest extends RetsTestCase {
|
public class RetsSessionTest extends RetsTestCase {
|
||||||
private final Logger logger = LoggerFactory.getLogger(RetsSessionTest.class);
|
private final Logger logger = LoggerFactory.getLogger(RetsSessionTest.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Login should return SessionID from server
|
* Test Login should return SessionID from server
|
||||||
*/
|
*/
|
||||||
|
@ -33,13 +32,34 @@ public class RetsSessionTest extends RetsTestCase {
|
||||||
try {
|
try {
|
||||||
RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
|
RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
|
||||||
assertNotNull(session.getSessionId());
|
assertNotNull(session.getSessionId());
|
||||||
|
|
||||||
|
// CHECK MetaData
|
||||||
|
logger.error("Session ID - [{}]", session.getSessionId());
|
||||||
|
logger.error("MetaData version - [{}]", session.getMetadataVersion());
|
||||||
|
logger.error("MetaData Timestamp - [{}]", session.getMetadataTimestamp());
|
||||||
|
|
||||||
|
} catch (RetsException ex) {
|
||||||
|
logger.error("Session Login Error", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Login should return SessionID from server
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testLoginWithConfigurator() {
|
||||||
|
logger.debug("Test Rets Session Login by URL: [{}]", retsLoginUrl);
|
||||||
|
|
||||||
|
try {
|
||||||
|
RetsSession session = SessionUtils.retsLogin(retsConfigurator);
|
||||||
|
// session.login()
|
||||||
|
assertNotNull(session.getSessionId());
|
||||||
} catch (RetsException ex) {
|
} catch (RetsException ex) {
|
||||||
logger.debug("Session Login Error", ex);
|
logger.debug("Session Login Error", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TEST Logout
|
* TEST Logout
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +70,9 @@ public class RetsSessionTest extends RetsTestCase {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
|
session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
|
||||||
|
|
||||||
assertNotNull(session.getSessionId());
|
assertNotNull(session.getSessionId());
|
||||||
|
|
||||||
} catch (RetsException ex) {
|
} catch (RetsException ex) {
|
||||||
logger.debug("Session Login Error", ex);
|
logger.debug("Session Login Error", ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue