You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@progress.com> on 2009/09/07 11:28:48 UTC

JAXRS : Generating code snippets on the fly (Re: Starting to investigate schema-driven bindings with JAXRS)

> If you want to use JAX-RS, presumably you want to talk to your web service
from Javascript

I'm sure a number of users will agree with you but some won't - it basically makes the idea if having the JAVA-based RESTful API a 
non-starter.

However what I'd really like to suggest here is that we indeed do JavaScript generation or indeed generate the code snippets in a 
language asked by user.
We've discussed it before a bit. basically the idea is to handle system queries like

_planguage=jscript
_planguage=java
etc

where planguage is a progaramming language of some sort (_language may be reserved for HTTP Aceept-Language).

We can work together on some initial  JavaScript code generator, given your experience in this area...It can be done similar to the 
way WADLGenerator is done.

cheers, Sergey

----- Original Message ----- 
From: "Benson Margulies" <bi...@gmail.com>
To: <us...@cxf.apache.org>
Sent: Sunday, September 06, 2009 3:13 AM
Subject: Re: Starting to investigate schema-driven bindings with JAXRS


Allow me to add some bits of doubt to your thought process here.

If you want to use JAX-RS, presumably you want to talk to your web service
from Javascript or some other low-octane language.

Now, you \could/ investigate CXF's full Javascript web service code
generator.

Otherwise, you have to think about how painful it is going to be to work
with the data in Javascript. The full data bindings are not so much designed
to help you make this easy. After all, the assumption is that you've got a
full binding on both ends. I'm not being quite fair to them, but they are
more oriented toward completeness than toward simplicity. I've been there.
We wrote the Javascript code gen after reaching a sufficiently of
frustration with that process.



On Sat, Sep 5, 2009 at 5:19 PM, Sergey Beryozkin
<se...@iona.com>wrote:

>
> Hi
>
> I haven't uploaded the updated schema to the Apache web site yet...Perhaps
> such updates can indeed be done as part of the release builds.
> Also, may be we can consider introducing a common set of elements like
> databinding/etc which can be used by both jaxws@endpoint and jaxrs:server
> elements.
>
> You can share a databinding bean between jaxws and jaxrs endpoints by
> referring to it from both jaxws:databinding and jaxrs:databiding element.
>
> CXF DataBindings were introduced before JAXRS has been implemented. It's
> only recently that CXF JAXRS started supporting them. So as far the support
> for schema-driven (data)bindings is concerned, one can rely on either
> JAXBElementProvider or XMLBeansElementProvider (contributed to CXF awhile
> back) or CXF DataBindings.
>
> If a user does both JAXWS and JAXB and especially if a databinding bean has
> already been configured for JAXWS then reusing the same bean for JAXRS may
> also of of interest. Even if it's JAXRS only one may want to try using
> databindings.
>
> However CXF DataBindings need to be told in advance (by the JAXRS runtime)
> about all the input and output classes/types that may need to be handled
> during the lifetime of a given application. If a resource class depends on
> subresources which can not be statically resolved (for ex when locator
> methods return Objects). In such cases CXF JAXRS providers
> (JAXBElementProvider, etc) will work better, they may also have some
> configuration options one can't apply to databindings. Also at the moment
> the way CXF JAXRS initializes DataBindings is not ideal and we've
> introduced
> a PropertiesAwareDataBinding interface to make this initialization work
> better.
>
> Going forward, I think it will make sense to continue working toward a
> common codebase, as far as the support for databindings in CXF is
> concerned.
>
> Does it makes things a bit clearer ?
>
> cheers, Sergey
>
> P.S 'DataBingings' - I think I spotted the typo you referred to :-)
>
>
>
> KARR, DAVID (ATTCINW) wrote:
> >
> > Comments below.
> >
> >> -----Original Message-----
> >> From: KARR, DAVID (ATTCINW)
> >> Sent: Friday, September 04, 2009 9:29 AM
> >> To: users@cxf.apache.org
> >> Subject: Starting to investigate schema-driven bindings with JAXRS
> >>
> >> I now have a trivial prototype using JAXRS.  I now want to investigate
> >> adding some elements of realism :) , by adding schema-driven bindings,
> >> even from fake schemas.  My current prototype uses a hand-written
> >> "@XmlRootElement" annotation on the class that represents the root of
> >> the response message.  I'd like to investigate how to define the root
> >> element and bindings in Spring and associated configuration files.  I
> >> see some scattered pieces of how to do this, but I'm having some
> >> trouble
> >> figuring out how these pieces fit together.  I know that CXF uses JAXB
> >> by default, although XMLBeans is an option.  Why would someone choose
> >> one over the other?
> >>
> >> I see examples of a "jaxws:dataBinding" element in various samples, but
> >> the "jaxrs" samples don't do anything like that.   Can I simply have a
> >> "jaxws:dataBinding" element inside the "jaxrs:server" element?
> >>
> >> I see the documentation briefly mentions (with no examples) that
> >> specifying a "jaxbElementClassNames" property is how you could use
> >> element classes that you can't add "@XmlRootElement" annotations to
> >> (like, if they were generated).  There's barely any mention of that
> >> property name in the entire CXF distribution.
> >
> > I also noticed the following in the JAX-RS section of the manual (note
> the
> > obvious typo :) ):
> > --------
> > Support for CXF DataBingings
> >
> > Starting from CXF 2.2.3 it is now possible to register a CXF DataBinding
> > bean using a jaxrs:databinding element and it will be wrappped as a JAXRS
> > MessageBodyReader/Writer provider capable of dealing with XML-based
> > content. It can be of special interest to users combining JAX-RS and
> > JAXWS. Thus CXF JAXB, Aegis, SDO and XMLBeans databindings can be easily
> > plugged in.
> > JSON support is also available for all these databindings.
> > Please see this configuration file for some examples.
> >
> > Similarly to the default JSONProvider these DataBinding-aware JSON
> > provider can have "namespaceMap", "serializeAsArray", "arrayKeys",
> > "dropRootElement" and "writeXsiType" properties set. Additionally they
> may
> > also have an "ignoreMixedContent" property set.
> >
> > Note that at the moment this feature is not available when a cxf-jaxrs
> > bundle is used (except for Aegis).
> > --------------
> >
> > The "Please see this configuration file" is a link to <
> >
> http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
> >,
> > which this is an excerpt of:
> > --------------
> > <jaxrs:server id="jaxbbook" address="/jaxb">
> > −
> > <jaxrs:serviceBeans>
> > <ref bean="serviceBean"/>
> > </jaxrs:serviceBeans>
> > −
> > <jaxrs:dataBinding>
> > <bean class="org.apache.cxf.jaxb.JAXBDataBinding"/>
> > </jaxrs:dataBinding>
> > </jaxrs:server>
> > --------------
> >
> > Here's a "jaxrs:dataBinding" element, but I don't see that in the current
> > jaxrs schema.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Starting-to-investigate-schema-driven-bindings-with-JAXRS-tp25297620p25312450.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>