Skip to content
Permalink
Browse files

Fix issue #98 upgrade to Apache HttpClient 4.2.5; props to jamesrdf f…

…or the patches though I applied them manually and tinkered a bit
  • Loading branch information
ndw committed Jul 26, 2013
1 parent fbcc769 commit 81a2db693cdd62c96305e9fc650e04e34f4d864c
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +25.9 KB lib/httpmime-4.2.5.jar
Binary file not shown.
BIN +4.7 KB (110%) lib/xmlresolver.jar
Binary file not shown.
@@ -59,11 +59,11 @@
<version>9.4.0.7</version>
</dependency>

<!-- No need to specify commons-logging or commons-codec - they're transitive dependencies of commons-httpclient -->
<!-- No need to specify commons-logging or commons-codec - they're transitive dependencies of httpclient -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>

<dependency>
@@ -20,6 +20,54 @@

package com.xmlcalabash.core;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Logger;

import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;

import net.sf.saxon.Configuration;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.s9api.ExtensionFunction;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;

import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

import com.xmlcalabash.config.XProcConfigurer;
import com.xmlcalabash.functions.BaseURI;
import com.xmlcalabash.functions.Cwd;
@@ -34,6 +82,9 @@
import com.xmlcalabash.functions.XProcExtensionFunctionDefinition;
import com.xmlcalabash.io.ReadableData;
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.model.DeclareStep;
import com.xmlcalabash.model.Parser;
import com.xmlcalabash.model.PipelineLibrary;
import com.xmlcalabash.runtime.XLibrary;
import com.xmlcalabash.runtime.XPipeline;
import com.xmlcalabash.runtime.XRootStep;
@@ -44,51 +95,8 @@
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.StepErrorListener;
import com.xmlcalabash.util.TreeWriter;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.s9api.ExtensionFunction;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.SaxonApiException;
import com.xmlcalabash.model.Parser;
import com.xmlcalabash.model.DeclareStep;
import com.xmlcalabash.model.PipelineLibrary;
import com.xmlcalabash.util.XProcURIResolver;
import com.xmlcalabash.util.URIUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Logger;
import java.util.Hashtable;
import java.util.Vector;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;

import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import org.apache.commons.httpclient.Cookie;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import com.xmlcalabash.util.XProcURIResolver;

