struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Mohan <rahul.mo...@tcs.com>
Subject Re: Bizarre sporadic problem with streaming a stylesheet.
Date Tue, 21 Sep 2010 05:42:10 GMT
Dave,

Did you take a look at this request through Firebug? It might show some 
useful info. Also, is the content type proper (text/css) in the request 
header? I can't see you setting it anywhere. 

- Rahul



From:
Dave Belfer-Shevett <dbs@homeport.org>
To:
user@struts.apache.org
Date:
21-09-2010 10:07
Subject:
Bizarre sporadic problem with streaming a stylesheet.



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.BufferedInputStream@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message