|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Thread
com.sun.jini.tool.ClassServer
A simple HTTP server, for serving up JAR and class files.
The following items are discussed below:
This implementation uses the Logger named
com.sun.jini.tool.ClassServer to log information at the
following logging levels:
| Level | Description |
|---|---|
SEVERE |
failure to accept an incoming connection |
WARNING |
failure to read the contents of a requested file,
failure to find the message resource bundle, failure while
executing the -stop option
|
INFO |
server startup and termination |
CONFIG |
the JAR files being used for -trees |
HANDLED |
failure reading an HTTP request or writing a response |
FINE |
bad HTTP requests, HTTP requests for nonexistent files |
FINER |
good HTTP requests |
Examples for running ClassServer
This server can be run directly from the command line or as a nonactivatable service under the Service Starter.
An example of running directly from the command line is:
% java -jar install_dir/lib/tools.jar
-port 8081 -dir install_dir/lib -verbose
where install_dir
is the directory where the starter kit is installed.
This command places the class server on the (non-default) port
8081, which serves out the files under the (non-default) directory
install_dir/lib. The -verbose option
also causes download attempts to be logged.
An example of running under the Service Starter is:
% java -Djava.security.policy=start_policy
-jar install_dir/lib/start.jar
httpd.config
where start_policy is the name of a security
policy file (not provided), and httpd.config is the
following configuration file:
import com.sun.jini.start.NonActivatableServiceDescriptor;
import com.sun.jini.start.ServiceDescriptor;
com.sun.jini.start {
serviceDescriptors = new ServiceDescriptor[]{
new NonActivatableServiceDescriptor(
"",
"httpd_policy",
"install_dir/lib/tools.jar",
"com.sun.jini.tool.ClassServer",
new String[]{"-port", "8081", "-dir", "install_dir/lib", "-verbose"})
};
}
where httpd_policy is the name of a security
policy file (not provided).
| Field Summary |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
ClassServer(int port,
String dir,
boolean trees,
boolean verbose)
Construct a server. |
|
ClassServer(String[] args,
LifeCycle lifeCycle)
Construct a running server, accepting the same command line options supported by main, except for the -stop
option. |
|
| Method Summary | |
protected void |
fileDownloaded(String fp,
InetAddress addr)
This method provides a way for subclasses to be notified when a file has been completely downloaded. |
int |
getPort()
Returns the port on which this server is listening. |
static void |
main(String[] args)
Command line interface for creating an HTTP server. |
void |
run()
Just keep looping, spawning a new thread for each incoming request. |
void |
terminate()
Close the server socket, causing the thread to terminate. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ClassServer(int port,
String dir,
boolean trees,
boolean verbose)
throws IOException
port - the port to usedir - the directory to serve files fromtrees - true if files within JAR files should be served upverbose - true if downloads should be logged
IOException - if the server socket cannot be created
NullPointerException - if dir is null
public ClassServer(String[] args,
LifeCycle lifeCycle)
throws IOException
main, except for the -stop
option.
args - command line optionslifeCycle - life cycle control object, or null
IOException - if the server socket cannot be created
IllegalArgumentException - if a command line option is not
understood
NullPointerException - if args or any element
of args is null| Method Detail |
public void run()
public void terminate()
public int getPort()
protected void fileDownloaded(String fp,
InetAddress addr)
fp - The path to the file that was downloaded.public static void main(String[] args)
[-port port] [-dir dir] [-trees] [-verbose]The default port is 8080; the default can be overridden with the -port option. The default directory on Windows is J: and the default on other systems is /vob/jive/lib; the default can be overridden with the -dir option. By default, all files under this directory (including all subdirectories) are served up via HTTP. If the pathname of a file is path relative to the top-level directory, then the file can be downloaded using the URL
http://host:port/pathNo caching of directory contents or file contents is performed. If the -verbose option is given, then all attempts to download files are output.
The -trees option can be used to serve up individual files stored within JAR files in addition to the files that are served up by default. If the option is used, the server finds all JAR files in the top-level directory (not in subdirectories). For each JAR file, if the name of the JAR file is name.jar, then any individual file named file within that JAR file (or within the JAR or zip files referenced transitively in the Class-Path manifest attribute, can be downloaded using a URL of the form:
http://host:port/name/fileWhen this option is used, an open file descriptor and cached information is held for each JAR file, for the life of the process.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||