Revision: 3337
http://vexi.svn.sourceforge.net/vexi/?rev=3337&view=rev
Author: mkpg2
Date: 2009-01-04 05:24:45 +0000 (Sun, 04 Jan 2009)
Log Message:
-----------
Fix. When reading a streams info (if progress traps are set) was doing a get
instead of using the stream from the post's response.
Modified Paths:
--------------
trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java
trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
Added Paths:
-----------
trunk/core/org.ibex.js/src_junit/test/js/exec/http/post3.js
Modified: trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java 2009-01-04
04:02:18 UTC (rev 3336)
+++ trunk/core/org.ibex.js/src/org/ibex/js/Fountain.java 2009-01-04
05:24:45 UTC (rev 3337)
@@ -182,6 +182,7 @@
public static class HTTP extends Fountain{
private String url;
private HTTPInputStream lastResponse;
+ private JS lastInfo;
private org.ibex.net.HTTP http(){ return new org.ibex.net.HTTP(url);}
public String canonical() { return url; }
public HTTP(String url) {
@@ -189,28 +190,36 @@
this.url = url;
}
public JS _get(JS key) throws JSExn { return new HTTP(url + "/" +
JSU.toString(key)); }
- public JS getInfo() throws IOException {
+ private JS readInfo(HTTPInputStream is){
JS.Obj r = new JS.Obj();
- // FIXME - this cast can break (if stream is zipped)
- // remember the stream (we only want it here for its properties)
- lastResponse = (HTTPInputStream) http().GET(null, null);
try {
- r.put(SC_lastModified,
JSU.S(lastResponse.getLastModified()));
- r.put(SC_length, JSU.N(lastResponse.getLength()));
+ r.put(SC_lastModified, JSU.S(is.getLastModified()));
+ r.put(SC_length, JSU.N(is.getLength()));
r.put(SC_name, JSU.S(url));
}catch(JSExn e){
- // only supported by Java 6
- //throw new IOException(e);
- throw new IOException(e.getMessage());
+ // should not be possible
+ throw new Error(e);
}
return r;
}
+
+ public JS getInfo() throws IOException {
+ if(lastInfo==null){
+ lastResponse = (HTTPInputStream) http().GET(null, null);
+ lastInfo = readInfo(lastResponse);
+ }
+ return lastInfo;
+ }
//public String getCacheKey(Vec path) throws NotCacheableException {
return url; }
public InputStream _getInputStream() throws IOException {
- if(lastResponse!=null)
- try{ return lastResponse;}
- finally{lastResponse=null;}
- return http().GET(null, null); }
+ if(lastResponse==null){
+ lastResponse = (HTTPInputStream) http().GET(null, null);
+ lastInfo = readInfo(lastResponse);
+ }
+ InputStream r = lastResponse;
+ lastResponse = null;
+ return r;
+ }
/*public InputStream getHeadInputStream() throws IOException {
try{return http.HEAD(null, null);}
// if the server doesn't support HTTP/HEAD fallback to get
@@ -224,6 +233,7 @@
public void close() throws IOException {
// HACK - hardcode mime type
lastResponse= (HTTPInputStream)
http().POST("test/xml", toByteArray(), null, null);
+ lastInfo = readInfo(lastResponse);
}
};
return r;
Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
2009-01-04 04:02:18 UTC (rev 3336)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/http/TestHTTP.java
2009-01-04 05:24:45 UTC (rev 3337)
@@ -44,7 +44,7 @@
static public void main(String[] args) throws Throwable {
before();
JSTestSuite jts = new TestHTTP();
- TestCase t = jts.createTestCase(jts.getResourceDirs(), "post2.js");
+ TestCase t = jts.createTestCase(jts.getResourceDirs(), "post3.js");
t.run();
after();
}
Added: trunk/core/org.ibex.js/src_junit/test/js/exec/http/post3.js
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/http/post3.js
(rev 0)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/http/post3.js 2009-01-04
05:24:45 UTC (rev 3337)
@@ -0,0 +1,11 @@
+ sys.import("shared");
+ var ss = sys.stream.url("http://localhost:9999/capitalize");
+ ss.progress ++= function(v){ }
+ sys.stream.utf8writer(ss).write("abc");
+
+ var r = sys.stream.utf8reader(ss).all;
+
+ sys.log.warn(r.length);
+ assertEquals("ABC",r);
+
+
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn