国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp預(yù)編譯工具

2024-09-05 00:20:30
字體:
供稿:網(wǎng)友

一個可以進行jsp預(yù)編譯工作的程序. 下面是read.me 以及 java 源程序.
author: ugorji dick-nwoke [email protected]
date: jan 16. 2002

---------------------------------------------------
post server startup jsp file compiler and validator
---------------------------------------------------
this utility helps to
1. simulate a precompilation of jsp´s after the server
has already started up.
this way, we do not have to wait for all the jsp´s to be precompiled
before starting up the server.
2. test the validity of all the jsp´s. if any jsp does not compile, a
response code of 500 is returned. the tool lists that jsp, so it can
be worked on.

the list of jsp targets to be precompiled must be supplied in a plain
text file.

a sample is below:
#---------------------------------------------
/console/index.jsp
/console/standards/home.jsp
#---------------------------------------------

all the targets defined in there a hit sequentially, the response code
monitored and such information relayed to the user.

usage:
java testjspfiles <fname>

if you specify no parameters, this help will be displayed
at least one parameter, the filename should be specified

below simulates the default argument list (if no parameters are passed in)
jsp-pages.txt

if form based authentication is required, then send the username and parameters

system properties, passed using the -d flag, are used to set the argument
list. they are listed below:
host the hostname or ip address of the machine
port the port the server is listening on
debug if true, extra information like the actual output string
is written to std error stream
if authentication is required to view some of the pages, the following
will be required.
username the username to login as
password the password for that user
formauthtarget the j_security_check target. by default, it is
/j_security_check. it can be specified as the login
page may vary.

sample usage is below:
java
-ddebug=false
-dhost=localhost
-dport=7701
-dusername=system
-dpassword=system_password
-dformauthtarget=/console/login/j_security_check
testjspfiles
jsp-pages.txt

at the end, we tell you how many pages were ok (returned 200)
and how many were broken (including list of broken pages).
this will help you know which pages are broken immediately.

any pages already precompiled will not precompile again.
thus, there is no performance hit on running this script
multiple times.

**** note ****
the file passed should have the full path of pages to precompile
example scenario:
webapp context-path is /console
to precompile the jsp pages, index.jsp and standards/home.jsp in there
file should be as below
#---------------------------------------------
/console/index.jsp
/console/standards/home.jsp

#---------------------------------------------

enjoy. - ugorji [email protected]

// package weblogic.qa.taskmgr;

import java.util.*;
import java.io.*;
import java.net.*;


/**
* precompiles all the jsp and tell us which are broken
* <xmp>to see usage information: java weblogic.qa.taskmgr.testjspfiles</xmp>
* fname is the list of files with the paths of jsp files to precompile
* host and port are the server host and port respectively
*
* currently, this is only geared towards form-based authenticated sites
*
* @author ugorji dick-nwoke [email protected]
* @version 1.0, august 3, 2001
*/
public class testjspfiles
{
private static string help_message = null;

public boolean debug = false;
public list jspfiles;
public string host;
public int port;
public string username;
public string password;
public string cookiestring;
public string formauthtarget = "/j_security_check";

// set the help message
static {
string lsep = system.getproperty ("line.separator");
help_message =
"usage: " + lsep +
"java [-dhost=] [-dport=] [-dusername=] [-dpassword=] [-dformauthtarget=] testjspfiles <fname> " + lsep +
"defaults:" + lsep +
" -dhost=localhost" + lsep +
" -dport=80" + lsep +
" -dusername=" + lsep +
" -dpassword=" + lsep +
" -dformauthtarget=/j_security_check" + lsep +
" file should be of the form below:" + lsep +
"#---------------------------------------------" + lsep +
"/console/index.jsp" + lsep +
"/console/standards/home.jsp" + lsep +
"#---------------------------------------------" + lsep +
"";
}

public string tostring () {
string s = host + ":" + port + " [user/pass=" + username + "/" + password + "]";
return s;
}

public void run ()
throws exception
{
cookiestring = getcookiestring ();
if (debug) system.err.println (cookiestring);
list badfiles = new arraylist ();
list goodfiles = new arraylist ();
int numgood = 0;
int numbad = 0;

int sz = jspfiles.size ();
for (int i = 0; i < sz; i++) {
string file = null;
try {
file = (string) jspfiles.get (i);
int respcode = getresponsecode (file);
if (respcode == 200) {
system.out.println ("good: " + file + " --- got respcode " + respcode);
goodfiles.add (file);
numgood++;
}
else {
system.out.println ("error: " + file + " --- got respcode " + respcode);
badfiles.add (file);
numbad++;
}
}
catch (exception exc) {
system.out.println ("error: " + file + " --- got exception " + exc);
badfiles.add (file);
numbad++;
}
if (debug) {
system.err.println ("=============================================");
}
}

// output stats
system.out.println ("good files: " + numgood);
system.out.println ("bad files: " + numbad);
system.out.println ("---------------------------------------");
for (int i = 0; i < numbad; i++) {
system.out.println (badfiles.get (i) );
}

}

public int getresponsecode (string file)
throws exception
{
int respcode = -1;
socket s = new socket (host, port);
printwriter out = new printwriter( new outputstreamwriter( s.getoutputstream() ) );
string target = file + "?jsp_precompile=true";
out.print ("get " + target + " http/1.0" + " ");
out.print ("cookie: " + cookiestring + " ");
out.print ("connection: close ");
out.print ("host: " + host + " ");
out.print (" ");
out.flush ();
bufferedreader buffreader = new bufferedreader( new inputstreamreader( s.getinputstream() ) );
string line = buffreader.readline();
if( line != null ) {
stringtokenizer st = new stringtokenizer( line.trim() );
st.nexttoken();
respcode = integer.parseint (st.nexttoken());
}
while( (line = buffreader.readline()) != null ) {
if( line.trim().length() == 0 ) break;
}
stringbuffer buf = new stringbuffer ();
while( (line = buffreader.readline()) != null ) {
buf.append (line).append (" ");
}
if (debug) {
system.err.println (target);
system.err.println (respcode);
system.err.println (buf.tostring () );
}
buffreader.close ();
out.close ();
s.close ();
return respcode;
}

public string getcookiestring ()
throws exception
{
string cookieline = null;
string c = null;
socket s = new socket (host, port);
printwriter out = new printwriter( new outputstreamwriter( s.getoutputstream() ) );
string target = formauthtarget;
// out = new printwriter (system.out, true);
out.print ("post " + target + " http/1.0" + " ");
out.print ("connection: close ");
out.print ("host: " + host + " ");
out.print ("content-type: application/x-www-form-urlencoded " );
string poststring = "j_username=" + username + "&j_password=" + password;
out.print ("content-length: " + poststring.length() + " " );
out.print (" ");
out.print (poststring + " " );
out.print (" ");
out.flush ();
bufferedreader buffreader = new bufferedreader( new inputstreamreader( s.getinputstream() ) );
string line = null;
while( (line = buffreader.readline()) != null ) {
if (debug) system.err.println (line);
if( line.trim().length() == 0 ) break;
if( line.tolowercase().startswith( "set-cookie:" ) ) {
cookieline = line.substring( "set-cookie:".length() ).trim();
int semicolon = cookieline.indexof( ";" );
if( semicolon != -1 ) {
cookieline = cookieline.substring( 0, semicolon ).trim();
}
break;
}
}
buffreader.close ();
out.close ();
s.close ();
return cookieline;
}

public int getresponsecode0 (string file)
throws exception
{
httpurlconnection urlconn = null;
try {
string target = file + "?jsp_precompile=true";
url url = new url ("http", host, port, target);
urlconn = (httpurlconnection) url.openconnection ();
urlconn.connect ();
// inputstream is = urlconn.getinputstream ();
// while ( is.read (b) != -1 ) { }
int respcode = urlconn.getresponsecode ();
return respcode;
}
finally {
try { if (urlconn != null) urlconn.disconnect (); }
catch (exception exc2) { }
}
}

/** <xmp>usage: java weblogic.qa.taskmgr.testjspfiles <fname> <host> <port> </xmp> */
public static void main (string[] args)
throws exception
{
if (args.length == 0) {
system.out.println (help_message);
system.exit (0);
}

string fname = "jsp-pages.txt";
string thost = "localhost";
int tport = 80;
string tuser = null;
string tpass = null;
string tformauthtarget = "/j_security_check";
boolean tdebug = false;

string tmpstr = null;
if ( (tmpstr = system.getproperty ("host") ) != null)
thost = tmpstr;
if ( (tmpstr = system.getproperty ("port") ) != null)
tport = integer.parseint (tmpstr);
if ( (tmpstr = system.getproperty ("username") ) != null)
tuser = tmpstr;
if ( (tmpstr = system.getproperty ("password") ) != null)
tpass = tmpstr;
if ("true".equals (system.getproperty ("debug")) )
tdebug = true;
if ( (tmpstr = system.getproperty ("formauthtarget") ) != null)
tformauthtarget = tmpstr;

if (args.length > 0)
fname = args [0];
if (args.length > 1)
thost = args [1];
if (args.length > 2)
tport = integer.parseint (args [2]);
if (args.length > 3)
tuser = args [3];
if (args.length > 4)
tpass = args [4];

filereader fr = new filereader (fname);
bufferedreader br = new bufferedreader (fr);
list files = new arraylist ();
string line = null;
while ( (line = br.readline () ) != null ) {
line = line.trim ();
if (line.length() == 0 || line.startswith ("#") )
continue;
files.add (line);
}
fr.close ();
br.close ();

testjspfiles test = new testjspfiles ();
test.host = thost;
test.port = tport;
test.jspfiles = files;
test.username = tuser;
test.password = tpass;
test.formauthtarget = tformauthtarget;
test.debug = tdebug;

system.out.println ("file&: " + fname);
system.out.println ("testjspfiles: " + test);
test.run ();

}


}

# top level files
/console/index.jsp
/console/help.jsp

# other stuff
/webapp1/thankyou.jsp
/webapp2/thankyou2.jsp
 



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 永济市| 云和县| 恩平市| 张北县| 淳化县| 大竹县| 荣成市| 泰兴市| 海宁市| 成都市| 邮箱| 嘉禾县| 无为县| 永福县| 闻喜县| 海兴县| 祁门县| 郯城县| 法库县| 两当县| 娄烦县| 定安县| 登封市| 桐庐县| 陵水| 新蔡县| 徐水县| 平和县| 湖南省| 衡南县| 武隆县| 沈阳市| 新河县| 姚安县| 巫山县| 平谷区| 荣成市| 广元市| 库伦旗| 成都市| 错那县|