Package javassist.tools.web
Class Webserver
java.lang.Object
javassist.tools.web.Webserver
- Direct Known Subclasses:
AppletServer
A web server for running sample programs.
This enables a Java program to instrument class files loaded by web browsers for applets. Since the (standard) security manager does not allow an applet to create and use a class loader, instrumenting class files must be done by this web server.
Note: although this class is included in the Javassist API, it is provided as a sample implementation of the web server using Javassist. Especially, there might be security flaws in this server. Please use this with YOUR OWN RISK.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClassPoolIf this field is not null, the class files taken fromClassPoolare written out under the directory specified by this field.private static final byte[]The top directory of html (and .gif, .class, ...) files.private ServerSocketprotected Translatorprivate static final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTranslator(ClassPool cp, Translator t) Adds a translator, which is called whenever a client requests a class file.private voidcheckFilename(String filename, int len) voiddoReply(InputStream in, OutputStream out, String cmd) Proceses a HTTP request from a client.voidend()Closes the socket.private booleanletUsersSendClassfile(OutputStream out, String filename, int length) voidPrints a log message.voidPrints a log message.voidPrints a log message.voidPrints a log message with indentation.static voidStarts a web server.(package private) final voidprivate StringreadLine(InputStream in) private voidreplyError(OutputStream out, BadHttpRequest e) voidrun()Begins the HTTP service.private voidsendHeader(OutputStream out, long dataLength, int filetype) voidsetClassPool(ClassPool loader) Requests the web server to use the specifiedClassPoolobject for obtaining a class file.private intskipLine(InputStream in)
-
Field Details
-
socket
-
classPool
-
translator
-
endofline
private static final byte[] endofline -
typeHtml
private static final int typeHtml- See Also:
-
typeClass
private static final int typeClass- See Also:
-
typeGif
private static final int typeGif- See Also:
-
typeJpeg
private static final int typeJpeg- See Also:
-
typeText
private static final int typeText- See Also:
-
debugDir
If this field is not null, the class files taken fromClassPoolare written out under the directory specified by this field. The directory name must not end with a directory separator. -
htmlfileBase
The top directory of html (and .gif, .class, ...) files. It must end with the directory separator such as "/". (For portability, "/" should be used as the directory separator. Javassist automatically translates "/" into a platform-dependent character.) If this field is null, the top directory is the current one where the JVM is running.If the given URL indicates a class file and the class file is not found under the directory specified by this variable, then
Class.getResourceAsStream()is called for searching the Java class paths.
-
-
Constructor Details
-
Webserver
Constructs a web server.- Parameters:
port- port number- Throws:
IOException
-
Webserver
Constructs a web server.- Parameters:
port- port number- Throws:
IOException
-
-
Method Details
-
main
Starts a web server. The port number is specified by the first argument.- Throws:
IOException
-
setClassPool
Requests the web server to use the specifiedClassPoolobject for obtaining a class file. -
addTranslator
public void addTranslator(ClassPool cp, Translator t) throws NotFoundException, CannotCompileException Adds a translator, which is called whenever a client requests a class file.- Parameters:
cp- theClassPoolobject for obtaining a class file.t- a translator.- Throws:
NotFoundExceptionCannotCompileException
-
end
Closes the socket.- Throws:
IOException
-
logging
Prints a log message. -
logging
Prints a log message. -
logging
Prints a log message. -
logging2
Prints a log message with indentation. -
run
public void run()Begins the HTTP service. -
process
- Throws:
IOException
-
readLine
- Throws:
IOException
-
skipLine
- Throws:
IOException
-
doReply
public void doReply(InputStream in, OutputStream out, String cmd) throws IOException, BadHttpRequest Proceses a HTTP request from a client.- Parameters:
out- the output stream to a clientcmd- the command received from a client- Throws:
IOExceptionBadHttpRequest
-
checkFilename
- Throws:
BadHttpRequest
-
letUsersSendClassfile
private boolean letUsersSendClassfile(OutputStream out, String filename, int length) throws IOException, BadHttpRequest - Throws:
IOExceptionBadHttpRequest
-
sendHeader
- Throws:
IOException
-
replyError
- Throws:
IOException
-