Revision: 4698 http://sourceforge.net/p/vexi/code/4698 Author: mkpg2 Date: 2014-05-20 13:19:14 +0000 (Tue, 20 May 2014) Log Message: ----------- Fix. JreHTTP error response. - Was throwing an internal IOException and not a HTTP exception. - Need to use getErrorStream() when reading an error response. Improve. Avoid throwing an IOException when attempting to parse a number, using the lexer method.
Modified Paths: -------------- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSNumber.java branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp branches/vexi3/org.vexi-library.net/src/main/java/org/ibex/net/JreHTTP.java Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSNumber.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSNumber.java 2014-05-15 18:02:33 UTC (rev 4697) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSNumber.java 2014-05-20 13:19:14 UTC (rev 4698) @@ -4,7 +4,6 @@ package org.ibex.js; -import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; @@ -49,11 +48,9 @@ if(formatConst==N_RATIONAL){ n = Rational.tryParse(s); }else{ - n = Lexer.parseNumber(s, true); + n = Lexer.getNumber(s, true); } return JSU.N(n); - }catch(IOException e){ - return null; }catch(NumberFormatException e){ return null; } Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2014-05-15 18:02:33 UTC (rev 4697) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2014-05-20 13:19:14 UTC (rev 4698) @@ -82,8 +82,11 @@ jeObj.putSafe(SC_stream,stream); String mimetype = he.info.contentType; // remove ; charset ... (TODO - verify we have already taken this into account) - if(mimetype.indexOf(";")!=-1) + if(mimetype==null){ + mimetype = "text/plain"; + }else if(mimetype.indexOf(";")!=-1){ mimetype = mimetype.substring(0,mimetype.indexOf(";")); + } jeObj.putSafe(SC_mimetype, JSU.S(mimetype)); return je; } @@ -137,9 +140,9 @@ }else if(js instanceof JSBoolean){ return JSU.N(((JSBoolean)js).toInt()); }else { - try{ - return JSU.N(Lexer.parseNumber(JSU.toString(js), false)); - }catch(IOException e){} + Number n = Lexer.getNumber(JSU.toString(js), false); + if(n!=null) + return JSU.N(n); } return null; } Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp 2014-05-15 18:02:33 UTC (rev 4697) +++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp 2014-05-20 13:19:14 UTC (rev 4698) @@ -26,24 +26,27 @@ /** Lexes a stream of characters into a stream of Tokens */ public class Lexer implements Tokens, Constants { - - static public Number parseNumber(String s, boolean suffixAllowed) throws IOException{ - Lexer l = new Lexer(new StringReader(s), s, 0); - int tok = l.getToken(); - boolean negative = false; - if(tok == Tokens.SUB){ - negative = true; - tok = l.getToken(); + static public Number getNumber(String s, boolean suffixAllowed) { + try{ + Lexer l = new Lexer(new StringReader(s), s, 0); + int tok = l.getToken(); + boolean negative = false; + if(tok == Tokens.SUB){ + negative = true; + tok = l.getToken(); + } + if(tok == Tokens.NUMBER){ + Number r = l.number; + if(!suffixAllowed && l.getToken()!=-1) return null; + if(negative) + r = negateNumber(r); + return r; + }else{ + return null; + } + }catch(IOException e){ + throw new Error(e); } - if(tok == Tokens.NUMBER){ - Number r = l.number; - if(!suffixAllowed && l.getToken()!=-1) throw new IOException(); - if(negative) - r = negateNumber(r); - return r; - }else{ - throw new IOException("Not a valid number: "+s); - } } static public Number negateNumber(Number n){ Modified: branches/vexi3/org.vexi-library.net/src/main/java/org/ibex/net/JreHTTP.java =================================================================== --- branches/vexi3/org.vexi-library.net/src/main/java/org/ibex/net/JreHTTP.java 2014-05-15 18:02:33 UTC (rev 4697) +++ branches/vexi3/org.vexi-library.net/src/main/java/org/ibex/net/JreHTTP.java 2014-05-20 13:19:14 UTC (rev 4698) @@ -1,7 +1,6 @@ package org.ibex.net; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -95,14 +94,14 @@ } public HTTPResponse readResponse(HttpURLConnection connection) throws IOException{ - InputStream is = connection.getInputStream(); int statusCode = connection.getResponseCode(); if(statusCode>=400){ + InputStream is = connection.getErrorStream(); byte[] bytes = IOUtil.toByteArray(is); // HACK doesn't seem to work unless we read this here HTTPEntityInfo info = new HTTPEntityInfo((int)bytes.length,"",connection.getContentType()); throw new HTTPErrorResponse(connection.getResponseMessage(), statusCode+"", bytes, info); }else{ - + InputStream is = connection.getInputStream(); String lastmod = connection.getHeaderField("Last-Modified"); String lengthStr = connection.getHeaderField("Content-Length"); String contentTypeR = connection.getHeaderField("Content-Type"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn