[beanutils] converting HTTP params into an arbitrary object model

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[beanutils] converting HTTP params into an arbitrary object model

ahardy66
I have spent a day researching and prototyping with various open-source
options available which facilitate converting an HTTP request's
parameters into an object model of javabeans in a JPA persistence
framework.

I don't want to re-invent the wheel and I was quite confident that
BeanUtils could handle it all, but I have now come across some areas
where I need to code it myself.

I just wanted to ask BeanUtils developers what the future holds in terms
of my aims, as I'll take that as guidance on how much to code around
BeanUtils and how much to compromise to get what I need, when there's a
strong chance of being able to ditch the code I'll have to write now, to
replace it with ideally just a couple of calls to BeanUtils.

The main thing I have to work around is the inability of a custom
Converter to know what class of entity beans belong in a list or set. If
the Converter could see the entity bean owning the list (the parent in
the parent-child entity relationship), then in Java 1.5+ it could work
out by reflection how it has been parameterized with generics and which
child entity bean belongs in the list.

Just in case you were going to point me to OGNL to do this, thanks but
I've been there and have some other issues with that.

Best regards
Adam



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

Andrew Hughes-5
I have no idea if this suits your needs, but JXPath has a HTTP Request
expression parser. So you can then 'pick' out of the http request/session...
etc  whatever you want using an XPath expression.
http://commons.apache.org/jxpath/users-guide.html#Servlet_Contexts



On Sun, Feb 22, 2009 at 6:34 AM, Adam Hardy <
[hidden email]> wrote:

> I have spent a day researching and prototyping with various open-source
> options available which facilitate converting an HTTP request's parameters
> into an object model of javabeans in a JPA persistence framework.
>
> I don't want to re-invent the wheel and I was quite confident that
> BeanUtils could handle it all, but I have now come across some areas where I
> need to code it myself.
>
> I just wanted to ask BeanUtils developers what the future holds in terms of
> my aims, as I'll take that as guidance on how much to code around BeanUtils
> and how much to compromise to get what I need, when there's a strong chance
> of being able to ditch the code I'll have to write now, to replace it with
> ideally just a couple of calls to BeanUtils.
>
> The main thing I have to work around is the inability of a custom Converter
> to know what class of entity beans belong in a list or set. If the Converter
> could see the entity bean owning the list (the parent in the parent-child
> entity relationship), then in Java 1.5+ it could work out by reflection how
> it has been parameterized with generics and which child entity bean belongs
> in the list.
>
> Just in case you were going to point me to OGNL to do this, thanks but I've
> been there and have some other issues with that.
>
> Best regards
> Adam
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

ahardy66

Hi Andrew

I've done it now with BeanUtils - it was mainly a question of getting the
iteration and recursion algorithm right.

I know the odds are that I re-invented the wheel but I just couldn't find the
existing wheel, so to speak.

If it blows up in unexpected ways that leave me stranded, I'll definitely check
up on JXPath.

Thanks
Adam

Andrew Hughes on 22/02/09 22:15, wrote:

> I have no idea if this suits your needs, but JXPath has a HTTP Request
> expression parser. So you can then 'pick' out of the http request/session...
> etc  whatever you want using an XPath expression.
> http://commons.apache.org/jxpath/users-guide.html#Servlet_Contexts
>
>
>
> On Sun, Feb 22, 2009 at 6:34 AM, Adam Hardy <
> [hidden email]> wrote:
>
>> I have spent a day researching and prototyping with various open-source
>> options available which facilitate converting an HTTP request's parameters
>> into an object model of javabeans in a JPA persistence framework.
>>
>> I don't want to re-invent the wheel and I was quite confident that
>> BeanUtils could handle it all, but I have now come across some areas where I
>> need to code it myself.
>>
>> I just wanted to ask BeanUtils developers what the future holds in terms of
>> my aims, as I'll take that as guidance on how much to code around BeanUtils
>> and how much to compromise to get what I need, when there's a strong chance
>> of being able to ditch the code I'll have to write now, to replace it with
>> ideally just a couple of calls to BeanUtils.
>>
>> The main thing I have to work around is the inability of a custom Converter
>> to know what class of entity beans belong in a list or set. If the Converter
>> could see the entity bean owning the list (the parent in the parent-child
>> entity relationship), then in Java 1.5+ it could work out by reflection how
>> it has been parameterized with generics and which child entity bean belongs
>> in the list.
>>
>> Just in case you were going to point me to OGNL to do this, thanks but I've
>> been there and have some other issues with that.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

