Help me obi-wan struts-geeks. This one is puzzling me.
I need to 'stream' a stylesheet out to the browser. Due to the app,
that stylesheet is sort of generated on the fly from the database, so I
can't just point the browser at a static file.
In the document, I have:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK REL="StyleSheet" href="getConfiguredStylesheet.action"
type="text/css">
</head>
Here's the method mapped to this (note this is at the moment reading
from a file off the filesystem, not from the db - but even the comment
in the StringBuffer doesn't show up)
public void getConfiguredStylesheet() throws IOException, Exception {
logger.info("Fetching configured stylesheet...");
sessionData = ActionContext.getContext().getSession();
// Open up the .css file specified in the event
try {
InputStream is =
sc.getResourceAsStream("/public/web-emphasis.css");
logger.debug("inputstream for stylesheet should not be null. It is: "
+ is);
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
logger.debug("Setting up sb with basic stylesheet info...");
StringBuffer sb = new StringBuffer("/* Read via CSSFetcher from
web-emphasis.css */\n");
String s ;
int counter=0;
while ((s = br.readLine()) != null) {
counter++;
sb.append(s + "\n");
}
logger.debug("Stringbuffer counted " + counter + " lines, and is " +
sb.length() + " bytes long.");
is.close();
logger.debug("Writing it to the response...");
resp.getWriter().write(sb.toString());
resp.getWriter().flush();
resp.getWriter().close();
} catch (Exception e) {
logger.error(e);
logger.error(e.getMessage());
e.printStackTrace();
throw e;
}
}
Here's the problem.
The stylesheet shows up in the browser - only about 4 times out of 5.
Every 3rd, 4th, 5th, sometimes 6th webhit, there's no stylesheet. The
log, however, shows that the stylesheet went out - no matter whether
it's available in the stylesheet viewer on the browser or not, the log
always says:
2010-09-20 23:30:20,743 INFO [CSSFetcher] Fetching configured stylesheet...
2010-09-20 23:30:20,743 DEBUG [CSSFetcher] inputstream for stylesheet
should not be null. It is: java.io.bufferedinputstr...@23b35955
2010-09-20 23:30:20,744 DEBUG [CSSFetcher] Setting up sb with basic
stylesheet info...
2010-09-20 23:30:20,743 INFO [CSSFetcher] Fetching con-specific
stylesheet information...
2010-09-20 23:30:20,744 DEBUG [CSSFetcher] Stringbuffer counted 259
lines, and is 4889 bytes long.
2010-09-20 23:30:20,745 DEBUG [CSSFetcher] Writing it to the response...
My guess is there's some weird interraction with timing with how the
stylesheet is being loaded and when the browser is expecting it to be
completed. I can't for the life of me figure out what it is. The
flush() and close() lines in the method were added to attempt to 'finish
up' the connection, but they made no difference.
Help?
-d
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org