You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de> on 2003/01/24 15:33:40 UTC

FileUpload in mod-db / HttpRequest.getParameter()

Goeff,

thanks for your patch to use MultiPart with the DatabaseActions.

On 24.Jan.2003 -- 12:22 AM, Geoff Howard wrote:
> Anyway, it's all working now, autoincrement, inserting the data, and the
> database reader (pending the patch).
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16382

However, it does not work for me! It took me quite a long time with
the debugger to find the reason for this (now to the reason I cc'ed
Jeroen and cocoon-dev): 

If FilePartArray is used the uploaded file is stored inside the
request object. Fine. But how to access it there?
HttpRequest.getParameter() returns java.lang.String and thus
JDBCTypeConversions.storeColumn() tries to open a file named
"org.apache.cocoon.components.request.multipart.FilePartArray@234768" !

In which situations does FilePartArray work at all? Or is this class
completely useless?

Any idead how to make this work?

Would it be better to pass the uploaded file through a request
attribute? 

Is there some backward compatibility issue with placing the file name
in a request parameter?

Would it make sense to create an input module that first checks the
request attribute for an FilePartArray and if not found asks the
request parameter for the file name?

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 24.Jan.2003 -- 10:37 AM, Geoff Howard wrote:
> > If FilePartArray is used the uploaded file is stored inside the
> > request object. Fine. But how to access it there?
> > HttpRequest.getParameter() returns java.lang.String and thus
> > JDBCTypeConversions.storeColumn() tries to open a file named
> > "org.apache.cocoon.components.request.multipart.FilePartArray@234768" !
> 
> On second thought, FilePartArray vs FilePartFile shouldn't matter - the code
> is looking for the superclass FilePart and is only using getSize() and
> getInputStream().  I can't find where the action is getting the parameter,
> probably because of the input module abstraction.

Yes. It is in DatabaseAction.getColumnValue() which calls
InputModule.getAttribute() which in turn (for the request parameter
module) calls 
ObjectModelHelper.getRequest(objectModel).getParameter(pname)

But in HttpRequest 

    public String getParameter(String name) {
        String value = this.req.getParameter(name);
        if (this.form_encoding == null || value == null) {
            return value;
        }
        return decode(value);
    }

The FilePartArray is casted to java.lang.String returning "org.apache.cocoon....."

> Still, all this makes it weird that it works on my machine and not yours.
> Do you have local modifications that aren't checked in that could be making
> the difference?

Don't think so. Basically, I have your patches applied but that's
it. This is jdk 1.4.1_01 + tomcat 4.1.18 on debian linux.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Geoff Howard <co...@leverageweb.com>.
even weirder - I was using FilePartArray (i think - see below).  I'm using
straight out of cvs, and the default in web.xml is
    <init-param>
      <param-name>autosave-uploads</param-name>
      <param-value>false</param-value>
    </init-param>

Which should make it use FPArray.  The only glitch is that I have a parallel
webapp deployed  in the same container which has autosave-uploads set to
true.  I'll add some debugging to show what kind of object it's finding and
get back to you.

Which jdk are you using?

Geoff

> -----Original Message-----
> From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
> Sent: Friday, January 24, 2003 9:34 AM
> To: Geoff Howard
> Cc: j.tervoorde@home.nl; cocoon-dev@xml.apache.org
> Subject: FileUpload in mod-db / HttpRequest.getParameter()
>
>
> Goeff,
>
> thanks for your patch to use MultiPart with the DatabaseActions.
>
> On 24.Jan.2003 -- 12:22 AM, Geoff Howard wrote:
> > Anyway, it's all working now, autoincrement, inserting the data, and the
> > database reader (pending the patch).
> >
> > http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16382
>
> However, it does not work for me! It took me quite a long time with
> the debugger to find the reason for this (now to the reason I cc'ed
> Jeroen and cocoon-dev):
>
> If FilePartArray is used the uploaded file is stored inside the
> request object. Fine. But how to access it there?
> HttpRequest.getParameter() returns java.lang.String and thus
> JDBCTypeConversions.storeColumn() tries to open a file named
> "org.apache.cocoon.components.request.multipart.FilePartArray@234768" !
>
> In which situations does FilePartArray work at all? Or is this class
> completely useless?
>
> Any idead how to make this work?
>
> Would it be better to pass the uploaded file through a request
> attribute?
>
> Is there some backward compatibility issue with placing the file name
> in a request parameter?
>
> Would it make sense to create an input module that first checks the
> request attribute for an FilePartArray and if not found asks the
> request parameter for the file name?
>
> 	Chris.
> --
> C h r i s t i a n       H a u l
> haul@informatik.tu-darmstadt.de
>     fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Geoff Howard <co...@leverageweb.com>.
excellent - so it works for you now with that change?

> > I haven't managed to get output from JDBCTypeConversions yet (no logger
> > available and System.out is not showing up in the console - or
> it's never
> > getting to the lines I've done the poorman's debug).  But, I'd
> be willing to
>
> Yep, for reasons unknown to me, some debug messages never show
> up. E.g. I have a case where methods of the super class are logged but
> the subclass's are not :-|

