Skip to content

Commit

Permalink
avoid IllegalStateException related to recycled request objects in To…
Browse files Browse the repository at this point in the history
…mcat
  • Loading branch information
loitly committed Jun 24, 2024
1 parent c95b830 commit 02ea84b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docker/launchTomcat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fi

if [ "$1" = "--help" ] || [ "$1" = "-help" ] || [ "$1" = "-h" ]; then
sed "s:ipac/firefly:${NAME}:" ./start-examples.txt
aWarFile=`ls ${CATALINA_HOME}/webapps/*.war | head -1 | awk '{print $1}'`
aWarFile=`ls ${CATALINA_HOME}/webapps-ref/*.war | head -1 | awk '{print $1}'`
onlyWar=`echo ${aWarFile} | awk -F/ '{print $NF}'`
if [ "$onlyWar" = "firefly.war" ]; then
cat ./customize-firefly.txt
Expand Down
2 changes: 1 addition & 1 deletion docker/setupFireflyExample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - modify the script line of the html files so that they will load
# to test: http://localhost:<port>/local/
#
aWarFile=`ls ${CATALINA_HOME}/webapps/*.war | head -1 | awk '{print $1}'`
aWarFile=`ls ${CATALINA_HOME}/webapps-ref/*.war | head -1 | awk '{print $1}'`
onlyWar=`echo ${aWarFile} | awk -F/ '{print $NF}'`
dirEmpty=`find /local/www -maxdepth 0 -empty -exec echo true \;`
if [ "$onlyWar" = "firefly.war" ] && [ "$dirEmpty" = "true" ]; then
Expand Down
49 changes: 24 additions & 25 deletions src/firefly/java/edu/caltech/ipac/firefly/server/RequestAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static edu.caltech.ipac.util.StringUtils.applyIfNotEmpty;

/**
* Date: 4/20/15
* This class acts as an agent for the underlaying request. A request can initiate from different sources.
Expand Down Expand Up @@ -146,17 +148,25 @@ protected Map<String, Cookie> extractCookies() {
//====================================================================

public static class HTTP extends RequestAgent {
public static String AUTH_KEY = "JOSSO_SESSIONID";
public static String TO_BE_DELETE = "-";
private static final String AUTH_KEY = "JOSSO_SESSIONID";
private static final Logger.LoggerImpl LOG = Logger.getLogger();
private HttpServletRequest request;
private HttpServletResponse response;
private static final String[] ID_COOKIE_NAMES = new String[]{AUTH_KEY, "ISIS"};
private final HashMap<String, String> headers = new HashMap<>(); // key stored as lowercase; multiple values are separated by \t.
private final HashMap<String, Cookie> cookies = new HashMap<>();
private final HttpServletResponse response;
private final String realPath;



public HTTP(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;

Collections.list(request.getHeaderNames()).forEach(h -> {
headers.put(h.toLowerCase(), StringUtils.toString(Collections.list(request.getHeaders(h)), "\t"));
});
applyIfNotEmpty(request.getCookies(), v -> {
Arrays.stream(v).forEach(c -> cookies.put(c.getName(), c));
});

// getting the base url including the application path is a bit tricky when behind reverse proxy(ies)
String proto = getHeader("X-Forwarded-Proto", request.getScheme());
String host = getHeader("X-Forwarded-Host", getHeader("X-Forwarded-Server", request.getServerName()));
Expand Down Expand Up @@ -188,24 +198,18 @@ public HTTP(HttpServletRequest request, HttpServletResponse response) {
setRemoteIP(remoteIP);
setSessId(request.getSession(true).getId());
setServletPath(request.getServletPath());

realPath = request.getServletContext().getRealPath("/");
}

@Override
protected Map<String, Cookie> extractCookies() {
HashMap<String, Cookie> cookies = new HashMap<>();
if (request != null) {
if (request.getCookies() != null) {
for (javax.servlet.http.Cookie c : request.getCookies()) {
cookies.put(c.getName(), c);
}
}
}
return cookies;
}

@Override
public String getRealPath(String relPath) {
return response != null ? request.getRealPath(relPath) : null;
return new File(realPath, relPath).getAbsolutePath();
}

@Override
Expand All @@ -217,13 +221,8 @@ public void sendCookie(Cookie cookie) {

@Override
public String getHeader(String name, String def) {
if (request != null) {
String retval = request.getHeader(name);
retval = retval == null ? request.getHeader(name.toLowerCase()) : retval;
return StringUtils.isEmpty(retval) ? def : retval;
} else {
return def;
}
String retval = name == null ? null : headers.get(name.toLowerCase());
return StringUtils.isEmpty(retval) ? def : retval;
}

@Override
Expand Down

0 comments on commit 02ea84b

Please sign in to comment.