[jboss-user] [JBoss Seam] - Servlet Emulation and Request content problem

E6Fred do-not-reply at jboss.com
Fri Apr 6 12:01:57 EDT 2007


Hi,

I'm trying to emulate a servlet behavior with JSF and Seam.
The goal of this, is to expose an URL in my application to which I could post data using a simple HTML Form or an ESB.

I added the following in the pages.xml file :

<page view-id="/connect.xhtml" action="#{connector.doRequest}"/>

The HTML form I use to test this is as simple as :

<html>
  |   <body>
  |     <form name="myForm"    action="http://localhost:8080/myApp/connect.faces" method="POST' enctype="multipart/form-data">
  |       <input type="file" name="myFile"/>
  |       <input type="submit"/>
  |     </form>
  |   </body>
  | </html>


connector is a Stateless bean that exposes a doRequest method :
In this method, I'm trying to analyze the content of the http request that has been posted

public void doRequest(){
  |   FacesContext context = FacesContext.getCurrentInstance();
  |   HttpServletRequest request =      (HttpServletRequest)context.getExternalContext().getRequest();
  |   System.out.println("contentlength = "+request.getContentLength())
  |   byte[] data = new byte[2048];
  |   int count;
  |   InputStream is = request.getInputStream();
  |   count = is.read(data,0,2048);
  |   while(count != -1){
  |     System.out.write(data,0,count);
  |     count = is.read(data,0,2048);
  |   }
  | }

The 'request.getContentLength()' returns a value that seems to be correct (non-zero and approximately the size of the uploaded file)
but when I try to read the request content, the first 'is.read(data,0,2048)' call returns '-1' as if the stream was empty :(

I tried to add a SeamMultipartFilter but it didn't change anything

Do you think the way I proceed is able to work ?
Is there any configuration I could add somewhere to make things work ?

Thanks

Fred





View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035378#4035378

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035378



More information about the jboss-user mailing list