/**
*
@@ -106,7 +114,6 @@
private Hashtable<QName, DeclareStep> declaredSteps = new Hashtable<QName,DeclareStep> ();
private DeclareStep pipeline = null;
private XPipeline xpipeline = null;
private Vector<Throwable> errors = null;
private static String episode = null;
private Hashtable<String,Vector<XdmNode>> collections = null;
private URI staticBaseURI = null;
@@ -120,7 +127,8 @@
private XProcMessageListener msgListener = null;
private PipelineLibrary standardLibrary = null;
private XLibrary xStandardLibrary = null;
private Hashtable<String,Vector<Cookie>> cookieHash = new Hashtable<String,Vector<Cookie>> ();
private HttpClient httpClient;
private Map<String, CookieStore> cookieStores;
private XProcConfigurer configurer = null;
private String htmlParser = null;
private Vector<XProcExtensionFunctionDefinition> exFuncs = new Vector<XProcExtensionFunctionDefinition>();
@@ -244,7 +252,8 @@ public XProcRuntime(XProcRuntime runtime) {
msgListener = runtime.msgListener;
standardLibrary = runtime.standardLibrary;
xStandardLibrary = runtime.xStandardLibrary;
cookieHash = runtime.cookieHash;
httpClient = runtime.httpClient;
cookieStores = runtime.cookieStores;
configurer = runtime.configurer;
allowGeneralExpressions = runtime.allowGeneralExpressions;
allowXPointerOnText = runtime.allowXPointerOnText;
@@ -276,6 +285,8 @@ public void close() {
for (XProcExtensionFunctionDefinition xf : exFuncs) {
xf.close();
}
HttpClientUtils.closeQuietly(httpClient);
httpClient = null;
}

public XProcConfigurer getConfigurer() {
@@ -464,17 +475,16 @@ public XLibrary getStandardLibrary() {
return xStandardLibrary;
}

private void reset() {
private synchronized void reset() {
errorCode = null;
errorMessage = null;
declaredSteps = new Hashtable<QName,DeclareStep> ();
//explicitDeclarations = false;
pipeline = null;
xpipeline = null;
errors = null;
episode = null;
collections = null;
cookieHash = new Hashtable<String,Vector<Cookie>> ();
cookieStores = new HashMap<String, CookieStore>();

xprocData = new XProcData(this);

@@ -727,26 +737,39 @@ public DeclareStep getBuiltinDeclaration(QName name) {
}
}

public void clearCookies(String key) {
if (cookieHash.containsKey(key)) {
cookieHash.get(key).clear();
}
public synchronized CookieStore getCookieStore(String key) {
if (cookieStores.containsKey(key))
return cookieStores.get(key);
BasicCookieStore cookieStore = new BasicCookieStore();
cookieStores.put(key, cookieStore);
return cookieStore;
}

public void addCookie(String key, Cookie cookie) {
if (!cookieHash.containsKey(key)) {
cookieHash.put(key, new Vector<Cookie> ());
public synchronized void setCookieStore(String key, CookieStore cookieStore) {
if (cookieStore == null) {
removeCookieStore(key);
} else {
this.cookieStores.put(key, cookieStore);
}
}

cookieHash.get(key).add(cookie);
public synchronized void removeCookieStore(String key) {
this.cookieStores.remove(key);
}

public Vector<Cookie> getCookies(String key) {
if (cookieHash.containsKey(key)) {
return cookieHash.get(key);
} else {
return new Vector<Cookie> ();
}
public synchronized HttpClient getHttpClient() {
if (this.httpClient == null) {
SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
// Provide custom retry handler is necessary
httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(3, false));
return this.httpClient = httpClient;
} else {
return httpClient;
}
}

public synchronized void setHttpClient(HttpClient client) {
this.httpClient = client;
}

public QName getErrorCode() {
@@ -1,22 +1,20 @@
package com.xmlcalabash.extensions;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;

import org.apache.http.cookie.Cookie;

import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.core.XProcException;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.TreeWriter;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import org.apache.commons.httpclient.Cookie;

import javax.xml.datatype.Duration;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Created by IntelliJ IDEA.
@@ -66,7 +64,7 @@ public void run() throws SaxonApiException {
tree.addStartElement(c_cookies);
tree.startContent();

for (Cookie cookie : runtime.getCookies(cookieKey)) {
for (Cookie cookie : runtime.getCookieStore(cookieKey).getCookies()) {
tree.addStartElement(c_cookie);
tree.addAttribute(_name, cookie.getName());
tree.addAttribute(_value, cookie.getValue());
@@ -1,26 +1,27 @@
package com.xmlcalabash.extensions;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmNodeKind;

import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicClientCookie;

import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.core.XProcException;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.RelevantNodes;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmNodeKind;
import org.apache.commons.httpclient.Cookie;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Created by IntelliJ IDEA.
@@ -87,9 +88,7 @@ public void run() throws SaxonApiException {
throw new XProcException(step.getNode(), "Invalid cookie: " + node);
}

Cookie cookie = new Cookie();
cookie.setName(name);
cookie.setValue(value);
SetCookie cookie = new BasicClientCookie(name, value);

if (domain != null) { cookie.setDomain(domain); }
if (path != null) { cookie.setPath(path); }
@@ -112,7 +111,7 @@ public void run() throws SaxonApiException {
}
}

runtime.addCookie(cookieKey, cookie);
runtime.getCookieStore(cookieKey).addCookie(cookie);

} else if (node.getNodeKind() == XdmNodeKind.TEXT) {
if ("".equals(node.getStringValue().trim())) {

0 comments on commit 81a2db6

Please sign in to comment.
You can’t perform that action at this time.