home *** CD-ROM | disk | FTP | other *** search
- package lotus.domino.servlet;
-
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.OptionalDataException;
- import java.io.PrintStream;
- import java.io.StreamCorruptedException;
- import java.io.StringReader;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import javax.servlet.Servlet;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
-
- public class DominoServletInvoker {
- public static final int UNINITIALIZED = 0;
- public static final int READY = 1;
- public static final int WAITING_TO_DIE = 2;
- public static final int DEAD = 3;
- public static final int ERROR = 4;
- public static final String INTERNAL_ERROR_MESSAGE = "Internal Error";
- protected String i_name;
- private String i_classname;
- private Servlet i_servlet;
- private ServletConfig i_config;
- private int i_state = 0;
-
- public DominoServletInvoker(String var1, ServletConfig var2, String var3) {
- this.i_classname = var1;
- this.i_config = var2;
- this.i_name = var3;
- if (this.i_config != null) {
- String var4 = this.i_config.getInitParameter("GO_LOAD_AT_STARTUP");
- if (var4 != null && var4.toUpperCase().equals("YES")) {
- this.load();
- }
- }
-
- }
-
- public void load() {
- try {
- Object var1 = null;
- int var2 = this.i_classname.lastIndexOf(".");
- if (var2 != -1) {
- String var3 = this.i_classname.substring(var2);
- if (var3.toUpperCase().equals(".SER")) {
- FileInputStream var4 = new FileInputStream(this.i_classname);
- ObjectInputStream var5 = new ObjectInputStream(var4);
- var1 = var5.readObject();
- } else if (var3.toUpperCase().equals(".CLASS")) {
- this.i_classname = this.i_classname.substring(0, var2);
- Class var19 = Class.forName(this.i_classname);
- var1 = var19.newInstance();
- } else {
- Class var20 = Class.forName(this.i_classname);
- var1 = var20.newInstance();
- }
- } else {
- Class var17 = Class.forName(this.i_classname);
- var1 = var17.newInstance();
- }
-
- if (var1 instanceof Servlet) {
- this.i_servlet = (Servlet)var1;
- Hashtable var18 = ServletManager.getServletTable();
- var18.put(this.i_name, this.i_servlet);
- this.i_servlet.init(this.i_config);
- this.i_state = 1;
- } else {
- throw new ClassCastException("Cannot convert Class " + this.i_classname + " to java.lang.Servlet");
- }
- } catch (FileNotFoundException var6) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("File " + this.i_classname + " was not found");
- this.printInfo(this.toString(), System.err);
- ((Throwable)var6).printStackTrace(System.err);
- } catch (IllegalArgumentException var7) {
- this.i_state = 4;
- System.err.println("Error loading Servlet (" + this.i_name + "): " + this.i_classname + " is not a valid class name");
- this.printInfo(this.toString(), System.err);
- ((Throwable)var7).printStackTrace(System.err);
- } catch (ClassNotFoundException var8) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("Class " + this.i_classname + " was not found: check the CLASSPATH");
- this.printInfo(this.toString(), System.err);
- ((Throwable)var8).printStackTrace(System.err);
- } catch (IllegalAccessException var9) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("Could not create an instance of class: " + this.i_classname);
- this.printInfo(this.toString(), System.err);
- ((Throwable)var9).printStackTrace(System.err);
- } catch (InstantiationException var10) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("Could not create an instance of class: " + this.i_classname);
- this.printInfo(this.toString(), System.err);
- ((Throwable)var10).printStackTrace(System.err);
- } catch (OptionalDataException var11) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("Could not create an instance of class: " + this.i_classname);
- this.printInfo(this.toString(), System.err);
- ((Throwable)var11).printStackTrace(System.err);
- } catch (StreamCorruptedException var12) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("The serialization file is corrupt");
- this.printInfo(this.toString(), System.err);
- ((Throwable)var12).printStackTrace(System.err);
- } catch (IOException var13) {
- this.i_state = 4;
- System.err.println("Error occurred while loading Servlet (" + this.i_name + ")");
- System.err.println("I/O error while loading class: " + this.i_classname);
- this.printInfo(this.toString(), System.err);
- ((Throwable)var13).printStackTrace(System.err);
- } catch (ServletException var14) {
- this.i_state = 4;
- System.err.println("Error occurred while initializing Servlet (" + this.i_name + ")");
- this.printInfo(this.toString(), System.err);
- ((Throwable)var14).printStackTrace(System.err);
- } catch (Throwable var15) {
- this.i_state = 4;
- System.err.println("Error occurred while initializing Servlet (" + this.i_name + ")");
- this.printInfo(this.toString(), System.err);
- var15.printStackTrace(System.err);
- }
- }
-
- public void destroy() {
- if (this.i_state == 1) {
- this.i_state = 2;
- this.i_servlet.destroy();
- }
-
- this.i_state = 3;
- }
-
- public int invokeSSI() throws ServletException, IOException {
- try {
- if (this.i_state == 4) {
- NativeStub.set("HTTP_REASON", "Internal Error");
- return 500;
- } else {
- return this.executeServlet(true);
- }
- } catch (NativeStubException var2) {
- ((Throwable)var2).printStackTrace();
- throw new ServletException("Set HTTP_REASON for SSI failed");
- }
- }
-
- public int service() throws ServletException, IOException {
- return this.executeServlet(false);
- }
-
- private int executeServlet(boolean var1) throws ServletException, IOException {
- if (this.i_state == 4) {
- try {
- NativeStub.set("HTTP_REASON", "Internal Error");
- } catch (NativeStubException var6) {
- ((Throwable)var6).printStackTrace();
- }
-
- return 500;
- } else {
- if (this.i_state == 0 && this.i_config != null) {
- this.load();
- }
-
- if (this.i_state == 1) {
- NativeStubContext var2 = new NativeStubContext();
- Object var3 = null;
- Object var4 = null;
- if (this.i_servlet instanceof Servlet) {
- DominoHttpServletRequest var10 = new DominoHttpServletRequest(var2);
- DominoHttpServletResponse var11 = new DominoHttpServletResponse(var2);
- var10.setResponse(var11);
- var11.setRequest(var10);
- ((DominoServletRequest)var10).getInputStream();
-
- try {
- this.i_servlet.service(var10, var11);
- } catch (Throwable var8) {
- Throwable var5 = var8;
- System.err.println("Exception detected while executing while executing Servlet (" + this.i_name + ")");
- var8.printStackTrace();
-
- try {
- if (!var11.containsHeader("HTTP_REASON")) {
- var2.set("HTTP_REASON", "Internal Error");
- }
-
- var5.printStackTrace();
- } catch (NativeStubException var7) {
- var8.printStackTrace();
- }
- }
-
- ((DominoServletRequest)var10).close();
- ((DominoServletResponse)var11).close();
- return var2.getReturnCode();
- } else {
- System.err.println(this.i_name + " is not a valid servlet");
- this.i_state = 4;
- return 500;
- }
- } else {
- try {
- NativeStub.set("HTTP_REASON", "Internal Error");
- } catch (NativeStubException var9) {
- ((Throwable)var9).printStackTrace();
- }
-
- return 500;
- }
- }
- }
-
- public String getName() {
- return this.i_name;
- }
-
- public Servlet getServlet() {
- return this.i_servlet;
- }
-
- public String toString() {
- String var1 = "-----Servlet Information-----\n";
- var1 = var1 + "Name: " + this.i_name.toString() + "\n";
- var1 = var1 + "Base Class: " + this.i_classname.toString() + "\n";
- var1 = var1 + "State: ";
- switch (this.i_state) {
- case 0:
- var1 = var1 + "UNITIALIZED";
- break;
- case 1:
- var1 = var1 + "READY";
- break;
- case 2:
- var1 = var1 + "WAITING_TO_DIE";
- break;
- case 3:
- var1 = var1 + "DEAD";
- break;
- case 4:
- var1 = var1 + "ERROR";
- }
-
- var1 = var1 + "\n";
- if (this.i_config != null) {
- Enumeration var2 = this.i_config.getInitParameterNames();
- String var3;
- if (!var2.hasMoreElements()) {
- var1 = var1 + "Configuration parameters: <none>\n";
- } else {
- for(var1 = var1 + "Configuration parameters:\n"; var2.hasMoreElements(); var1 = var1 + this.i_name + " parameter: " + var3 + " = " + this.i_config.getInitParameter(var3) + "\n") {
- var3 = var2.nextElement().toString();
- }
- }
- } else {
- var1 = var1 + "Servlet Configuration Object is null\n";
- }
-
- if (this.i_servlet != null) {
- var1 = var1 + "Info for: " + this.i_servlet.toString() + "\n";
- }
-
- return var1;
- }
-
- public void printInfo(String var1, PrintStream var2) {
- BufferedReader var3 = new BufferedReader(new StringReader(var1));
-
- try {
- for(String var4 = var3.readLine(); var4 != null; var4 = var3.readLine()) {
- var2.println(var4);
- }
-
- } catch (IOException var5) {
- }
- }
- }
-