gnu.cajo.utils.CodebaseServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ghost4j Show documentation
Show all versions of ghost4j Show documentation
Java wrapper for Ghostscript API
package gnu.cajo.utils;
import java.io.*;
import java.net.*;
import gnu.cajo.invoke.Remote;
import java.util.Date;
import java.text.SimpleDateFormat;
/*
* RMI Codebase and Graphical Proxy Server
* Copyright (C) 1999 John Catherino
* The cajo project: https://cajo.dev.java.net
*
* For issues or suggestions mailto:[email protected]
*
* This file CodebaseServer.java is part of the cajo library.
*
* The cajo library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation, at version 3 of the licence, or (at your
* option) any later version.
*
* The cajo library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public Licence for more details.
*
* You should have received a copy of the GNU Lesser General Public Licence
* along with this library. If not, see http://www.gnu.org/licenses/lgpl.html
*/
/**
* 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
* @author John Catherino
*/
public final class CodebaseServer extends Thread {
private static final SimpleDateFormat formatter =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
private static final byte[] // http headers:
bye = ("HTTP/1.0 404 Not Found\r\n" // unsupported request
+ "Content-type: text/html\r\n"
+ "Server: cajo/CodebaseServer\r\n"
+ "Connection: close\r\n\r\n"
+ "
404: URL Not Found "
+ "404 - Not Found
"
+ "The requested resource is not available from this server.
"
+ "
gnu.cajo.utils.CodebaseServer - The cajo project: "
+ "https://cajo.dev.java.net."
+ "").getBytes(),
apl = ("HTTP/1.0 200 OK\r\n"
+ "Content-type: text/html\r\n"
+ "Server: cajo/CodebaseServer\r\n"
+ "Last-Modified: " + formatter.format(new Date()) + "\r\n"
+ "Connection: close\r\n\r\n").getBytes(), // for applets
jws = ("HTTP/1.0 200 OK\r\n"
+ "Content-type: application/x-java-jnlp-file\r\n"
+ "Server: cajo/CodebaseServer\r\n"
+ "Last-Modified: " + formatter.format(new Date()) + "\r\n"
+ "Connection: close\r\n\r\n").getBytes(), // for WebStart
jarHdr = ("HTTP/1.0 200 OK\r\n" // for jar files
+ "Content-type: application/x-java-archive\r\n"
+ "Server: cajo/CodebaseServer\r\n").getBytes(), // for WebStart
classHdr = ("HTTP/1.0 200 OK\r\n" // for class files
+ "Content-type: application/x-java-vm\r\n"
+ "Server: cajo/CodebaseServer\r\n").getBytes(), // for WebStart
imgHdr = ("HTTP/1.0 200 OK\r\n" // for image files
+ "Content-type: image/jpeg\r\n"
+ "Server: cajo/CodebaseServer\r\n").getBytes(), // for WebStart
end = ( // http footers:
"PLUGINSPAGE=\"http://java.sun.com/j2se/1.5.0/download.html\">\r\n"
+ "