USRE-84 add apache httpclient connection

This commit is contained in:
YuCheng Hu 2021-11-24 13:37:37 -05:00
parent 02b2bf291c
commit 71e0ab4217
5 changed files with 91 additions and 87 deletions

15
pom.xml
View File

@ -39,6 +39,15 @@
<artifactId>logback-classic</artifactId>
<version>1.2.5</version>
</dependency>
<!-- APACHE COMMONS -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${commons-httpclient.version}</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
@ -111,7 +120,9 @@
<commons-lang.version>2.6</commons-lang.version>
<commons-lang3.version>3.11</commons-lang3.version>
<commons-cli.version>1.4</commons-cli.version>
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
<commons-httpclient.version>4.5.13</commons-httpclient.version>
<!-- UTILS -->
<guava.version>30.1.1-jre</guava.version>
@ -143,6 +154,8 @@
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
</properties>
</project>

View File

@ -11,8 +11,9 @@ import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
import org.realtor.rets.util.RETSConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URLEncoder;
@ -27,8 +28,7 @@ import java.util.zip.GZIPInputStream;
* @version 1.0
*/
public class RETSConnection extends java.lang.Object {
// log4j category
static Category cat = Category.getInstance(RETSConnection.class);
private final static Logger logger = LoggerFactory.getLogger(RETSConnection.class);
static {
RETSConfigurator.configure();

View File

@ -6,14 +6,13 @@
*/
package org.realtor.rets.retsapi;
//import java.util.*;
import org.apache.log4j.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
///////////////////////////////////////////////////////////////////////
public class RETSGetMetadataTransaction extends RETSTransaction {
static Category cat = Category.getInstance(RETSGetMetadataTransaction.class);
private final static Logger logger = LoggerFactory.getLogger(RETSConnection.class);
String version = null;
/**

View File

@ -1,26 +1,28 @@
/**
* RETSTransaction.java
* RETSTransaction.java
*
* @author jbrush
* @version
* @author jbrush
* @version
*/
package org.realtor.rets.retsapi;
import org.apache.log4j.*;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
import org.realtor.rets.util.RETSRequestResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.regexp.*;
import org.realtor.rets.util.*;
import java.io.*;
import java.util.*;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
///////////////////////////////////////////////////////////////////////
public class RETSTransaction extends RETSRequestResponse {
static Category cat = Category.getInstance(RETSTransaction.class);
private final static Logger logger = LoggerFactory.getLogger(RETSConnection.class);
private static final String STATUS = "status";
private static final String STATUSTEXT = "statusText";
private static final String BODY = "body";
@ -47,7 +49,7 @@ public class RETSTransaction extends RETSRequestResponse {
firstStatusRE = new RE("<RETS\\s?ReplyCode=\"(.*?)\"\\s?ReplyText=\"(.*?)\"");
secondStatusRE = new RE("<RETS-STATUS\\s?ReplyCode=\"(.*?)\"\\s?ReplyText=\"(.*?)\"");
} catch (RESyntaxException e) {
cat.error("Error compiling REs", e);
logger.error("Error compiling REs", e);
}
}
@ -140,7 +142,7 @@ public class RETSTransaction extends RETSRequestResponse {
public String getUrl() {
String url = getCapabilityUrl(getRequestType());
cat.debug("getUrl():" + getRequestType() + " url:" + url);
logger.debug("getUrl():" + getRequestType() + " url:" + url);
return url;
}
@ -228,22 +230,22 @@ public class RETSTransaction extends RETSRequestResponse {
// If we have no header map, we obviously have no headers. Also, if
// there is no list for the header name, we don't have the
// requested header.
if ( headerName != null && headerName.equals("content-type") ) {
if (headerName != null && headerName.equals("content-type")) {
headerName = "Content-Type";
}
if (responseHeaderMap != null) {
cat.debug("RESPONSEHEADERMAP ==> " + responseHeaderMap.toString());
logger.debug("RESPONSEHEADERMAP ==> " + responseHeaderMap.toString());
// responseString = (String) responseHeaderMap.get(headerName.toLowerCase());
cat.debug("ContentType Class is ... " + responseHeaderMap.get(headerName).getClass().getName());
logger.debug("ContentType Class is ... " + responseHeaderMap.get(headerName).getClass().getName());
Object object = responseHeaderMap.get(headerName);
if ( object == null )
if (object == null)
return null;
if ( object instanceof ArrayList ) {
responseString = (String) ((ArrayList)object).get(0);
if (object instanceof ArrayList) {
responseString = (String) ((ArrayList) object).get(0);
} else
responseString = object.toString();
} else {
cat.debug("RESPONSEHEADERMAP ==> " + responseHeaderMap);
logger.debug("RESPONSEHEADERMAP ==> " + responseHeaderMap);
}
return responseString;
}
@ -267,7 +269,7 @@ public class RETSTransaction extends RETSRequestResponse {
}
static public void log(String logMessage) {
cat.debug(logMessage);
logger.debug(logMessage);
}
}

View File

@ -1,28 +1,20 @@
package org.realtor.rets.retsapi;
import org.apache.log4j.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.Map;
import org.apache.xpath.XPathAPI;
import org.realtor.rets.util.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.util.Collections;
import java.util.Vector;
import javax.xml.transform.TransformerException;
/**
* RETSUpdateTransaction.java
* RETSUpdateTransaction.java
*
* @author pobrien
* @version 1.0
* @author pobrien
* @version 1.0
*/
public class RETSUpdateTransaction extends RETSTransaction {
static Category cat = Category.getInstance(RETSUpdateTransaction.class);
private final static Logger logger = LoggerFactory.getLogger(RETSConnection.class);
/**
*
@ -34,9 +26,9 @@ public class RETSUpdateTransaction extends RETSTransaction {
}
/**
* Sets the response body for the transaction.
* Sets the response body for the transaction.
*
* @param body body of the transaction
* @param body body of the transaction
*/
public void setResponse(String body) {
super.setResponse(body);
@ -44,55 +36,56 @@ public class RETSUpdateTransaction extends RETSTransaction {
setKeyValuePairs(body);
}
/**
* Sets the type attribute to the string passed in.
* Sets the type attribute to the string passed in.
*
* @param type type attribute value
* @param str type attribute value
*/
public void setType(String str) {
cat.debug("set Type=" + str);
logger.debug("set Type=" + str);
setRequestVariable("Type", str);
}
/**
* Sets the ID attribute to the string passed in.
* Sets the ID attribute to the string passed in.
*
* @param str ID of the object
* @param str ID of the object
*/
public void setValidate(String str) {
cat.debug("set Validate=" + str);
logger.debug("set Validate=" + str);
setRequestVariable("Validate", str);
}
/**
* Sets the location attribute to the string passed in.
* Sets the location attribute to the string passed in.
*
* @param str location attribute value
* @param str location attribute value
*/
public void setDelimiter(String str) {
cat.debug("set Delimiter=" + str);
logger.debug("set Delimiter=" + str);
setRequestVariable("Delimiter", str);
}
public String getDelimiter() {
return getRequestVariable("Delimiter");
return getRequestVariable("Delimiter");
}
public void setRecord(String str) {
cat.debug("set Record=" + str);
logger.debug("set Record=" + str);
setRequestVariable("Record", str);
}
public void setWarningResponse(String str) {
cat.debug("set WarningResponse=" + str);
setRequestVariable("WarningResponse", str);
logger.debug("set WarningResponse=" + str);
setRequestVariable("WarningResponse", str);
}
public void setNewValues(Map m) {
// convert to a string and feed to setRecord()....
StringBuffer record = new StringBuffer();
Iterator iter = m.keySet().iterator();
// delimiter is a 2 digit HEX value
// delimiter is a 2 digit HEX value
char delim = (char) Integer.parseInt(getDelimiter().trim(), 16);
while (iter.hasNext()) {
@ -122,36 +115,36 @@ public class RETSUpdateTransaction extends RETSTransaction {
public void setWarningResponseValues(Map m) {
// convert to a string and feed to setWarningResponse()....
StringBuffer warning = new StringBuffer("(");
Iterator iter = m.keySet().iterator();
// delimiter is a 2 digit HEX value
char delim = (char) Integer.parseInt(getDelimiter().trim(), 16);
// convert to a string and feed to setWarningResponse()....
StringBuffer warning = new StringBuffer("(");
Iterator iter = m.keySet().iterator();
// delimiter is a 2 digit HEX value
char delim = (char) Integer.parseInt(getDelimiter().trim(), 16);
while (iter.hasNext()) {
String name = (String) iter.next();
Object val = m.get(name);
String value = "";
while (iter.hasNext()) {
String name = (String) iter.next();
Object val = m.get(name);
String value = "";
if (val instanceof String) {
value = (String) val;
} else {
String[] arr = (String[]) val;
value = arr[0];
}
if (val instanceof String) {
value = (String) val;
} else {
String[] arr = (String[]) val;
value = arr[0];
}
warning.append(name);
warning.append("=");
warning.append(value);
warning.append(name);
warning.append("=");
warning.append(value);
if (iter.hasNext()) {
if (iter.hasNext()) {
warning.append(delim);
}
}
warning.append(delim);
}
}
warning.append(")");
setWarningResponse(warning.toString());
warning.append(")");
setWarningResponse(warning.toString());
}
public void setUID(String id) {
@ -160,7 +153,4 @@ public class RETSUpdateTransaction extends RETSTransaction {
}
}