Matt Benson
In reply to this post by ahardy66

--- On Sat, 2/21/09, Adam Hardy <[hidden email]> wrote:

> From: Adam Hardy <[hidden email]>
> Subject: [beanutils] converting HTTP params into an arbitrary object model
> To: [hidden email]
> Date: Saturday, February 21, 2009, 2:04 PM
> I have spent a day researching and
> prototyping with various open-source options available which
> facilitate converting an HTTP request's parameters into an
> object model of javabeans in a JPA persistence framework.
>
> I don't want to re-invent the wheel and I was quite
> confident that BeanUtils could handle it all, but I have now
> come across some areas where I need to code it myself.
>
> I just wanted to ask BeanUtils developers what the future
> holds in terms of my aims, as I'll take that as guidance on
> how much to code around BeanUtils and how much to compromise
> to get what I need, when there's a strong chance of being
> able to ditch the code I'll have to write now, to replace it
> with ideally just a couple of calls to BeanUtils.
>
> The main thing I have to work around is the inability of a
> custom Converter to know what class of entity beans belong
> in a list or set. If the Converter could see the entity bean
> owning the list (the parent in the parent-child entity
> relationship), then in Java 1.5+ it could work out by
> reflection how it has been parameterized with generics and
> which child entity bean belongs in the list.
>
> Just in case you were going to point me to OGNL to do this,
> thanks but I've been there and have some other issues with
> that.

You may want to check out Morph @ http://morph.sourceforge.net .  OOTB, it can "reflect" ServletRequest parameters as bean properties and do a straight copy, as long as the servlet API is found on the classpath.

HTH,
Matt

>
> Best regards
> Adam
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


     

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

ahardy66
Matt Benson on 23/02/09 16:23, wrote:
--- On Sat, 2/21/09, Adam Hardy wrote:
> > >> I have spent a day researching and prototyping with various open-source
>> options available which facilitate converting an HTTP request's parameters
>> into an object model of javabeans in a JPA persistence framework.
>>
>
> You may want to check out Morph @ http://morph.sourceforge.net .  OOTB, it
> can "reflect" ServletRequest parameters as bean properties and do a straight
> copy, as long as the servlet API is found on the classpath.

I had a look at morph (following the link from the beanutils wiki) but their
website didn't really enlighten me and what I did find didn't look very helpful,
so I made a management decision not to pursue it.

The problem is that there are that many little details to check for, e.g. can it
handle sets, can it deduce the javabean items on generics, can it handle indexed
lists of ".0, .1, .2" notation etc

Regards
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

Matt Benson
In reply to this post by ahardy66



--- On Tue, 2/24/09, Adam Hardy <[hidden email]> wrote:

> From: Adam Hardy <[hidden email]>
> Subject: Re: [beanutils] converting HTTP params into an arbitrary object model
> To: "Commons Users List" <[hidden email]>
> Date: Tuesday, February 24, 2009, 3:19 AM
> Matt Benson on 23/02/09 16:23,
> wrote:
> --- On Sat, 2/21/09, Adam Hardy wrote:
> > > >> I have spent a day researching and
> prototyping with various open-source
> >> options available which facilitate converting an
> HTTP request's parameters into an object model of javabeans
> in a JPA persistence framework.
> >>
> >
> > You may want to check out Morph @ http://morph.sourceforge.net .  OOTB, it can
> "reflect" ServletRequest parameters as bean properties and
> do a straight copy, as long as the servlet API is found on
> the classpath.
>
> I had a look at morph (following the link from the
> beanutils wiki) but their
> website didn't really enlighten me and what I did find
> didn't look very helpful,
> so I made a management decision not to pursue it.
>
> The problem is that there are that many little details to
> check for, e.g. can it handle sets, can it deduce the
> javabean items on generics, can it handle indexed lists of
> ".0, .1, .2" notation etc
>

