public class Webserver extends Object
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.
Modifier and Type | Field and Description |
---|---|
String |
debugDir
If this field is not null, the class files taken from
ClassPool are written out under the directory
specified by this field. |
String |
htmlfileBase
The top directory of html (and .gif, .class, ...) files.
|
protected Translator |
translator |
Constructor and Description |
---|
Webserver(int port)
Constructs a web server.
|
Webserver(String port)
Constructs a web server.
|
Modifier and Type | Method and Description |
---|---|
void |
addTranslator(ClassPool cp,
Translator t)
Adds a translator, which is called whenever a client requests
a class file.
|
void |
doReply(InputStream in,
OutputStream out,
String cmd)
Proceses a HTTP request from a client.
|
void |
end()
Closes the socket.
|
void |
logging(String msg)
Prints a log message.
|
void |
logging(String msg1,
String msg2)
Prints a log message.
|
void |
logging(String msg1,
String msg2,
String msg3)
Prints a log message.
|
void |
logging2(String msg)
Prints a log message with indentation.
|
static void |
main(String[] args)
Starts a web server.
|
void |
run()
Begins the HTTP service.
|
void |
setClassPool(ClassPool loader)
Requests the web server to use the specified
ClassPool object for obtaining a class file. |
protected Translator translator
public String debugDir
ClassPool
are written out under the directory
specified by this field. The directory name must not end
with a directory separator.public String htmlfileBase
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.
public Webserver(String port) throws IOException
port
- port numberIOException
public Webserver(int port) throws IOException
port
- port numberIOException
public static void main(String[] args) throws IOException
IOException
public void setClassPool(ClassPool loader)
ClassPool
object for obtaining a class file.public void addTranslator(ClassPool cp, Translator t) throws NotFoundException, CannotCompileException
cp
- the ClassPool
object for obtaining
a class file.t
- a translator.NotFoundException
CannotCompileException
public void end() throws IOException
IOException
public void logging(String msg)
public void logging2(String msg)
public void run()
public void doReply(InputStream in, OutputStream out, String cmd) throws IOException, BadHttpRequest
out
- the output stream to a clientcmd
- the command received from a clientIOException
BadHttpRequest
Copyright © 2019. All rights reserved.