In this case it was because it was never hitting any of the debug statements
because it was a String object already - I eventually got it.

> Would eclipse lie to you? ;-)

I don't trust it that implicitly - yet!  It's either going to make me lazy
or help me learn faster.  Of course, esql and the mod-db actions are going
to make me forget java!

>
> I'm glad this is sorted out and I'm really happy with your new sample.
> Thanks again!

Me too - pretty impressive to populate blobs from uploads and read them back
out with zero lines of code!  (and not that many behind the scenes).

Thanks for your help and your challenge.

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 24.Jan.2003 -- 11:25 AM, Geoff Howard wrote:
> > On second thought, FilePartArray vs FilePartFile shouldn't matter
> > - the code
> > is looking for the superclass FilePart and is only using getSize() and
> > getInputStream().  I can't find where the action is getting the parameter,
> > probably because of the input module abstraction.
> 
> Ok, I think I have it (thanks to eclipse which made finding the exact right
> lines of code almost effortless - so far it's worth every penny!).

> Shouldn't that use:
> 
> 	return ObjectModelHelper.getRequest(objectModel).get( pname ); ?
> 
> getParameter() returns String - get() returns Object.

Blimey! Yes! I've been using getParameter() for so long that I totally
forgot about get(). Well, it doesn't really say it accesses the same
thing.

So now everything is perfect now. Thanks for your help!

> I haven't managed to get output from JDBCTypeConversions yet (no logger
> available and System.out is not showing up in the console - or it's never
> getting to the lines I've done the poorman's debug).  But, I'd be willing to

Yep, for reasons unknown to me, some debug messages never show
up. E.g. I have a case where methods of the super class are logged but
the subclass's are not :-|

> bet that for whatever reason, I'm getting a FilePartFile and the toString is
> giving a usable system id somewhere and that's causing it to work by
> accident?  I haven't done debug tracing with eclipse yet - maybe it's time
> to learn.

That is my guess.

> > Normally, one does a org.apache.cocoon.environment.Request.get() on the
> > parameter name which gets a (FilePart)Object.  I'm not clear enough on
> > InputModule internals to know what it's doing.>

It really get's difficult if you rely on defaults. For example, most
places default to "request-param" if no other module short hand is
given. Same here.

> Still not real deep on the InputModule internals - is it using
> RequestParameterModule as I've guessed??

Yes, it is. Would eclipse lie to you? ;-)

I'm glad this is sorted out and I'm really happy with your new sample.
Thanks again!

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Geoff Howard <co...@leverageweb.com>.
> On second thought, FilePartArray vs FilePartFile shouldn't matter
> - the code
> is looking for the superclass FilePart and is only using getSize() and
> getInputStream().  I can't find where the action is getting the parameter,
> probably because of the input module abstraction.

Ok, I think I have it (thanks to eclipse which made finding the exact right
lines of code almost effortless - so far it's worth every penny!).

o.a.c.components.modules.input.RequestParameterModule line 80:

public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {

        String pname = name;
        if ( modeConf != null ) {
            pname = modeConf.getAttribute( "parameter", pname );
        }
        return ObjectModelHelper.getRequest(objectModel).getParameter(
pname );
    }

Shouldn't that use:

	return ObjectModelHelper.getRequest(objectModel).get( pname ); ?

getParameter() returns String - get() returns Object.

I haven't managed to get output from JDBCTypeConversions yet (no logger
available and System.out is not showing up in the console - or it's never
getting to the lines I've done the poorman's debug).  But, I'd be willing to
bet that for whatever reason, I'm getting a FilePartFile and the toString is
giving a usable system id somewhere and that's causing it to work by
accident?  I haven't done debug tracing with eclipse yet - maybe it's time
to learn.

>
> Normally, one does a org.apache.cocoon.environment.Request.get() on the
> parameter name which gets a (FilePart)Object.  I'm not clear enough on
> InputModule internals to know what it's doing.>

Still not real deep on the InputModule internals - is it using
RequestParameterModule as I've guessed??

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: FileUpload in mod-db / HttpRequest.getParameter()

Posted by Geoff Howard <co...@leverageweb.com>.
> If FilePartArray is used the uploaded file is stored inside the
> request object. Fine. But how to access it there?
> HttpRequest.getParameter() returns java.lang.String and thus
> JDBCTypeConversions.storeColumn() tries to open a file named
> "org.apache.cocoon.components.request.multipart.FilePartArray@234768" !

On second thought, FilePartArray vs FilePartFile shouldn't matter - the code
is looking for the superclass FilePart and is only using getSize() and
getInputStream().  I can't find where the action is getting the parameter,
probably because of the input module abstraction.

Normally, one does a org.apache.cocoon.environment.Request.get() on the
parameter name which gets a (FilePart)Object.  I'm not clear enough on
InputModule internals to know what it's doing.

Still, all this makes it weird that it works on my machine and not yours.
Do you have local modifications that aren't checked in that could be making
the difference?

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org