Morph is not generics-enabled; it can handle most of your basic non-generic constructs (e.g. Sets) right out of the box and just about anything else you can throw at it if you want to implement its API here and there for custom transformations, and while I am 100% sure it can handle [n] index notation I am about 90% sure it also handles indices as property names as you have described (.n)--if not, that is pluggable.  But this isn't the Morph list and, as you said, you made a management decision not to pursue it.  As a Morph team member I will take your "documentation didn't look very helpful" criticism under advisement as well.

Regards,
Matt

> Regards
> Adam
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

Niall Pemberton
On Tue, Feb 24, 2009 at 3:09 PM, Matt Benson <[hidden email]> wrote:

>
> --- On Tue, 2/24/09, Adam Hardy <[hidden email]> wrote:
>
>> From: Adam Hardy <[hidden email]>
>> Subject: Re: [beanutils] converting HTTP params into an arbitrary object model
>> To: "Commons Users List" <[hidden email]>
>> Date: Tuesday, February 24, 2009, 3:19 AM
>> Matt Benson on 23/02/09 16:23,
>> wrote:
>> --- On Sat, 2/21/09, Adam Hardy wrote:
>> > > >> I have spent a day researching and
>> prototyping with various open-source
>> >> options available which facilitate converting an
>> HTTP request's parameters into an object model of javabeans
>> in a JPA persistence framework.
>> >>
>> >
>> > You may want to check out Morph @ http://morph.sourceforge.net .  OOTB, it can
>> "reflect" ServletRequest parameters as bean properties and
>> do a straight copy, as long as the servlet API is found on
>> the classpath.
>>
>> I had a look at morph (following the link from the
>> beanutils wiki) but their
>> website didn't really enlighten me and what I did find
>> didn't look very helpful,
>> so I made a management decision not to pursue it.
>>
>> The problem is that there are that many little details to
>> check for, e.g. can it handle sets, can it deduce the
>> javabean items on generics, can it handle indexed lists of
>> ".0, .1, .2" notation etc
>>
>
> Morph is not generics-enabled; it can handle most of your basic non-generic constructs (e.g. Sets) right out of the box and just about anything else you can throw at it if you want to implement its API here and there for custom transformations, and while I am 100% sure it can handle [n] index notation I am about 90% sure it also handles indices as property names as you have described (.n)--if not, that is pluggable.  But this isn't the Morph list and, as you said, you made a management decision not to pursue it.  As a Morph team member I will take your "documentation didn't look very helpful" criticism under advisement as well.
>

Yeah its out-of-date

http://tinyurl.com/dhsupb

Niall

> Regards,
> Matt
>
>> Regards
>> Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

ahardy66
Niall Pemberton on 25/02/09 10:54, wrote:

> On Tue, Feb 24, 2009 at 3:09 PM, Matt Benson <[hidden email]> wrote:
>>> --- On Sat, 2/21/09, Adam Hardy wrote: The problem is that there are that
>>> many little details to check for, e.g. can it handle sets, can it deduce
>>> the javabean items on generics, can it handle indexed lists of ".0, .1,
>>> .2" notation etc
>>>
>> Morph is not generics-enabled; it can handle most of your basic non-generic
>> etc etc [snipped]
>
> Yeah its out-of-date
>
> http://tinyurl.com/dhsupb

Hi Niall,
were you skiing? that's the only valid excuse I'll accept for your tardy
response I'm afraid. Well ok i might let you off for anything involving
hospitalisation, death or taxes ;)

Is there any kind of roadmap for beanutils to bring in decent locale handling
and more refined converter mapping? (mapping a converter to a property, not just
a complete class)

I like beanutils - some people say it's got a (inter-)face only a mother could
love, but I think it's OK.


regards
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] converting HTTP params into an arbitrary object model

Niall Pemberton
On Wed, Feb 25, 2009 at 12:53 PM, Adam Hardy
<[hidden email]> wrote:

