Additional top-level class in compilation unit: ServiceThread.
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 |
|---|---|
| private ClassPool | |
| public String | debugDir
If this field is not null, the class files taken from
|
| private static final byte[] | |
| public String | htmlfileBase
The top directory of html (and .gif, .class, ...) files. |
| private ServerSocket | |
| protected Translator | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addTranslator(ClassPool
the cp, Translator ClassPool object for obtaining
a class file.a translator. t)Adds a translator, which is called whenever a client requests a class file. |
| private void | |
| public void | doReply(InputStream in, OutputStream
the output stream to a client out, String the command received from a client cmd)Proceses a HTTP request from a client. |
| public void | |
| private boolean | |
| public void | |
| public void | |
| public void | |
| public void | |
| public static void | |
| pack-priv final void | |
| private String | |
| private void | |
| public void | |
| private void | |
| public void | setClassPool(ClassPool loader)
Requests the web server to use the specified
|
| private int |
| classPool | back to summary |
|---|---|
| private ClassPool classPool | |
| debugDir | back to summary |
|---|---|
| public String debugDir If this field is not null, the class files taken from
| |
| endofline | back to summary |
|---|---|
| private static final byte[] endofline | |
| htmlfileBase | back to summary |
|---|---|
| public String 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 | |
| socket | back to summary |
|---|---|
| private ServerSocket socket | |
| translator | back to summary |
|---|---|
| protected Translator translator | |
| typeClass | back to summary |
|---|---|
| private static final int typeClass | |
| typeGif | back to summary |
|---|---|
| private static final int typeGif | |
| typeHtml | back to summary |
|---|---|
| private static final int typeHtml | |
| typeJpeg | back to summary |
|---|---|
| private static final int typeJpeg | |
| typeText | back to summary |
|---|---|
| private static final int typeText | |
| Webserver | back to summary |
|---|---|
| public Webserver(String port) throws IOException Constructs a web server.
| |
| Webserver | back to summary |
|---|---|
| public Webserver(int port) throws IOException Constructs a web server.
| |
| addTranslator | back to summary |
|---|---|
| public void addTranslator(ClassPool cp, Translator t) throws NotFoundException, CannotCompileException Adds a translator, which is called whenever a client requests a class file.
| |
| checkFilename | back to summary |
|---|---|
| private void checkFilename(String filename, int len) throws BadHttpRequest | |
| doReply | back to summary |
|---|---|
| public void doReply(InputStream in, OutputStream out, String cmd) throws IOException, BadHttpRequest Proceses a HTTP request from a client.
| |
| end | back to summary |
|---|---|
| public void end() throws IOException Closes the socket. | |
| letUsersSendClassfile | back to summary |
|---|---|
| private boolean letUsersSendClassfile(OutputStream out, String filename, int length) throws IOException, BadHttpRequest | |
| logging | back to summary |
|---|---|
| public void logging(String msg) Prints a log message. | |
| logging | back to summary |
|---|---|
| public void logging(String msg1, String msg2) Prints a log message. | |
| logging | back to summary |
|---|---|
| public void logging(String msg1, String msg2, String msg3) Prints a log message. | |
| logging2 | back to summary |
|---|---|
| public void logging2(String msg) Prints a log message with indentation. | |
| main | back to summary |
|---|---|
| public static void main(String[] args) throws IOException Starts a web server. The port number is specified by the first argument. | |
| process | back to summary |
|---|---|
| pack-priv final void process(Socket clnt) throws IOException | |
| readLine | back to summary |
|---|---|
| private String readLine(InputStream in) throws IOException | |
| replyError | back to summary |
|---|---|
| private void replyError(OutputStream out, BadHttpRequest e) throws IOException | |
| run | back to summary |
|---|---|
| public void run() Begins the HTTP service. | |
| sendHeader | back to summary |
|---|---|
| private void sendHeader(OutputStream out, long dataLength, int filetype) throws IOException | |
| setClassPool | back to summary |
|---|---|
| public void setClassPool(ClassPool loader) Requests the web server to use the specified
| |
| skipLine | back to summary |
|---|---|
| private int skipLine(InputStream in) throws IOException | |