ASF Bugzilla – Attachment 29244 Details for
Bug 53713
Performance tuning solution for JspReader
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Comparison test case for JspReader
TestJspReader.java (text/plain), 6.12 KB, created by
Sheldon Shao
on 2012-08-17 14:31:30 UTC
(
hide
)
Description:
Comparison test case for JspReader
Filename:
MIME Type:
Creator:
Sheldon Shao
Created:
2012-08-17 14:31:30 UTC
Size:
6.12 KB
patch
obsolete
>package org.apache.jasper.compiler; > >import java.io.BufferedInputStream; >import java.io.File; >import java.io.FileInputStream; >import java.io.InputStreamReader; > >import org.apache.catalina.startup.Tomcat; >import org.apache.catalina.startup.TomcatBaseTest; >import org.apache.jasper.JasperException; >import org.junit.Test; > >public class TestJspReader extends TomcatBaseTest { > > private static String[] folders = new String[] { "test/webapp-2.3", > "test/webapp-2.4", "test/webapp-2.5", "test/webapp-3.0", > "test/webapp-3.0-fragments", > "test/webapp-3.0-servletsecurity2", > "test/webapp-3.0-virtual-webapp" }; > > > @Test > public void testSkipUntil() throws Exception { > for(String folder: folders) { > doWebapp(folder); > } > } > > private void doWebapp(String folder) throws Exception { > Tomcat tomcat = getTomcatInstance(); > > File appDir = new File(folder); > tomcat.addWebapp(null, "/" + appDir.getName(), appDir.getAbsolutePath()); > tomcat.start(); > > int count = 1000; > long start = System.currentTimeMillis(); > for(int i = 0; i < count; i ++) { > goThroughAllJsp(appDir, true); > } > System.out.println("Webapp " + folder + " New JspReader:" > + (System.currentTimeMillis() - start)); > start = System.currentTimeMillis(); > for(int i = 0; i < count; i ++) { > goThroughAllJsp(appDir, false); > } > System.out.println("Webapp " + folder + " Old JspReader:" > + (System.currentTimeMillis() - start)); > } > > private void goThroughAllJsp(File appDir, boolean newJspReader) { > File[] files = appDir.listFiles(); > for (File file : files) { > if (file.isDirectory()) { > goThroughAllJsp(file, newJspReader); > } else if (file.getName().endsWith(".jsp")) { > try { > if (newJspReader) { > read(file); > } else { > oldRead(file); > } > } catch (Exception ex) { > } > } > } > } > > /* > * Checks to see if the given page contains, as its first element, a <root> > * element whose prefix is bound to the JSP namespace, as in: > * > * <wombat:root xmlns:wombat="http://java.sun.com/JSP/Page" version="1.2"> > * ... </wombat:root> > * > * @param reader The reader for this page > * > * @return true if this page contains a root element whose prefix is bound > * to the JSP namespace, and false otherwise > */ > private boolean hasJspRoot(JspReader reader) throws JasperException { > > // <prefix>:root must be the first element > Mark start = null; > while ((start = reader.skipUntil("<")) != null) { > int c = reader.nextChar(); > if (c != '!' && c != '?') > break; > } > if (start == null) { > return false; > } > Mark stop = reader.skipUntil(":root"); > if (stop == null) { > return false; > } > // call substring to get rid of leading '<' > String prefix = reader.getText(start, stop).substring(1); > > start = stop; > stop = reader.skipUntil(">"); > if (stop == null) { > return false; > } > > // Determine namespace associated with <root> element's prefix > String root = reader.getText(start, stop); > String xmlnsDecl = "xmlns:" + prefix; > int index = root.indexOf(xmlnsDecl); > if (index == -1) { > return false; > } > index += xmlnsDecl.length(); > while (index < root.length() > && Character.isWhitespace(root.charAt(index))) { > index++; > } > if (index < root.length() && root.charAt(index) == '=') { > index++; > while (index < root.length() > && Character.isWhitespace(root.charAt(index))) { > index++; > } > if (index < root.length() > && (root.charAt(index) == '"' || root.charAt(index) == '\'')) { > index++; > if (root.regionMatches(index, TagConstants.JSP_URI, 0, > TagConstants.JSP_URI.length())) { > return true; > } > } > } > > return false; > } > > /* > * Checks to see if the given page contains, as its first element, a <root> > * element whose prefix is bound to the JSP namespace, as in: > * > * <wombat:root xmlns:wombat="http://java.sun.com/JSP/Page" version="1.2"> > * ... </wombat:root> > * > * @param reader The reader for this page > * > * @return true if this page contains a root element whose prefix is bound > * to the JSP namespace, and false otherwise > */ > private boolean hasJspRoot(OldJspReader reader) throws JasperException { > > // <prefix>:root must be the first element > OldMark start = null; > while ((start = reader.skipUntil("<")) != null) { > int c = reader.nextChar(); > if (c != '!' && c != '?') > break; > } > if (start == null) { > return false; > } > OldMark stop = reader.skipUntil(":root"); > if (stop == null) { > return false; > } > // call substring to get rid of leading '<' > String prefix = reader.getText(start, stop).substring(1); > > start = stop; > stop = reader.skipUntil(">"); > if (stop == null) { > return false; > } > > // Determine namespace associated with <root> element's prefix > String root = reader.getText(start, stop); > String xmlnsDecl = "xmlns:" + prefix; > int index = root.indexOf(xmlnsDecl); > if (index == -1) { > return false; > } > index += xmlnsDecl.length(); > while (index < root.length() > && Character.isWhitespace(root.charAt(index))) { > index++; > } > if (index < root.length() && root.charAt(index) == '=') { > index++; > while (index < root.length() > && Character.isWhitespace(root.charAt(index))) { > index++; > } > if (index < root.length() > && (root.charAt(index) == '"' || root.charAt(index) == '\'')) { > index++; > if (root.regionMatches(index, TagConstants.JSP_URI, 0, > TagConstants.JSP_URI.length())) { > return true; > } > } > } > > return false; > } > > public void oldRead(File jsp) throws Exception { > FileInputStream fis = new FileInputStream(jsp); > BufferedInputStream bis = new BufferedInputStream(fis); > InputStreamReader isr = new InputStreamReader(bis, "UTF-8"); > OldJspReader jspReader = new OldJspReader(null, jsp.getAbsolutePath(), > "UTF-8", isr, null); > jspReader.setSingleFile(true); > if (hasJspRoot(jspReader)) { > } > isr.close(); > } > > public void read(File jsp) throws Exception { > FileInputStream fis = new FileInputStream(jsp); > BufferedInputStream bis = new BufferedInputStream(fis); > InputStreamReader isr = new InputStreamReader(bis, "UTF-8"); > JspReader jspReader = new JspReader(null, jsp.getAbsolutePath(), > "UTF-8", isr, null); > jspReader.setSingleFile(true); > if (hasJspRoot(jspReader)) { > } > isr.close(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 53713
:
29223
|
29224
|
29242
|
29243
| 29244 |
29245
|
29246