cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oskar Casquero" <jtaca...@bi.ehu.es>
Subject multipart HTTP and stream generator
Date Wed, 06 Nov 2002 19:52:00 GMT
Hi,

Has anybody tried to get data from a multipart http request in cocoon? I've modified the stream
generator with "marsh" project classes (in sourceForge.net) in order to support multipart
http resquest and it doesn't work, but I've also tested the same example in a servlet (outside
cocoon) and it works, so I don't know what happens. Where is the problem? Perhaps in HttpServletRequest
request = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);?

Oskar

Here is the generate method of the modified stream generator:
public void generate() throws IOException, SAXException, ProcessingException

{

    Parser parser = null;

    String parameter = parameters.getParameter(MyStreamGenerator.FORM_NAME, null);

    String myParameter = parameters.getParameter(MyStreamGenerator.FILE_NAME, null);

    int len = 0;

    String contentType = null;

    try {

        HttpServletRequest request = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);

        contentType = request.getContentType();

        if (contentType == null) {

            throw new IOException("Required header ContentType is missing.");

        } else if (contentType.startsWith("application/x-www-form-urlencoded")) { 

            String sXml = request.getParameter(parameter);

            inputSource = new InputSource(new StringReader(sXml));

        } else if (contentType.startsWith("multipart/form-data")) {

            // Instantiate and parse the multipart/form-data POST.

            MultipartServletRequest mpReq = new MultipartServletRequest(request);

            // Get the variables we want from the request, including the file.

            MultipartFileInfo fileInfo = mpReq.getFile(myParameter);



            InputStream fileIn = fileInfo.getFile();

            len = fileInfo.getLength();

            PostInputStream anStream = new PostInputStream(request.getInputStream(), len);

            inputSource = new InputSource(anStream);


        } else if (contentType.startsWith("text/plain") ||

            contentType.startsWith("text/xml") ||

            contentType.startsWith("application/xml")) {

            len = request.getContentLength();

            if (len > 0) {

                PostInputStream anStream = new PostInputStream(request.getInputStream(), len);

                inputSource = new InputSource(anStream);

            } else {

                throw new IOException("getContentLen() == 0");

            }

Mime
View raw message