Source code: org/enhydra/httpServerTest/server/application/BasicTestApp.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * $Id: BasicTestApp.java,v 1.2.2.1.2.1 2000/10/19 17:59:08 jasona Exp $
22 */
23
24 package org.enhydra.httpServerTest.server.application;
25
26 import com.lutris.appserver.server.ApplicationException;
27 import com.lutris.appserver.server.StandardApplication;
28 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
29 import com.lutris.util.Config;
30 import com.lutris.util.ConfigException;
31 import com.lutris.util.KeywordValueException;
32
33 import java.io.File;
34 /**
35 * This is the basic application class object for the http server test.
36 * This class is very limited in its functionality and simply provides
37 * static references to a temporary directory location, setable through the
38 * appication configuration file, and a counter. The temorary directory
39 * is used for caching of files that are uploaded. The counter is used
40 * to ensure that each thread of this application, handling uploaded files,
41 * will create a unique sub-directory, under the specified temporary
42 * directory, to write to. This allows each thread to only account for
43 * uploaded files that occured on the current request being handled.
44 *
45 * @author Mike Ward
46 **/
47 public class BasicTestApp extends StandardApplication {
48
49 /**
50 * This is the reference key used to lookup the validation DTD for
51 * HttpResponseObject. This value is specified in the application
52 * configuration file as
53 * 'Application.HttpResponseObjectDTD = <location of DTD>
54 **/
55 public static final String HTTP_RESPONSE_OBJECT_DTD =
56 "HttpResponseObjectDTD";
57
58 /**
59 * This is the reference key used to lookup the temporary base
60 * directory in the application configuration file. The expected
61 * key is 'Application.TemporaryBaseDir = <some tmp dir>'.
62 **/
63 public static final String TEMP_BASE_DIR = "TemporaryBaseDir";
64
65 /**
66 * This is the reference key used to grab the application specific
67 * section of the configuration file. All application specific
68 * configuration variables begin with this tag 'Application.<var name>'.
69 **/
70 public static final String APPLICATION_TAG = "Application";
71
72 /**
73 * This holds the location of the DTD used to validate the
74 * HttpResponseObject when read from the application configuration file.
75 **/
76 public static String httpResponseObjectDTD = null;
77
78 /**
79 * This holds the value of the temporary base direstory when read from
80 * the application configuration file.
81 **/
82 public static String temporaryBaseDir = null;
83
84 /**
85 * This is a static counter used by the presentation objects to ensure
86 * a unique sub-directory under the specified temporary base directory.
87 * The directories created using this count variable are used to cache
88 * files uploaded from the client.
89 **/
90 protected static Long fileCacheDirCnt = new Long(0);
91
92 /**
93 * This is the global Config object that is shared by the
94 * whole application. If there was an error reading the file, this
95 * will be null.
96 *
97 * @see com.lutris.util.Config
98 **/
99 public static Config config = null;
100
101 /**
102 * This is the startup function called when this application is loaded.
103 * This function calls super.startup(appConfig) and then attempts to
104 * read the temporary base directory from the supplied configuration
105 * parameters. If this configuration setting is not found, this function
106 * will throw an excepion.
107 *
108 * @param appConfig
109 * The configuration object for this application.
110 * @exception ApplicationException
111 * Thrown if an error occurs while retrieving the temporary
112 * base directory.
113 **/
114 public void startup(Config appConfig)
115 throws ApplicationException {
116 super.startup(appConfig);
117 // Here is where you would read application-specific settings from
118 // your config file.
119 config = appConfig;
120 try {
121 Config appConfigSection = config.getConfig(APPLICATION_TAG);
122 temporaryBaseDir = appConfigSection.getString(TEMP_BASE_DIR);
123 if (!temporaryBaseDir.endsWith(File.pathSeparator)) {
124 temporaryBaseDir += File.separator;
125 }
126 httpResponseObjectDTD =
127 appConfigSection.getString(HTTP_RESPONSE_OBJECT_DTD);
128 } catch (ConfigException e) {
129 throw new ApplicationException(e.toString());
130 } catch (KeywordValueException e) {
131 throw new ApplicationException(e.toString());
132 }
133 }
134
135 /**
136 * This is a static function to retrieve the next sequence of the conter
137 * variable held in this class. This function synchronizes on the
138 * fileCacheDirCnt and increments this count each time this function is
139 * called and then returns the new count.
140 *
141 * @return long
142 * The current, incremented counter.
143 **/
144 public static long getFileCacheDirCnt() {
145 synchronized (fileCacheDirCnt) {
146 fileCacheDirCnt = new Long(fileCacheDirCnt.longValue() + (long)1);
147 return fileCacheDirCnt.longValue();
148 }
149 }
150
151 /**
152 * This is an optional function, used only by the Multiserver's graphical
153 * administration. This bit of HTML appears in the status page for this
154 * application. You could add extra status info, for example
155 * a list of currently logged in users.
156 *
157 * @return HTML that is displayed in the status page of the Multiserver.
158 **/
159 public String toHtml() {
160 return "This is <I>BasicTestApp</I>";
161 }
162 }
163