Class CodebaseServer
- java.lang.Object
-
- java.lang.Thread
-
- gnu.cajo.utils.CodebaseServer
-
- All Implemented Interfaces:
java.lang.Runnable
public final class CodebaseServer extends java.lang.Thread
The standard mechanism to send proxies, and other complex objects to remote VMs. It requires one outbound port. The port can be anonymous, i.e. selected from any available free port at runtime, or it can be explicitly specified, usually to operate through a firewall. It also provides the generic graphical proxy host client service, as an Applet, and via WebStart.Note: There can be at most one CodebaseServer instance per JVM.
- Version:
- 1.0, 01-Nov-99 Initial release
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]
apl
private static byte[]
bye
private static byte[]
classHdr
private static byte[]
end
private static java.text.SimpleDateFormat
formatter
private static byte[]
imgHdr
private static byte[]
jarHdr
private static byte[]
jws
private java.io.PrintStream
log
private byte[]
mid
private static byte[]
out
static int
port
Deprecated.The preferred field to check is serverPort as this field is mutable unfortunately; it remains solely to maintain backward compatibility.int
serverPort
This is the inbound ServerSocket port number providing both the HTTP client tag and codebase jar service.private java.net.ServerSocket
ss
private byte[]
tip
private byte[]
top
private byte[]
xml
-
Constructor Summary
Constructors Constructor Description CodebaseServer(java.lang.String[] jars, int port, java.lang.String client, java.lang.String title, java.lang.String vendor, java.lang.String icon, java.lang.String splash)
The main constructor will start up the server's codebase transport mechanism on the specified port.CodebaseServer(java.lang.String base, int port)
This constructor simply calls the three argument constructor, providing the standard cajo generic graphical client as the client argument.CodebaseServer(java.lang.String base, int port, java.lang.String client)
This constructor will start up the server's codebase transport mechanism on the specified port, using the specified codebase jar file, with the specified clent.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(java.lang.String[] args)
The application creates a utility server to share any jar and class files in its working directory and subdirectories.void
run()
The server thread method, it will send the proxy codebase, and it will also support installing the hostingClient
, or application specific host, in a Java-enabled browser, or as a web start application via JNLP.void
setLog(java.io.OutputStream log)
This method can be used to log the client requests of the Codebase server.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
formatter
private static final java.text.SimpleDateFormat formatter
-
bye
private static final byte[] bye
-
apl
private static final byte[] apl
-
jws
private static final byte[] jws
-
jarHdr
private static final byte[] jarHdr
-
classHdr
private static final byte[] classHdr
-
imgHdr
private static final byte[] imgHdr
-
end
private static final byte[] end
-
out
private static final byte[] out
-
top
private final byte[] top
-
mid
private final byte[] mid
-
tip
private final byte[] tip
-
xml
private final byte[] xml
-
ss
private final java.net.ServerSocket ss
-
log
private java.io.PrintStream log
-
serverPort
public final int serverPort
This is the inbound ServerSocket port number providing both the HTTP client tag and codebase jar service. If the server is behind a firewall, this port, must be made accessible from outside. If the port argument used in the constructor was zero, it will use an anonymous port; i.e. one selected by the OS from any ports available at runtime. In that case, the port actually offered by the operating system will be stored here automatically, following construction.
-
port
public static int port
Deprecated.The preferred field to check is serverPort as this field is mutable unfortunately; it remains solely to maintain backward compatibility.This is the inbound ServerSocket port number providing both the HTTP client tag and codebase jar service. If the server is behind a firewall, this port, must be made accessible from outside. If the port argument used in the constructor was zero, it will use an anonymous port; i.e. one selected by the OS from any ports available at runtime. In that case, the port actually offered by the operating system will be stored here automatically, following construction.
-
-
Constructor Detail
-
CodebaseServer
public CodebaseServer(java.lang.String[] jars, int port, java.lang.String client, java.lang.String title, java.lang.String vendor, java.lang.String icon, java.lang.String splash) throws java.io.IOException
The main constructor will start up the server's codebase transport mechanism on the specified port. To shut the service down, call its inherited interrupt method. All other constructors in this class call it.- Parameters:
jars
- An array of strings representing the path and filename of a library jar needed by the client application. The CodebaseServer will serve them to the remote JVM. The server will first search for the jar in its own executable jar file, if that fails, then it will check the local filesystem. The jars could represent individual proxies, or general-purpose shared libraries.The first jar named in the array will be assumed to be the jar containing the main client class.
Note: if this value is null, it indicates that the proxy codebase is not in a jar. The server will then look first in its own jar file for the class files to send, and if not found, it will next look in its working directory. This feature provides an extremely simple, essentially zero-configuration, approach to proxy codebase service.
As a special safety feature, if the jar from which the service items are running is given the special> name service.jar it not be allowed to be requested over the network. This would be important for example, if you did not wish to share the server.jar file.
port
- The TCP port on which to serve the codebase, and client applet. It can be zero, to use an anonymous port. If zero, the actual port selected by the OS at runtime will be stored in theserverPort
member.client
- The name of the graphical client class to be furnished as an Applet, or via WebStart. For example, the generic cajo standard graphical proxy is: gnu.cajo.invoke.Clienttitle
- The optional application specific titile to show in the browser, when running as an applet.vendor
- The optional vendor name of the WebStart application.icon
- The optional custom desktop icon to represent the WebStart application, it can also be null. It is typically of the form "images/icon.gif", where it will be requested from the server. The image can be in either GIF or JPEG format.splash
- The optional splash screen image to represent the WebStart application while it is loading, it can also be null. It is typically of the form "images/splash.jpeg", where it will be requested from the server. The image can be in either GIF or JPEG format.- Throws:
java.io.IOException
- If the HTTP socket providing the codebase and applet tag service could not be created.
-
CodebaseServer
public CodebaseServer(java.lang.String base, int port, java.lang.String client) throws java.io.IOException
This constructor will start up the server's codebase transport mechanism on the specified port, using the specified codebase jar file, with the specified clent.- Parameters:
base
- The path and name of the file containing the proxy codebase jar file.port
- The TCP port on which to serve the codebase, and client applet.client
- The name of the graphical client class to be furnished as an Applet, or via WebStart.- Throws:
java.io.IOException
- If the HTTP socket providing the codebase and applet tag service could not be created.
-
CodebaseServer
public CodebaseServer(java.lang.String base, int port) throws java.io.IOException
This constructor simply calls the three argument constructor, providing the standard cajo generic graphical client as the client argument.- Parameters:
base
- The path and name of the file containing the proxy codebase jar file.port
- The TCP port on which to serve the codebase, and client applet.- Throws:
java.io.IOException
- If the HTTP socket providing the codebase and applet tag service could not be created.
-
-
Method Detail
-
setLog
public void setLog(java.io.OutputStream log)
This method can be used to log the client requests of the Codebase server. The log can range from System.out, to a network socket OutputStream.Note: Only one log stream can be assigned to the CodebaseServer at any given time.
- Parameters:
log
- The OutputStream to record the client requests. If this argument is null, no change will take place.
-
run
public void run()
The server thread method, it will send the proxy codebase, and it will also support installing the hostingClient
, or application specific host, in a Java-enabled browser, or as a web start application via JNLP.The format of a browser's proxy request URL one required, and five optional parameters, utilizing the following format:
http://serverHost[:serverPort]/[clientPort][:localPort][-proxyName][!]
Where the parameters have the following meanings:
- serverHost The domain name, or IP address of the proxy server.
- serverPort The port number of the applet/codebases service, unspecified it will be 80.
- clientPort The client's external port number on which the remote proxy can be reached. It is often explicitly specified when the client is behind a firewall, or is using port translation. Unspecified, it will be the same as the localPort value, described next.
- localPort The client's internal port number on which the remote proxy can be reached. Unspecified, it will be selected anonymously by the client at runtime.
- proxyName The registered name of the proxy serving object, by default "main", however a single server can support multiple service objects.
- ! This operator causes the proxy to be sent using JNLP. This will launch the proxy as an application on the client using WebStart.
To unspecify any optional object, simply omit it, from the URL, along with its preceeding delimiter, if any. The order of the arguments must be maintained however.
Note: other object servers can share this instance, by placing their proxy classes or jar files in the same working directory. However, those object servers will not be able to use the client service feature, as it is unique to the VM in which the CodebaseServer is running.
As a safety precaution, the server will send any requested jar or class file in or below its working directory except the jar file of the server itself. Typically people do not want to give this file out.
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
The application creates a utility server to share any jar and class files in its working directory and subdirectories. It is very useful in application development. If a port number is provided as an argument, it will be used, otherwise it will be opened on an anonymous port.- Throws:
java.lang.Exception
-
-