HttpServletRequest.getInputStream within an Element

View: New views
4 Messages — Rating Filter:   Alert me  

HttpServletRequest.getInputStream within an Element

by Joshua Hansen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---


Re: HttpServletRequest.getInputStream within an Element

by Geert Bevin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
-~----------~----~----~----~------~----~------~--~---


Re: HttpServletRequest.getInputStream within an Element

by Joshua Hansen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The only element class I see in com.uwyn.rife.cmf.elements is
ContentStore, which writes to the Response rather than reading from the
Request.  Did I miss something?

I'm guessing that what is occurring is that the InputStream has already
been slurped by RIFE, so there isn't anything left in it for me to read
by the time I get to it.

Regarding the web services elements for SoapXFire & Hessian
(com.uwyn.rife.engine.elements.SoapXFire & WebservicesHessian), is there
something about overriding the getDeploymentClass() method that prevents
RIFE from slurping up the InputStream like it normally would?

Josh
--
Joshua Hansen
Up Bear Enterprises
(541) 760-7685


Geert Bevin wrote:

> 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
-~----------~----~----~----~------~----~------~--~---


Re: HttpServletRequest.getInputStream within an Element

by gabriel munteanu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


i do it like this:
call setProhibitRawAccess(false); in public void initialize() {}
method, and it works.

regards,
gabi

On Wed, Jan 14, 2009 at 10:18 PM, Josh Hansen <joshuah@...> 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
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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