Re: HttpServletRequest.getInputStream within an Element

by Geert Bevin :: Rate this Message:

Reply to Author | View in Thread


Yeah, I've used it many times, RIFE even does within the CMF elements.

On 14 Jan 2009, at 21:18, Josh Hansen wrote:

>
> Hi all,
>
> Has anyone tried using HttpServletRequest.getInputStream() from within
> an Element?  The web services elements, specifically the
> WebserviceHessian element, refer to it, but I can't seem to actually
> read any data from it myself.
>
> Here's my code (also available at http://rifers.org/paste/show/8652):
> ==========================================
> public class ReportData extends Element {
> Logger logger =  Logger.getLogger(this.getClass().getName());
>
> public void processElement()
> {
>
> try {
> HttpServletRequest request = getHttpServletRequest();
> logger.info("getMethod()=["+getMethod()+"]");
> // This works: the content is a POST
>
> int max_length_of_data = request.getContentLength();
> // This works: the content length seems to be correct.
> logger.info("max_length_of_data: ["+max_length_of_data+"]");
>
> ServletInputStream  httpIn  = request.getInputStream();
>
> StringBuilder sb = new StringBuilder();
> byte[] buf = new byte[1000];
> int count = 0;
> try {
> // No data is ever read; even for
> // five attempts over 5 seconds...
> for( int i =0; i<=5; ++i ) {
> count = httpIn.read(buf, 0, 1000);
> logger.info("count=["+count+"]");
> if( count > -1 ) {
> String input = new String(buf,0,count);
> sb.append(input);
> }
> Thread.sleep(1000);
> }
> } catch( Exception e ) {
> logger.log(Level.INFO,e.getMessage(),e);
> }
> logger.info(""+sb.toString());
> } catch (Exception e1) {
> logger.log(Level.INFO,e1.getMessage(),e1);
> }
> return;
> }
>
> public boolean prohibitRawAccess()
> {
> return false;
> }
> }
> ==========================================
>
> All the best,
>
> Josh
> --
> Joshua Hansen
> Up Bear Enterprises
> (541) 760-7685
>
> >

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "rife-users" group.
To post to this group, send email to rife-users@...
To unsubscribe from this group, send email to rife-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rife-users?hl=en
-~----------~----~----~----~------~----~------~--~---

 
 
 
Google
rifers.org web