> Niall Pemberton on 25/02/09 10:54, wrote:
>>
>> On Tue, Feb 24, 2009 at 3:09 PM, Matt Benson <[hidden email]> wrote:
>>>>
>>>> --- On Sat, 2/21/09, Adam Hardy wrote: The problem is that there are
>>>> that
>>>> many little details to check for, e.g. can it handle sets, can it deduce
>>>> the javabean items on generics, can it handle indexed lists of ".0, .1,
>>>> .2" notation etc
>>>>
>>> Morph is not generics-enabled; it can handle most of your basic
>>> non-generic
>>> etc etc [snipped]
>>
>> Yeah its out-of-date
>>
>> http://tinyurl.com/dhsupb
>
> Hi Niall,
> were you skiing? that's the only valid excuse I'll accept for your tardy
> response I'm afraid. Well ok i might let you off for anything involving
> hospitalisation, death or taxes ;)

Yes all of those I'm afraid!

> Is there any kind of roadmap for beanutils to bring in decent locale
> handling and more refined converter mapping? (mapping a converter to a
> property, not just a complete class)

None that I know of.

> I like beanutils - some people say it's got a (inter-)face only a mother
> could love, but I think it's OK.

:)

Niall

> regards
> Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[beanutils] testing around ConvertUtils

ahardy66
In my unit tests I sometimes have the situation where I need to register my
custom converters for ConvertUtils in order to make everything behave as it
would in real life.

Normally the conversions are incidental to the test so it seems unnecessary to
need to set up ConvertUtils.

Seeing inside the ConvertUtils class that there is a ConvertUtilsBean, I had the
idea of using the ConvertUtilsBean in my classes, and initializing it via
dependency injection.

Then I could mock it.

However all access to the ConvertUtilsBean via the singleton getInstance factory
method is protected. Would it be unwise to instantiate it myself in my
dependency injection container?


Thanks
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] testing around ConvertUtils

Paul Benedict
Why can't you set up the test just like you would in real life? How do
you register your converters today?

On Thu, Mar 5, 2009 at 3:22 AM, Adam Hardy
<[hidden email]> wrote:

> In my unit tests I sometimes have the situation where I need to register my
> custom converters for ConvertUtils in order to make everything behave as it
> would in real life.
>
> Normally the conversions are incidental to the test so it seems unnecessary
> to need to set up ConvertUtils.
>
> Seeing inside the ConvertUtils class that there is a ConvertUtilsBean, I had
> the idea of using the ConvertUtilsBean in my classes, and initializing it
> via dependency injection.
>
> Then I could mock it.
>
> However all access to the ConvertUtilsBean via the singleton getInstance
> factory method is protected. Would it be unwise to instantiate it myself in
> my dependency injection container?
>
>
> Thanks
> Adam
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] testing around ConvertUtils

ahardy66
Hi Paul,

I do register them now, but I asked the question because I wanted to avoid it,
to keep my unit testing faster and easier.

I guess now that I've written a routine to set up the Converter, it's no more
hassle than setting up a mock, but in my ideal architecture, I would want to see
it mocked out instead.



Paul Benedict on 12/03/09 02:42, wrote:
> Why can't you set up the test just like you would in real life? How do
> you register your converters today?
>


> On Thu, Mar 5, 2009 at 3:22 AM, Adam Hardy
> <[hidden email]> wrote:
>> In my unit tests I sometimes have the situation where I need to register my
>> custom converters for ConvertUtils in order to make everything behave as it
>> would in real life.
>>
>> Normally the conversions are incidental to the test so it seems unnecessary
>> to need to set up ConvertUtils.
>>
>> Seeing inside the ConvertUtils class that there is a ConvertUtilsBean, I had
>> the idea of using the ConvertUtilsBean in my classes, and initializing it
>> via dependency injection.
>>
>> Then I could mock it.
>>
>> However all access to the ConvertUtilsBean via the singleton getInstance
>> factory method is protected. Would it be unwise to instantiate it myself in
>> my dependency injection container?


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]