costin 01/06/09 14:29:03
Modified: jasper34/runtime/org/apache/jasper34/runtime
HttpJspBase.java JspRuntimeLibrary.java
Log:
Initial code to use the new line map.
We don't do anything special - this is just the original code that does
the mapping.
Very inefficient ( 2 Writers, Readers, many Srings, linear search ) - it can
be changed later ( possibly in a general purpose util ). This is called only
on error - shouldn't be a frequent operation.
The code should do a println with the detected location in the JSP file
( small bug - the line is 0-based, need to increment it )
Revision Changes Path
1.5 +22 -0
jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/HttpJspBase.java
Index: HttpJspBase.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/HttpJspBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpJspBase.java 2001/06/08 05:41:14 1.4
+++ HttpJspBase.java 2001/06/09 21:29:02 1.5
@@ -129,6 +129,10 @@
out=pageContext.getOut();
_jspService(pageContext, request, response );
} catch (Exception ex) {
+ // Experimental/test line mappings
+ JspRuntimeLibrary.handleExceptionMapping( this,
+ ex );
+
if (pageContext != null)
pageContext.handlePageException(ex);
} catch (Error error) {
@@ -183,6 +187,24 @@
}
+ /** Return extra dependencies for this file ( TLDs, included files )
+ */
public String[] _getDepends() { return null; }
+
+ /** Return the static chunks to be used with sendChunk()
+ */
public String[] _getChunks() { return null; }
+
+ /** line mapping - the files used in lineMap
+ */
+ public String[] _getFileMap() { return null; }
+
+ /** Line map.
+ { java_start, java_end,
+ jsp_file_start_idx, jsp_file_start_line, jsp_file_start_col,
+ jsp_file_end_idx, jsp_file_end_line, jsp_file_end_col
+ }
+ @see GeneratorBase.generateLineMap
+ */
+ public int[][] _getLineMap() { return null; }
}
1.4 +86 -10
jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/JspRuntimeLibrary.java
Index: JspRuntimeLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/JspRuntimeLibrary.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JspRuntimeLibrary.java 2001/05/28 06:48:15 1.3
+++ JspRuntimeLibrary.java 2001/06/09 21:29:02 1.4
@@ -64,19 +64,14 @@
import java.lang.reflect.Method;
-import java.io.Writer;
-import java.io.Reader;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.*;
import java.beans.PropertyDescriptor;
import java.beans.IndexedPropertyDescriptor;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.jsp.*;
//import org.apache.jasper.JasperException;
@@ -651,7 +646,88 @@
methods.put( prop, method );
return method;
}
-
+
+ public static void handleExceptionMapping( HttpJspBase jsp,
+ Throwable ex )
+ {
+ int map[][]=jsp._getLineMap();
+ String fmap[]=jsp._getFileMap();
+
+ if( map==null ) return;
+
+
+ String trace=getTrace( ex );
+ if( trace==null ) return;
+
+ String classN=jsp.getClass().getName();
+
+ //log( "Trace " + trace );
+ //log("Finding " + classN );
+
+ try {
+ BufferedReader br=new BufferedReader(new StringReader( trace ));
+ String line;
+ while( true ) {
+ line=br.readLine();
+ if(line==null ) break;
+
+ if( line.indexOf( classN ) < 0 ) {
+ // log( "Not Found " + line );
+ continue;
+ }
+ //log( "Found " + line );
+ int col=line.indexOf( ':' );
+ int end=line.indexOf(')' );
+ if( col<0 || end<0 ) break;
+
+ String nr=line.substring( col+1, end );
+ int lineNr= Integer.parseInt( nr );
+ // Now do the mapping
+ //log( "Java line number " + lineNr + " " + map );
+ int mapping[]= findMapping( map, lineNr );
+ if( mapping== null ) return;
+ log( "JSP location: " +
+ fmap[mapping[2]] + ":" + mapping[3] );
+ }
+ br.close();
+ } catch( Exception ex1 ) {
+ ex1.printStackTrace();
+ }
+ }
+
+ // Linear search - this happens only on error, and we're
+ // still experimenting
+ private static int[] findMapping( int map[][], int lineNr ) {
+ if( map==null ) return null;
+ for( int i=map.length-1; i>=0; i-- ) {
+ if( map[i] == null ) continue;
+ if( map[i][0] <= lineNr &&
+ map[i][1] > lineNr ) {
+ return map[i];
+ }
+ //log( "Not found " + map[i][0] + " " + map[i][1] );
+ }
+ return null;
+ }
+
+ public static String getTrace( Throwable ex ) {
+ try {
+ StringWriter traceWriter=new StringWriter();
+ PrintWriter traceWriterPW=new PrintWriter( traceWriter );
+
+ ex.printStackTrace( traceWriterPW );
+ traceWriterPW.flush();
+ String trace=traceWriter.toString();
+ traceWriterPW.close();
+ return trace;
+ } catch( Exception ex1 ) {
+ return null;
+ }
+ }
+
+ private static void log(String s ) {
+ System.out.println("JspRuntimeLibrary: " + s );
+ }
}