RE: Dynamic Email
I actually tried that earlier (my last of 3 attempts before sending this e-mail), but the InputStream associated with the HttpURLConnection has run past all the content by the time I get it. I have no idea why it does that. Here's a snipet of the code: String strURL; if( request.getServerPort() == 443 ) { strURL = https://; + request.getServerName() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } else if (request.getServerPort() == 80 ) { strURL = http://; + request.getServerName() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } else { strURL = http://; + request.getServerName() + : + request.getServerPort() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } java.net.URL url = new java.net.URL( strURL ); java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection(); java.io.InputStream in = (InputStream)conn.getInputStream(); StringBuffer strMailContent = new StringBuffer(); while ( in.available() 0 ) { strMailContent.append( (char)in.read() ); } in.close(); conn.disconnect(); message.setText( strMailContent.toString() + \r\n\r\n + text ); But for some reason in.available() almost always returns 0 bytes. I can use my debugger to see the protected byte array used by the PushbackInputStream, but can't get at any of the data since the position variable is already pointing to the end of the array and the mark() and reset() messages aren't supported. I'm guessing that it may have to do with something that either the container does or the JVM does to pool or optimize connection requests, but I don't know. If the connection DOES return the content of the URL, then on the next invocation it ALWAYS returns nothing. One more thing, using this method ALWAYS causes Tomcat to log the request, so it appears to be processing the JSP every time this code calls for it. I can also pull the JSP up multiple times in a browser without any problems. This seemed to be a fairly simple, fail-safe way to approach it, but I don't understand why it's giving me trouble... Any ideas? Thanks, Tim [EMAIL PROTECTED] 11/15/01 04:48AM Here's an idea. Its sketched out in Java, but most technologies would work. Use HttpURLConnection to open the page you want (i.e. request the page through the Tomcat server). Copy the result text into the body of the email message. Send the email message. Randy -Original Message- From: Timothy Shadel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 5:59 PM To: [EMAIL PROTECTED] Subject: RE: Dynamic Email Thanks for the tip. It looks like the developer's guide at http://jakarta.apache.org/velocity/developer-guide.html#Using% 20Velocity%20In%20Servlets is going to give me the most options there. I'd REALLY like to avoid training my group on ANOTHER view mechanism, and I'd like to take custom JSP tags that we write for initial use in HTML and reuse them in the dynamic e-mail. I'm not satisfied that Velocity will be the best solution, though it seems to be a viable one. Any other ideas of how to use JSP to generate dynamic e-mail content? - Tim [EMAIL PROTECTED] 11/14/01 03:05PM Check out Velocity at apache.org Kevin McBrearty ATG Automation Technologies Group Ltd. __ A computer lets you make mistakes faster than any other invention in human history, with the possible exception of handguns and tequila. - D.W. McArthur -Original Message- From: Timothy Shadel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 4:42 PM To: [EMAIL PROTECTED] Subject: Dynamic Email Hi, I'd like to generate dynamic e-mail content, typically based on some parameters stored in the current HttpSession. JSP seems like a great tool for this. I can easily edit the static portion of the e-mail, and have non-technical personnel work with it. I'd get all the advantages JSP gives to dynamic HTML generation. I can't seem to figure out a good way to do it, though. I've tried to use the RequestDispactcher.include(), but there's no way to change the OutputStream to recover the content that was inadvertently streamed to the browser. I can't wrap the request/response objects in the Servlet 2.2 spec (tomcat 3.x), and I'm not sure I'd know the details of how to even if I was running tomcat 4.0. I tried creating a URL and calling getContent(), which returns a PushbackInputStream, but this works only sporadically. Most of the time the buffer has been read completely, and I have no data with which to push it back. All I want to do is load a JSP page, ensure that it's processed within the current Session and Request (so it has
RE: Dynamic Email (Workaround)
I found a workaround. Apparently the content wasn't ready as soon as my thread continued, so I just added a try to Thread.sleep( 100 ) a few times and then the InputStream had data ready to go. One drawback is that the input stream never returns -1 indicating the end of the input (because the socket's still open??), so I have to fake it by allowing 3 waits of 1/10 of a second each to see if there's more data before moving on. Strange, but it seems to work reliably now... From here I'll try to tack the session information onto the request to get access to at least that in my JSP page. [EMAIL PROTECTED] 11/15/01 08:26AM I actually tried that earlier (my last of 3 attempts before sending this e-mail), but the InputStream associated with the HttpURLConnection has run past all the content by the time I get it. I have no idea why it does that. Here's a snipet of the code: String strURL; if( request.getServerPort() == 443 ) { strURL = https://; + request.getServerName() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } else if (request.getServerPort() == 80 ) { strURL = http://; + request.getServerName() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } else { strURL = http://; + request.getServerName() + : + request.getServerPort() + request.getContextPath() + /mailContent.jsp?from= + from + to= + to; } java.net.URL url = new java.net.URL( strURL ); java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection(); java.io.InputStream in = (InputStream)conn.getInputStream(); StringBuffer strMailContent = new StringBuffer(); while ( in.available() 0 ) { strMailContent.append( (char)in.read() ); } in.close(); conn.disconnect(); message.setText( strMailContent.toString() + \r\n\r\n + text ); But for some reason in.available() almost always returns 0 bytes. I can use my debugger to see the protected byte array used by the PushbackInputStream, but can't get at any of the data since the position variable is already pointing to the end of the array and the mark() and reset() messages aren't supported. I'm guessing that it may have to do with something that either the container does or the JVM does to pool or optimize connection requests, but I don't know. If the connection DOES return the content of the URL, then on the next invocation it ALWAYS returns nothing. One more thing, using this method ALWAYS causes Tomcat to log the request, so it appears to be processing the JSP every time this code calls for it. I can also pull the JSP up multiple times in a browser without any problems. This seemed to be a fairly simple, fail-safe way to approach it, but I don't understand why it's giving me trouble... Any ideas? Thanks, Tim [EMAIL PROTECTED] 11/15/01 04:48AM Here's an idea. Its sketched out in Java, but most technologies would work. Use HttpURLConnection to open the page you want (i.e. request the page through the Tomcat server). Copy the result text into the body of the email message. Send the email message. Randy -Original Message- From: Timothy Shadel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 5:59 PM To: [EMAIL PROTECTED] Subject: RE: Dynamic Email Thanks for the tip. It looks like the developer's guide at http://jakarta.apache.org/velocity/developer-guide.html#Using% 20Velocity%20In%20Servlets is going to give me the most options there. I'd REALLY like to avoid training my group on ANOTHER view mechanism, and I'd like to take custom JSP tags that we write for initial use in HTML and reuse them in the dynamic e-mail. I'm not satisfied that Velocity will be the best solution, though it seems to be a viable one. Any other ideas of how to use JSP to generate dynamic e-mail content? - Tim [EMAIL PROTECTED] 11/14/01 03:05PM Check out Velocity at apache.org Kevin McBrearty ATG Automation Technologies Group Ltd. __ A computer lets you make mistakes faster than any other invention in human history, with the possible exception of handguns and tequila. - D.W. McArthur -Original Message- From: Timothy Shadel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 4:42 PM To: [EMAIL PROTECTED] Subject: Dynamic Email Hi, I'd like to generate dynamic e-mail content, typically based on some parameters stored in the current HttpSession. JSP seems like a great tool for this. I can easily edit the static portion of the e-mail, and have non-technical personnel work with it. I'd get all the advantages JSP gives to dynamic HTML generation. I can't seem to figure out a good way to do it, though. I've tried to use the RequestDispactcher.include
Dynamic Email
Hi, I'd like to generate dynamic e-mail content, typically based on some parameters stored in the current HttpSession. JSP seems like a great tool for this. I can easily edit the static portion of the e-mail, and have non-technical personnel work with it. I'd get all the advantages JSP gives to dynamic HTML generation. I can't seem to figure out a good way to do it, though. I've tried to use the RequestDispactcher.include(), but there's no way to change the OutputStream to recover the content that was inadvertently streamed to the browser. I can't wrap the request/response objects in the Servlet 2.2 spec (tomcat 3.x), and I'm not sure I'd know the details of how to even if I was running tomcat 4.0. I tried creating a URL and calling getContent(), which returns a PushbackInputStream, but this works only sporadically. Most of the time the buffer has been read completely, and I have no data with which to push it back. All I want to do is load a JSP page, ensure that it's processed within the current Session and Request (so it has access to the needed variables), and then push that content into an e-mail message that I send using the JavaMail API. I assume that somebody else has wanted this type of thing before. If there's another solution to let end-users easily edit the static surroundings of dynamic e-mail content, where I can use templates, internationalization, and other great tools as easily as Struts, please let me know. Thanks, Tim -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: Dynamic Email
Thanks for the tip. It looks like the developer's guide at http://jakarta.apache.org/velocity/developer-guide.html#Using%20Velocity%20In%20Servlets is going to give me the most options there. I'd REALLY like to avoid training my group on ANOTHER view mechanism, and I'd like to take custom JSP tags that we write for initial use in HTML and reuse them in the dynamic e-mail. I'm not satisfied that Velocity will be the best solution, though it seems to be a viable one. Any other ideas of how to use JSP to generate dynamic e-mail content? - Tim [EMAIL PROTECTED] 11/14/01 03:05PM Check out Velocity at apache.org Kevin McBrearty ATG Automation Technologies Group Ltd. __ A computer lets you make mistakes faster than any other invention in human history, with the possible exception of handguns and tequila. - D.W. McArthur -Original Message- From: Timothy Shadel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 4:42 PM To: [EMAIL PROTECTED] Subject: Dynamic Email Hi, I'd like to generate dynamic e-mail content, typically based on some parameters stored in the current HttpSession. JSP seems like a great tool for this. I can easily edit the static portion of the e-mail, and have non-technical personnel work with it. I'd get all the advantages JSP gives to dynamic HTML generation. I can't seem to figure out a good way to do it, though. I've tried to use the RequestDispactcher.include(), but there's no way to change the OutputStream to recover the content that was inadvertently streamed to the browser. I can't wrap the request/response objects in the Servlet 2.2 spec (tomcat 3.x), and I'm not sure I'd know the details of how to even if I was running tomcat 4.0. I tried creating a URL and calling getContent(), which returns a PushbackInputStream, but this works only sporadically. Most of the time the buffer has been read completely, and I have no data with which to push it back. All I want to do is load a JSP page, ensure that it's processed within the current Session and Request (so it has access to the needed variables), and then push that content into an e-mail message that I send using the JavaMail API. I assume that somebody else has wanted this type of thing before. If there's another solution to let end-users easily edit the static surroundings of dynamic e-mail content, where I can use templates, internationalization, and other great tools as easily as Struts, please let me know. Thanks, Tim -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: Byte Serving PDF's
I wrote a small servlet that went through PDF's byte by byte sending them to the output stream. It also looked for default values in PDF form fields and replaced them with parameters sent in by the request. Here's a slice of the code, but it's the part that loads the PDF file. The actual writing of the bytes to the OutputStream occurs in fillTemplateFileWithValues(), a portion of which is below. public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType( application/pdf ); try { InputStream template = getServletContext().getResourceAsStream( processPath(req) + .pdf ); OutputStream custom = res.getOutputStream(); PDFConverter convert = new PDFConverter( template, custom, buildParameterMap(req) ); convert.fillTemplateFileWithValues(); res.setContentLength( convert.getBytesSent() ); template.close(); custom.close(); } catch ( FileNotFoundException fnfe ) { fnfe.printStackTrace(); } catch ( SecurityException se ) { se.printStackTrace(); } catch ( InvalidStreamException ise ) { ise.printStackTrace(); } } This is the loop that outputs the PDF bytes that are definitely not going to be replaced. Another loop looks for strings to replace. while ( !inString (lastByteRead != EOF) ) { try { lastByteRead = templateFile.read(); } catch (IOException ioe) { ioe.printStackTrace(); lastByteRead = EOF; break; } // If we hit EOF, get out of this loop. // The others will take care of themselves. if( lastByteRead == EOF ) { break; // Found the start of a string } else if( lastByteRead == '(' ) { inString = true; } try { convertedFile.write( lastByteRead ); bytesSent = bytesSent + 1; } catch (IOException ioe) { ioe.printStackTrace(); lastByteRead = EOF; break; } } You could probably do this a lot simpler because you aren't replacing any PDF content, but this code's worked well for me. I don't know if it will solve your problem, though. It certainly doesn't stream it on a one-page-at-a-time basis, and it wouldn't display for us until we called setContentLength(). Of course, if you know that ahead of time (we can't for replacing), then you might luck out. Hope that helps... Tim [EMAIL PROTECTED] 11/14/01 03:59PM Yes. It's not only possible, but support for it is built in to most modern web servers. The PDF has to be optimized for byte-serving and the web server has to be capable of byte-serving. So my question remains. Anyone out there done it or know how to configure Tomcat 4 to do it? -T -Original Message- From: Chris Tucker [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 5:48 PM To: Tomcat Users List Subject: RE: Byte Serving PDF's Is this even possible? From my understanding of the PDF format, it is inherently random-access and relies on the entire file being available before it can be displayed. -Original Message- From: MacDonald, Todd [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 2:24 PM To: 'Tomcat Users List' Subject: RE: Byte Serving PDF's The PDF's are pre-existing. I need to byte serve them (for page-at-a-time access via the Acrobat Reader plug-in in the client's browser). Currently we have a servlet that reads the file and streams the whole thing back. Some of the PDF's are quite large (13 megs). This means that the user has to wait until all 13 megs are received before s/he can view it. Byte-serving solves that problem, I just don't know how to do it. -T -Original Message- From: Jim Urban [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 4:54 PM To: Tomcat Users List Subject: RE: Byte Serving PDF's Do you want to dynamically generate the PDF on the fly and return it directly to the browser or to simply serve PDF files? If you want to do the first, check out the FOP website and have a look at the FOPServlet source code. This assumes you can make the contents of the PDF available in XML format for processing by FOP. Jim -Original Message- From: MacDonald, Todd [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 14, 2001 1:53 PM To: Tomcat-User (E-mail) Subject: Byte Serving PDF's Anyone know how (or better yet, have some code to) byte serve PDF's through Tomcat 4? -T -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with
Re: multithreaded beans, struts, doing it right...
One option the Struts framework offers to deal with this is generating an MD5 hash (token) on some fairly unique data (current time and Session object ID), and then placing that hash in both the HTML sent to the browser and the Session object. When a request comes in, the MD5 hash from the browser is sent as a hidden variable. The business bean then checks that hash against the one in the Session. If they match, it first removes the hash from the Session object (so no duplicate submission will work), and then completes its processing. This way the same transaction can't be processed twice, and an old transaction won't be processed after a new one begins. The code is fairly simple, and is available for inspection in the Struts source. Hope this gives you some ideas, Tim Dmitri Colebatch [EMAIL PROTECTED] 06/19/01 05:35PM Ok, yeah that makes sense. What you want to do then is ensure that your business objects are only processing one thread at once. I'm guessing that you could do this in a similar way that ejb containers serialize access to an ejb. (THinking aloud here): Lets see, you currently have an object, called say BusinessBean that has a method called business(Object parameters), or something similar? rename business to doBusiness. create a member of the BusinessBean for a lock and a flag to indicate if we're active or not: // the lock to serializing access private Object LOCK = new Object(); // are we currently active private boolean active = false; replace the business method with something like this: ReturnType business(Object parameters) { // is it ok to execute boolean ok = false; // while its not ok - look to see when it becomes ok while (!ok) { // ensure we're the only one looking synchronized(LOCK) { // if no one else is executing - lets go if (!active) { ok = true; // set the active flags so other // threads will now wait active = true; } } // if its not ok to execute, wait if (!ok) wait(); } // execute the method and hold the return ReturnType r = doBusiness(parameters); // now reset the active flag and notify any waiting threads synchronized(LOCK) { active = false; notify(); } // the final return return r; } as I said.,.. thinking aloud (or via email)... but I think something like that you would ensure that only one thread is executing on the doBusiness at one time... although if you have a problem with the same command being executed twice then you have to do other things too (o: If I've missed something here, I'd love someone to point it out - I'm hoping to get something out of this too (o: cheesr dim On Wed, 20 Jun 2001 08:59, Russ Freeman wrote: Kind of :) In fact your solution isn't far away. I am currently supporting multiple threads of activity within the same browser window and hence session. Let's say we have a big table on a page with two columns, where each column is like a view. Each column view is displaying a different aspect of some business data and each column/pane has its own set of links too. If the user clicks a link in the left pane, the URI is sent with ID 1 encoded in the URI and if they click a link in the right pane, the URI is sent with ID 2 encoded in it. (The ID is a lookup into a Map of business objects). This is similar to what you were saying I think. However this works OK until the user accidentally double clicks one of the links and the same business object gets two requests, where the first isn't finished before it recieves the second. So far I have ensured that each business object is thread safe and I have yet to detmine if this will work or whether I have just covered up another problem! Does this help? Cheers, Russ - Original Message - From: Dmitri Colebatch [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Russ Freeman [EMAIL PROTECTED] Sent: Tuesday, June 19, 2001 11:24 PM Subject: Re: multithreaded beans, struts, doing it right... By multiple threads of activity do you mean the user has multiple windows open? If so, perhaps in the user's session you could have a Map of business logic beans instead of just one. And somehow have the client identify which thread of activity the currenty action is part of, from there
Default web.xml
I have a quick question about how the default web.xml found in the conf directory is supposed to act. The Tomcat User's guide says it acts as a default web.xml for all web applications. I tried to add the following to it: servlet-mapping !-- This was there by default -- servlet-name jsp /servlet-name url-pattern *.jsp /url-pattern /servlet-mapping servlet-mapping !-- I added this -- servlet-name jsp /servlet-name url-pattern *.tem /url-pattern /servlet-mapping because we wanted to logically separate our JSP files used as templates from those providing major content. However, accessing a valid JSP file that's been renamed with a .tem extension returns only the actual file contents instead of being translated as a JSP. The same servlet-mapping tag works perfectly in an application's web.xml. Am I supposed to be able to modify the web.xml in the conf directory and have it affect all applications, or is it only supposed to work with the one that comes with Tomcat by default? Thanks, Tim Shadel
Re: Default web.xml
I get this with both Tomcat 3.2.1 and 3.2.2. I'm using JDK 1.2.2. No error message appears. I just get the full text of the JSP file as if it were a text file (i.e. NO preprocessing at all) when I access /basic/login.tem Here are excerpts from the stderr.log (I've got Tomcat setup as a 2000 service on my development machine). The log shows two contexts: 1) /basic where no special JSP setup has been made, but the changes to the DEFAULT web.xml have been made. 2) /teacherapplication where the exact same servlet-mapping tag in the default web.xml was also placed in the APPLICATION's web.xml. Log excerpt # 1) 2001-06-15 12:57:21 - ContextManager: SimpleMapper1: SM: extension map /basic/*.jsp Ct (jsp(org.apache.jasper.servlet.JspServlet/null) ) Log excerpt # 2) 2001-06-15 12:57:21 - ContextManager: SimpleMapper1: SM: extension map /teacherapplication/*.jsp Ct (jsp(org.apache.jasper.servlet.JspServlet/null) ) 2001-06-15 12:57:21 - ContextManager: SimpleMapper1: SM: extension map /teacherapplication/*.tem Ct (jsp(org.apache.jasper.servlet.JspServlet/null) ) The log seems to show that there isn't an extension mapping being created for all contexts - just the one where I explicitly told it to in the APPLICATION web.xml. That's why I'm wondering if Tomcat is *supposed* to create the extension mapping based on the default web.xml, or if it's only supposed to use the DEFAULT provided with Tomcat without changes (i.e. is this a bug or a feature). Thanks, Tim Shadel Luba Powell [EMAIL PROTECTED] 06/15/01 02:06PM What is the error message you are getting? - Original Message - From: cathy moffatt [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 15, 2001 4:09 PM Subject: RE: Default web.xml After much difficulty I did manage to get Tomcat3.2.2 to run servlets jsp, but only with JDK1.3.1 not JDK1.3.0_02 I suspect an incompatibility problem -Original Message- From: Michael Wentzel [mailto:[EMAIL PROTECTED]] Sent: Friday, June 15, 2001 3:05 PM To: '[EMAIL PROTECTED]' Subject: RE: Default web.xml What version of tomcat are you running? --- Michael Wentzel Software Developer Software As We Think - http://www.aswethink.com Timothy Shadel I have a quick question about how the default web.xml found in the conf directory is supposed to act. The Tomcat User's guide says it acts as a default web.xml for all web applications. I tried to add the following to it: servlet-mapping !-- This was there by default -- servlet-name jsp /servlet-name url-pattern *.jsp /url-pattern /servlet-mapping servlet-mapping !-- I added this -- servlet-name jsp /servlet-name url-pattern *.tem /url-pattern /servlet-mapping because we wanted to logically separate our JSP files used as templates from those providing major content. However, accessing a valid JSP file that's been renamed with a .tem extension returns only the actual file contents instead of being translated as a JSP. The same servlet-mapping tag works perfectly in an application's web.xml. Am I supposed to be able to modify the web.xml in the conf directory and have it affect all applications, or is it only supposed to work with the one that comes with Tomcat by default? Thanks, Tim Shadel