Commit c5713e03 authored by mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

(partially) restore CL:LOAD from jar files.

There is apparently a fair amount of "breakage" of cases that used to
load no longer working which seems due to the changes in the semantics
for finding the FASL init loader.  The following tests are now broken
but no longer cause the JVM to crash: JAR-PATHNAME.LOAD.HTTP.1,
JAR-PATHNAME.LOAD.HTTP.2, JAR-PATHNAME.LOAD.HTTP.4,
JAR-PATHNAME.LOAD.HTTP.6, JAR-PATHNAME.LOAD.HTTP.7,
and JAR-PATHNAME.LOAD.HTTP.9.  Need to follow this up in subsequent work.

Fixed the underlying HttpHead.get() interface used to determine
whether to used a cache version. The custom HTTP HEAD code that was
working under Java 6 no longer worked on Java 7.

Added to HttpHead.get() asynchronous java.lang.Throwable on a socket
timeout of 5000 ms.
parent 5f132666
...@@ -86,11 +86,17 @@ public final class Debug ...@@ -86,11 +86,17 @@ public final class Debug
System.err.println(s); System.err.println(s);
} }
@SuppressWarnings("CallToThreadDumpStack")
public static final void trace(Throwable t) public static final void trace(Throwable t)
{ {
t.printStackTrace(); t.printStackTrace();
} }
public static final void trace(String message, Throwable t)
{
trace(message);
trace(t);
}
public static final Symbol _DEBUG_WARN_ public static final Symbol _DEBUG_WARN_
= exportSpecial("*DEBUG-WARN*", PACKAGE_SYS, NIL); = exportSpecial("*DEBUG-WARN*", PACKAGE_SYS, NIL);
......
...@@ -164,7 +164,12 @@ public class ZipCache { ...@@ -164,7 +164,12 @@ public class ZipCache {
// implementation only looking for Last-Modified // implementation only looking for Last-Modified
// headers, which if we don't find, we give up and // headers, which if we don't find, we give up and
// refetch the resource. // refetch the resource.
String dateString = HttpHead.get(url, "Last-Modified"); String dateString = null;
try {
dateString = HttpHead.get(url, "Last-Modified");
} catch (IOException ex) {
Debug.trace(ex);
}
Date date = null; Date date = null;
ParsePosition pos = new ParsePosition(0); ParsePosition pos = new ParsePosition(0);
......
...@@ -37,6 +37,7 @@ import org.armedbear.lisp.Debug; ...@@ -37,6 +37,7 @@ import org.armedbear.lisp.Debug;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
...@@ -48,7 +49,7 @@ import java.net.URL; ...@@ -48,7 +49,7 @@ import java.net.URL;
* Use HTTP/1.1 HEAD to retrieve the specified header field. * Use HTTP/1.1 HEAD to retrieve the specified header field.
*/ */
public class HttpHead { public class HttpHead {
static private String get(String urlString, String key) { static private String get(String urlString, String key) throws IOException {
URL url = null; URL url = null;
try { try {
url = new URL(urlString); url = new URL(urlString);
...@@ -58,7 +59,7 @@ public class HttpHead { ...@@ -58,7 +59,7 @@ public class HttpHead {
return get(url, key); return get(url, key);
} }
static public String get(URL url, String key) { static public String get(URL url, String key) throws IOException {
Socket socket = null; Socket socket = null;
String result = null; String result = null;
try { try {
...@@ -67,37 +68,30 @@ public class HttpHead { ...@@ -67,37 +68,30 @@ public class HttpHead {
log("The protocol " + "'" + protocol + "'" + " is not http."); log("The protocol " + "'" + protocol + "'" + " is not http.");
return result; return result;
} }
String host = url.getHost();
socket = new Socket(Proxy.NO_PROXY); // XXX add Proxy
int port = url.getPort(); int port = url.getPort();
if (port == -1) { if (port == -1) {
port = 80; port = 80;
} }
InetSocketAddress address = new InetSocketAddress(url.getHost(), port); socket = new Socket(host, port);
try {
socket.connect(address, 5000); // ??? too long? too short?
} catch (IOException ex) {
log("Connection failed: " + ex);
return result;
}
PrintWriter out = null; PrintWriter out = null;
BufferedReader in = null; BufferedReader in = null;
try { try {
socket.setSoTimeout(5000); // ms socket.setSoTimeout(5000); // ms
out = new PrintWriter(socket.getOutputStream()); out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) { } catch (IOException e) {
log("Failed to establish socket io: " + e); log("Failed to establish socket io: " + e);
return result; return result;
} }
String CRLF = "\r\n";
String head = "HEAD " + url.getPath() + " HTTP/1.1"; String head = "HEAD " + url.getPath() + " HTTP/1.1";
out.println(head); out.print(head + CRLF);
out.println("Host: " + url.getAuthority()); out.print("Host: " + url.getAuthority() + CRLF);
out.println("Connection: close"); out.print("Connection: close" + CRLF);
out.println(""); out.print(CRLF);
out.flush(); out.flush();
String line = null; String line = null;
...@@ -106,6 +100,9 @@ public class HttpHead { ...@@ -106,6 +100,9 @@ public class HttpHead {
} catch (IOException e) { } catch (IOException e) {
log("Failed to read HTTP response: " + e); log("Failed to read HTTP response: " + e);
} }
if (line == null) {
throw new IOException("Could not access URL to parse headers.");
}
String status[] = line.split("\\s"); String status[] = line.split("\\s");
if (status[1].equals("200")) { if (status[1].equals("200")) {
result = findHeader(in, key); result = findHeader(in, key);
...@@ -154,15 +151,21 @@ public class HttpHead { ...@@ -154,15 +151,21 @@ public class HttpHead {
} }
public static void main(String argv[]) { public static void main(String argv[]) {
if (argv.length != 1) { if (argv.length != 1) {
System.out.println("Usage: <cmd> URL"); System.out.println("Usage: <cmd> URL");
return; return;
} }
String modified = get(argv[0], "Last-Modified"); String modified = null;
if (modified != null) { try {
System.out.println("Last-Modified: " + modified); modified = get(argv[0], "Last-Modified");
} else { } catch (IOException ex) {
System.out.println("No result returned."); System.err.println("Unable to get Last-Modified header: ");
} ex.printStackTrace(System.err);
}
if (modified != null) {
System.out.println("Last-Modified: " + modified);
} else {
System.out.println("No result returned.");
}
} }
} }
...@@ -149,7 +149,7 @@ Returns the two values of the pathnames of the created archives." ...@@ -149,7 +149,7 @@ Returns the two values of the pathnames of the created archives."
(load-from-jar *tmp-jar-path* "eek") (load-from-jar *tmp-jar-path* "eek")
t) t)
çu(deftest jar-pathname.load.5 (deftest jar-pathname.load.5
(load-from-jar *tmp-jar-path* "eek.lisp") (load-from-jar *tmp-jar-path* "eek.lisp")
t) t)
...@@ -209,10 +209,6 @@ Returns the two values of the pathnames of the created archives." ...@@ -209,10 +209,6 @@ Returns the two values of the pathnames of the created archives."
`(load (probe-file (format nil "~A~A" *url-jar-pathname-base* ,path)))) `(load (probe-file (format nil "~A~A" *url-jar-pathname-base* ,path))))
;;; wrapped in PROGN for easy disabling without a network connection ;;; wrapped in PROGN for easy disabling without a network connection
;;; XXX come up with a better abstraction
;; disable until fix loading fasls via HTTP
#+nil Bombs JVM! --ME 20140126
(progn (progn
(deftest jar-pathname.load.http.1 (deftest jar-pathname.load.http.1
(load-url-relative "foo") (load-url-relative "foo")
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.armedbear.lisp.util; package org.armedbear.lisp.util;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -17,10 +12,6 @@ import org.junit.BeforeClass; ...@@ -17,10 +12,6 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/**
*
* @author evenson
*/
public class HttpHeadTest { public class HttpHeadTest {
public HttpHeadTest() { public HttpHeadTest() {
...@@ -42,36 +33,30 @@ public class HttpHeadTest { ...@@ -42,36 +33,30 @@ public class HttpHeadTest {
public void tearDown() { public void tearDown() {
} }
/**
* Test of get method, of class HttpHead.
*/
@Test @Test
public void testGet() { public void testGet() {
System.out.println("get");
URL url = null; URL url = null;
try { try {
url = new URL("http://abcl-dynamic-install.googlecode.com/files/baz-20130403a.jar"); url = new URL("http://abcl.org/fasl/42/baz-20140105a-fasl-42.jar");
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
Logger.getLogger(HttpHeadTest.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(HttpHeadTest.class.getName()).log(Level.SEVERE, null, ex);
} }
String key = "Last-Modified"; String key = "Last-Modified";
String expResult = ""; String result = null;
String result = HttpHead.get(url, key); try {
assertEquals(expResult, result); result = HttpHead.get(url, key);
System.out.println("Last-Modifed result was "+ result); } catch (IOException ex) {
fail("The test case is a prototype."); Logger.getLogger(HttpHeadTest.class.getName()).log(Level.SEVERE, null, ex);
}
assertNotNull(result);
System.out.println("Last-Modified result was "+ result);
} }
/**
* Test of main method, of class HttpHead.
*/
@Test @Test
public void testMain() { public void testMain() {
System.out.println("main"); System.out.println("main");
String[] argv = null; String[] argv = {"http://google.com/"};
HttpHead.main(argv); HttpHead.main(argv);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment