Remove abstract execute() method and add abstract getApplication().
Remove encoding instance variable and get it from application when needed.
This commit is contained in:
parent
381e235e19
commit
6f3f82f40a
3 changed files with 34 additions and 27 deletions
|
@ -20,6 +20,7 @@
|
|||
package helma.servlet;
|
||||
|
||||
import helma.framework.*;
|
||||
import helma.framework.core.Application;
|
||||
import helma.util.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
@ -47,9 +48,6 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
// cookie domain to use
|
||||
String cookieDomain;
|
||||
|
||||
// default encoding for requests
|
||||
String defaultEncoding = "ISO8859_1";
|
||||
|
||||
// allow caching of responses
|
||||
boolean caching;
|
||||
|
||||
|
@ -57,9 +55,9 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
boolean debug;
|
||||
|
||||
/**
|
||||
* Init this servlet.
|
||||
*
|
||||
*
|
||||
* @param init ...
|
||||
* @param init the servlet configuration
|
||||
*
|
||||
* @throws ServletException ...
|
||||
*/
|
||||
|
@ -78,21 +76,20 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
cookieDomain = cookieDomain.toLowerCase();
|
||||
}
|
||||
|
||||
// get default encoding
|
||||
String encoding = init.getInitParameter("charset");
|
||||
|
||||
if (encoding != null) {
|
||||
defaultEncoding = encoding;
|
||||
}
|
||||
|
||||
debug = ("true".equalsIgnoreCase(init.getInitParameter("debug")));
|
||||
caching = !("false".equalsIgnoreCase(init.getInitParameter("caching")));
|
||||
}
|
||||
|
||||
abstract ResponseTrans execute(RequestTrans req) throws Exception;
|
||||
/**
|
||||
* Abstract method to get the {@link helma.framework.core.Application Applicaton}
|
||||
* instance the servlet is talking to.
|
||||
*
|
||||
* @return this servlet's application instance
|
||||
*/
|
||||
abstract Application getApplication();
|
||||
|
||||
/**
|
||||
*
|
||||
* Handle a GET request.
|
||||
*
|
||||
* @param request ...
|
||||
* @param response ...
|
||||
|
@ -106,7 +103,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handle a POST request.
|
||||
*
|
||||
* @param request ...
|
||||
* @param response ...
|
||||
|
@ -128,8 +125,8 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
String encoding = request.getCharacterEncoding();
|
||||
|
||||
if (encoding == null) {
|
||||
// no encoding from request, use standard one
|
||||
encoding = defaultEncoding;
|
||||
// no encoding from request, use the application's charset
|
||||
encoding = getApplication().getCharset();
|
||||
}
|
||||
|
||||
// read and set http parameters
|
||||
|
@ -272,7 +269,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
// response.setHeader ("Server", "Helma/"+helma.main.Server.version);
|
||||
reqtrans.path = getPathInfo(request);
|
||||
|
||||
ResponseTrans restrans = execute(reqtrans);
|
||||
ResponseTrans restrans = getApplication().execute(reqtrans);
|
||||
|
||||
// set cookies
|
||||
if (restrans.countCookies() > 0) {
|
||||
|
@ -723,6 +720,8 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
int uriTokens = t.countTokens();
|
||||
StringBuffer pathbuffer = new StringBuffer();
|
||||
|
||||
String encoding = getApplication().getCharset();
|
||||
|
||||
for (int i = 0; i < uriTokens; i++) {
|
||||
String token = t.nextToken();
|
||||
|
||||
|
@ -734,7 +733,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
pathbuffer.append('/');
|
||||
}
|
||||
|
||||
pathbuffer.append(UrlEncoded.decode(token, defaultEncoding));
|
||||
pathbuffer.append(UrlEncoded.decode(token, encoding));
|
||||
}
|
||||
|
||||
// append trailing "/" if it is contained in original URI
|
||||
|
|
|
@ -52,13 +52,17 @@ public final class EmbeddedServletClient extends AbstractServletClient {
|
|||
}
|
||||
}
|
||||
|
||||
ResponseTrans execute(RequestTrans req) throws Exception {
|
||||
/**
|
||||
* Returns the {@link helma.framework.core.Application Applicaton}
|
||||
* instance the servlet is talking to.
|
||||
*
|
||||
* @return this servlet's application instance
|
||||
*/
|
||||
Application getApplication() {
|
||||
if (app == null) {
|
||||
app = Server.getServer().getApplication(appName);
|
||||
// get the app's charset
|
||||
defaultEncoding = app.getCharset();
|
||||
}
|
||||
|
||||
return app.execute(req);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,12 +68,18 @@ public final class StandaloneServletClient extends AbstractServletClient {
|
|||
}
|
||||
}
|
||||
|
||||
ResponseTrans execute(RequestTrans req) throws Exception {
|
||||
/**
|
||||
* Returns the {@link helma.framework.core.Application Applicaton}
|
||||
* instance the servlet is talking to.
|
||||
*
|
||||
* @return this servlet's application instance
|
||||
*/
|
||||
Application getApplication() {
|
||||
if (app == null) {
|
||||
createApp();
|
||||
}
|
||||
|
||||
return app.execute(req);
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +98,6 @@ public final class StandaloneServletClient extends AbstractServletClient {
|
|||
app = new Application(appName, appHome, dbHome);
|
||||
app.init();
|
||||
app.start();
|
||||
// get the app's charset
|
||||
defaultEncoding = app.getCharset();
|
||||
} catch (Exception x) {
|
||||
log("Error starting Application " + appName + ": " + x);
|
||||
x.printStackTrace();
|
||||
|
|
Loading…
Add table
Reference in a new issue