public class ClassServer extends Thread implements Startable
The following items are discussed below:
This implementation uses the Logger
named
org.apache.river.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 ServiceStarter.
An example of running directly from the command line is:
where install_dir is the directory where the River-Internet release 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-dl. The% java -jar install_dir/lib/classserver.jar \ -port 8081 -dir install_dir/lib-dl -verbose
-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:
where httpd_policy is the name of a security policy file (not provided).import org.apache.river.start.NonActivatableServiceDescriptor; import org.apache.river.start.ServiceDescriptor; org.apache.river.start { serviceDescriptors = new ServiceDescriptor[]{ new NonActivatableServiceDescriptor( "", "httpd_policy", "install_dir/lib/classserver.jar", "org.apache.river.tool.ClassServer", new String[]{"-port", "8081", "-dir", "install_dir/lib-dl", "-verbose"}) }; }
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
ClassServer(int port,
String dirlist,
boolean trees,
boolean verbose)
Construct a server that does not support network shutdown.
|
ClassServer(int port,
String dirlist,
boolean trees,
boolean verbose,
boolean stoppable)
Construct a server.
|
ClassServer(String[] args,
LifeCycle lifeCycle)
Construct a server, accepting the same command line options
supported by
main , except for the -stop
option. |
Modifier and Type | Method and Description |
---|---|
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.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public ClassServer(int port, String dirlist, boolean trees, boolean verbose) throws IOException
start
method to run it.port
- the port to usedirlist
- the list of directories to serve files from, with entries
separated by the path-separator
charactertrees
- true
if files within JAR files should be
served upverbose
- true
if downloads should be loggedIOException
- if the server socket cannot be createdNullPointerException
- if dir
is null
public ClassServer(int port, String dirlist, boolean trees, boolean verbose, boolean stoppable) throws IOException
start
method to run it.port
- the port to usedirlist
- the list of directories to serve files from, with entries
separated by the path-separator
charactertrees
- true
if files within JAR files should be
served upverbose
- true
if downloads should be loggedstoppable
- true
if network shutdown from the
local host should be supportedIOException
- if the server socket cannot be createdNullPointerException
- if dir
is null
public ClassServer(String[] args, LifeCycle lifeCycle) throws IOException
main
, except for the -stop
option.
If constructed by ServiceStarter
,
Commission#start()
, is called automatically, otherwise Thread.start()
must be called manually after construction.args
- command line optionslifeCycle
- life cycle control object, or null
IOException
- if the server socket cannot be createdIllegalArgumentException
- if a command line option is not
understoodNullPointerException
- if args
or any element
of args
is null
Startable
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 dirlist] [-dirs dirlist] [-stoppable] [-verbose] [-trees]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-dl
; the default can be overridden with the
-dir
or -dirs
option, providing one or more
directories separated by the path-separator character. All files under these directories (including
all subdirectories) are served up via HTTP. If the pathname of a file
is path relative to one of the top-level directories, then
the file can be downloaded using the URL
http://host:port/pathIf a relative path matches a file under more than one top-level directory, the file under the first top-level directory with a match is used. No caching of directory contents or file contents is performed.
If the -stoppable
option is given, the HTTP server can be
shut down with a custom HTTP SHUTDOWN
request originating
from the local host. The command line options for stopping an existing
HTTP server are:
[-port port] -stop
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 and zip files in addition to the files that are
served up as described above. If the option is used, the server finds
all JAR and zip files in the top-level directories (not in
subdirectories). If the name of the JAR or zip file is
name.jar
or name.zip
,
then any individual file named file within it (or within the
JAR or zip files referenced transitively in Class-Path
manifest attributes), can be downloaded using a URL of the form:
http://host:port/name/fileIf multiple top-level directories have JAR or zip files with the same name, the file under the first top-level directory with a match is used. If a
Class-Path
element matches a file under
more than one top-level directory, the file under the first top-level
directory with a match is used. When this option is used, an open file
descriptor and cached information is held for each JAR or zip file, for
the life of the process.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.