Top Description Fields Constructors Methods
javassist.tools.web

public Class Webserver

Additional top-level class in compilation unit: ServiceThread.

extends Object
Class Inheritance
Known Direct Subclasses
javassist.tools.rmi.AppletServer
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .ByteArrayOutputStream, .File, .FileInputStream, .IOException, .InputStream, .OutputStream, java.net.ServerSocket, .Socket, java.util.Date, javassist.CannotCompileException, .ClassPool, .CtClass, .NotFoundException, .Translator

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

Modifier and TypeField and Description
private ClassPool
public String
debugDir

If this field is not null, the class files taken from ClassPool are written out under the directory specified by this field.

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

Constructor Summary

AccessConstructor and Description
public
Webserver(String
port number
port
)

Constructs a web server.

public
Webserver(int
port number
port
)

Constructs a web server.

Method Summary

Modifier and TypeMethod and Description
public void
addTranslator(ClassPool
the ClassPool object for obtaining a class file.
cp
,
Translator
a translator.
t
)

Adds a translator, which is called whenever a client requests a class file.

private void
checkFilename(String filename, int len)

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
end()

Closes the socket.

private boolean
letUsersSendClassfile(OutputStream out, String filename, int length)

public void
logging(String msg)

Prints a log message.

public void
logging(String msg1, String msg2)

Prints a log message.

public void
logging(String msg1, String msg2, String msg3)

Prints a log message.

public void
logging2(String msg)

Prints a log message with indentation.

public static void
main(String[] args)

Starts a web server.

pack-priv final void
private String
private void
public void
run()

Begins the HTTP service.

private void
sendHeader(OutputStream out, long dataLength, int filetype)

public void
setClassPool(ClassPool loader)

Requests the web server to use the specified ClassPool object for obtaining a class file.

private int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classPoolback to summary
private ClassPool classPool
debugDirback to summary
public String debugDir

If this field is not null, the class files taken from ClassPool are written out under the directory specified by this field. The directory name must not end with a directory separator.

endoflineback to summary
private static final byte[] endofline
htmlfileBaseback 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 Class.getResourceAsStream() is called for searching the Java class paths.

socketback to summary
private ServerSocket socket
translatorback to summary
protected Translator translator
typeClassback to summary
private static final int typeClass
typeGifback to summary
private static final int typeGif
typeHtmlback to summary
private static final int typeHtml
typeJpegback to summary
private static final int typeJpeg
typeTextback to summary
private static final int typeText

Constructor Detail

Webserverback to summary
public Webserver(String port) throws IOException

Constructs a web server.

Parameters
port:String

port number

Webserverback to summary
public Webserver(int port) throws IOException

Constructs a web server.

Parameters
port:int

port number

Method Detail

addTranslatorback 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.

Parameters
cp:ClassPool

the ClassPool object for obtaining a class file.

t:Translator

a translator.

checkFilenameback to summary
private void checkFilename(String filename, int len) throws BadHttpRequest
doReplyback to summary
public void doReply(InputStream in, OutputStream out, String cmd) throws IOException, BadHttpRequest

Proceses a HTTP request from a client.

Parameters
out:OutputStream

the output stream to a client

cmd:String

the command received from a client

endback to summary
public void end() throws IOException

Closes the socket.

letUsersSendClassfileback to summary
private boolean letUsersSendClassfile(OutputStream out, String filename, int length) throws IOException, BadHttpRequest
loggingback to summary
public void logging(String msg)

Prints a log message.

loggingback to summary
public void logging(String msg1, String msg2)

Prints a log message.

loggingback to summary
public void logging(String msg1, String msg2, String msg3)

Prints a log message.

logging2back to summary
public void logging2(String msg)

Prints a log message with indentation.

mainback to summary
public static void main(String[] args) throws IOException

Starts a web server. The port number is specified by the first argument.

processback to summary
pack-priv final void process(Socket clnt) throws IOException
readLineback to summary
private String readLine(InputStream in) throws IOException
replyErrorback to summary
private void replyError(OutputStream out, BadHttpRequest e) throws IOException
runback to summary
public void run()

Begins the HTTP service.

sendHeaderback to summary
private void sendHeader(OutputStream out, long dataLength, int filetype) throws IOException
setClassPoolback to summary
public void setClassPool(ClassPool loader)

Requests the web server to use the specified ClassPool object for obtaining a class file.

skipLineback to summary
private int skipLine(InputStream in) throws IOException