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
System.err.println(s);
}
@SuppressWarnings("CallToThreadDumpStack")
public static final void trace(Throwable t)
{
t.printStackTrace();
}
public static final void trace(String message, Throwable t)
{
trace(message);
trace(t);
}
public static final Symbol _DEBUG_WARN_
= exportSpecial("*DEBUG-WARN*", PACKAGE_SYS, NIL);
......
......@@ -164,7 +164,12 @@ public class ZipCache {
// implementation only looking for Last-Modified
// headers, which if we don't find, we give up and
// 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;
ParsePosition pos = new ParsePosition(0);
......
......@@ -37,6 +37,7 @@ import org.armedbear.lisp.Debug;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
......@@ -48,7 +49,7 @@ import java.net.URL;
* Use HTTP/1.1 HEAD to retrieve the specified header field.
*/
public class HttpHead {
static private String get(String urlString, String key) {
static private String get(String urlString, String key) throws IOException {
URL url = null;
try {
url = new URL(urlString);
......@@ -58,7 +59,7 @@ public class HttpHead {
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;
String result = null;
try {
......@@ -67,37 +68,30 @@ public class HttpHead {
log("The protocol " + "'" + protocol + "'" + " is not http.");
return result;
}
socket = new Socket(Proxy.NO_PROXY); // XXX add Proxy
String host = url.getHost();
int port = url.getPort();
if (port == -1) {
port = 80;
}
InetSocketAddress address = new InetSocketAddress(url.getHost(), port);
try {
socket.connect(address, 5000); // ??? too long? too short?
} catch (IOException ex) {
log("Connection failed: " + ex);
return result;
}
socket = new Socket(host, port);
PrintWriter out = null;
BufferedReader in = null;
try {
socket.setSoTimeout(5000); // ms
out = new PrintWriter(socket.getOutputStream());
out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
log("Failed to establish socket io: " + e);
return result;
}
String CRLF = "\r\n";
String head = "HEAD " + url.getPath() + " HTTP/1.1";
out.println(head);
out.println("Host: " + url.getAuthority());
out.println("Connection: close");
out.println("");
out.print(head + CRLF);
out.print("Host: " + url.getAuthority() + CRLF);
out.print("Connection: close" + CRLF);
out.print(CRLF);
out.flush();
String line = null;
......@@ -106,6 +100,9 @@ public class HttpHead {
} catch (IOException 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");
if (status[1].equals("200")) {
result = findHeader(in, key);
......@@ -158,7 +155,13 @@ public class HttpHead {
System.out.println("Usage: <cmd> URL");
return;
}
String modified = get(argv[0], "Last-Modified");
String modified = null;
try {
modified = get(argv[0], "Last-Modified");
} catch (IOException ex) {
System.err.println("Unable to get Last-Modified header: ");
ex.printStackTrace(System.err);
}
if (modified != null) {
System.out.println("Last-Modified: " + modified);
} else {
......
......@@ -149,7 +149,7 @@ Returns the two values of the pathnames of the created archives."
(load-from-jar *tmp-jar-path* "eek")
t)
çu(deftest jar-pathname.load.5
(deftest jar-pathname.load.5
(load-from-jar *tmp-jar-path* "eek.lisp")
t)
......@@ -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))))
;;; 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
(deftest jar-pathname.load.http.1
(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;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
......@@ -17,10 +12,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author evenson
*/
public class HttpHeadTest {
public HttpHeadTest() {
......@@ -42,36 +33,30 @@ public class HttpHeadTest {
public void tearDown() {
}
/**
* Test of get method, of class HttpHead.
*/
@Test
public void testGet() {
System.out.println("get");
URL url = null;
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) {
Logger.getLogger(HttpHeadTest.class.getName()).log(Level.SEVERE, null, ex);
}
String key = "Last-Modified";
String expResult = "";
String result = HttpHead.get(url, key);
assertEquals(expResult, result);
System.out.println("Last-Modifed result was "+ result);
fail("The test case is a prototype.");
String result = null;
try {
result = HttpHead.get(url, key);
} catch (IOException ex) {
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
public void testMain() {
System.out.println("main");
String[] argv = null;
String[] argv = {"http://google.com/"};
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