Fixed bugs and performance problems in StandaloneServletClient.
The Hop embedded into the servlet container is now the most performant way to run a Hop app.
This commit is contained in:
parent
af93d7b66a
commit
96393ea5eb
2 changed files with 49 additions and 38 deletions
|
@ -85,7 +85,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
RequestTrans reqtrans = new RequestTrans (method);
|
RequestTrans reqtrans = new RequestTrans (method);
|
||||||
reqtrans.path = getRequestPath (pathInfo);
|
reqtrans.path = getRequestPath (pathInfo);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (cookies != null) {
|
if (cookies != null) {
|
||||||
for (int i=0; i < cookies.length;i++) try { // get Cookies
|
for (int i=0; i < cookies.length;i++) try { // get Cookies
|
||||||
|
@ -102,10 +102,10 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
if (reqtrans.session == null) {
|
if (reqtrans.session == null) {
|
||||||
reqtrans.session = Long.toString (Math.round (Math.random ()*Long.MAX_VALUE), 16);
|
reqtrans.session = Long.toString (Math.round (Math.random ()*Long.MAX_VALUE), 16);
|
||||||
reqtrans.session += "@"+Long.toString (System.currentTimeMillis (), 16);
|
reqtrans.session += "@"+Long.toString (System.currentTimeMillis (), 16);
|
||||||
Cookie c = new Cookie("HopSession", reqtrans.session);
|
Cookie c = new Cookie("HopSession", reqtrans.session);
|
||||||
c.setPath ("/");
|
c.setPath ("/");
|
||||||
if (cookieDomain != null)
|
if (cookieDomain != null)
|
||||||
c.setDomain (cookieDomain);
|
c.setDomain (cookieDomain);
|
||||||
response.addCookie(c);
|
response.addCookie(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
if (paramValues.length > 1)
|
if (paramValues.length > 1)
|
||||||
reqtrans.set (nextKey+"_array", paramValues); // set string array
|
reqtrans.set (nextKey+"_array", paramValues); // set string array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String contentType = request.getContentType();
|
String contentType = request.getContentType();
|
||||||
if (contentType != null && contentType.indexOf("multipart/form-data")==0) {
|
if (contentType != null && contentType.indexOf("multipart/form-data")==0) {
|
||||||
|
@ -168,7 +168,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
invalidateApp (appID);
|
invalidateApp (appID);
|
||||||
app = getApp (appID);
|
app = getApp (appID);
|
||||||
app.ping ();
|
app.ping ();
|
||||||
restrans = app.execute (reqtrans);
|
restrans = app.execute (reqtrans);
|
||||||
}
|
}
|
||||||
writeResponse (response, restrans, cookies, protocol);
|
writeResponse (response, restrans, cookies, protocol);
|
||||||
|
|
||||||
|
@ -177,9 +177,9 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
try {
|
try {
|
||||||
response.setContentType ("text/html");
|
response.setContentType ("text/html");
|
||||||
Writer out = response.getWriter ();
|
Writer out = response.getWriter ();
|
||||||
if (debug)
|
if (debug)
|
||||||
out.write ("<b>Error:</b><br>" +x);
|
out.write ("<b>Error:</b><br>" +x);
|
||||||
else
|
else
|
||||||
out.write ("This server is temporarily unavailable. Please check back later.");
|
out.write ("This server is temporarily unavailable. Please check back later.");
|
||||||
out.flush ();
|
out.flush ();
|
||||||
} catch (Exception io_e) {}
|
} catch (Exception io_e) {}
|
||||||
|
@ -187,21 +187,21 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {
|
void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {
|
||||||
|
|
||||||
for (int i = 0; i < trans.countCookies(); i++) try {
|
for (int i = 0; i < trans.countCookies(); i++) try {
|
||||||
Cookie c = new Cookie(trans.getKeyAt(i), trans.getValueAt(i));
|
Cookie c = new Cookie(trans.getKeyAt(i), trans.getValueAt(i));
|
||||||
c.setPath ("/");
|
c.setPath ("/");
|
||||||
if (cookieDomain != null)
|
if (cookieDomain != null)
|
||||||
c.setDomain (cookieDomain);
|
c.setDomain (cookieDomain);
|
||||||
int expires = trans.getDaysAt(i);
|
int expires = trans.getDaysAt(i);
|
||||||
if (expires > 0)
|
if (expires > 0)
|
||||||
c.setMaxAge(expires * 60*60*24); // Cookie time to live, days -> seconds
|
c.setMaxAge(expires * 60*60*24); // Cookie time to live, days -> seconds
|
||||||
res.addCookie(c);
|
res.addCookie(c);
|
||||||
} catch (Exception ign) {}
|
} catch (Exception ign) {}
|
||||||
|
|
||||||
if (trans.getRedirect () != null) {
|
if (trans.getRedirect () != null) {
|
||||||
try {
|
try {
|
||||||
res.sendRedirect(trans.getRedirect ());
|
res.sendRedirect(trans.getRedirect ());
|
||||||
} catch(Exception io_e) {}
|
} catch(Exception io_e) {}
|
||||||
|
|
||||||
|
|
|
@ -15,35 +15,61 @@ import helma.util.*;
|
||||||
/**
|
/**
|
||||||
* This is a standalone Hop servlet client, running a Hop application by itself.
|
* This is a standalone Hop servlet client, running a Hop application by itself.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class StandaloneServletClient extends AbstractServletClient {
|
public final class StandaloneServletClient extends AbstractServletClient {
|
||||||
|
|
||||||
private Application app = null;
|
private Application app = null;
|
||||||
private String appName;
|
private String appName;
|
||||||
private String serverProps;
|
private String serverProps;
|
||||||
|
|
||||||
|
|
||||||
public void init (ServletConfig init) throws ServletException {
|
public void init (ServletConfig init) throws ServletException {
|
||||||
super.init (init);
|
super.init (init);
|
||||||
appName = init.getInitParameter ("application");
|
appName = init.getInitParameter ("application");
|
||||||
serverProps = init.getInitParameter ("serverprops");
|
serverProps = init.getInitParameter ("serverprops");
|
||||||
|
|
||||||
super.init (init);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized IRemoteApp getApp (String appID) throws Exception {
|
IRemoteApp getApp (String appID) {
|
||||||
|
if (app == null)
|
||||||
|
createApp ();
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the application. Since we are synchronized only here, we
|
||||||
|
* do another check if the app already exists and immediately return if it does.
|
||||||
|
*/
|
||||||
|
synchronized void createApp () {
|
||||||
if (app != null)
|
if (app != null)
|
||||||
return app;
|
return;
|
||||||
try {
|
try {
|
||||||
File propfile = new File (serverProps);
|
File propfile = new File (serverProps);
|
||||||
File hopHome = new File (propfile.getParent());
|
File hopHome = new File (propfile.getParent());
|
||||||
SystemProperties sysProps = new SystemProperties (propfile.getAbsolutePath());
|
SystemProperties sysProps = new SystemProperties (propfile.getAbsolutePath());
|
||||||
app = new Application (appName, hopHome, sysProps, null);
|
app = new Application (appName, hopHome, sysProps, null);
|
||||||
|
app.init ();
|
||||||
app.start ();
|
app.start ();
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
System.err.println ("Error starting Application "+appName+": "+x);
|
System.err.println ("Error starting Application "+appName+": "+x);
|
||||||
x.printStackTrace ();
|
x.printStackTrace ();
|
||||||
}
|
}
|
||||||
return app;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The servlet is being destroyed. Close and release the application if
|
||||||
|
* it does exist.
|
||||||
|
*/
|
||||||
|
public void destroy () {
|
||||||
|
if (app != null) {
|
||||||
|
try {
|
||||||
|
app.stop ();
|
||||||
|
} catch (Exception x) {
|
||||||
|
System.err.println ("Error shutting down app "+app.getName()+": ");
|
||||||
|
x.printStackTrace ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalidateApp (String appID) {
|
void invalidateApp (String appID) {
|
||||||
|
@ -57,7 +83,7 @@ public class StandaloneServletClient extends AbstractServletClient {
|
||||||
String getRequestPath (String path) {
|
String getRequestPath (String path) {
|
||||||
// get request path
|
// get request path
|
||||||
if (path != null)
|
if (path != null)
|
||||||
return trim (path);
|
return trim (path);
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -85,23 +111,8 @@ public class StandaloneServletClient extends AbstractServletClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue