You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Brad <cf...@javawork.co.uk> on 2008/05/16 14:05:56 UTC

Re: Creating a REST service from a schema

Hi Sergey,

just to let you know, my employer has given me permission to submit my
XMLBean providers to the CXF project.

I've got two classes so far that produce and consume XML and JSON from
XMLBeans. I'm also going to be developing a provider class next week
to provide ATOM feeds.

If you still think they'd be of use I'd be happy to submit a patch as
a starting point for XMLBean support within CXF.

Brad.

On Thu, Apr 24, 2008 at 4:37 PM, Sergey Beryozkin
<se...@iona.com> wrote:
> Hi Brad
>
> This is good.
>
>> It looks to me like the included JSON
>> provider is essentially the JAXB provider with some Jettison mapping.
> Yes, exactly.
>
> There's also a Json support for Atom feeds/entries is available (
> courtesy of Abdera)
>
>> I'm going to have a go at creating a JSON provider for XMLBeans
>> sources to see if that theory checks out.
>
> Please do. If it works out ok for you then may be you might want to
> consider contributing such a provider to CXF...
>
> Cheers, Sergey
>> Hi Sergey,
>>
>> thanks for that advice, exactly what I needed to know. I've now got a
>> basic XMLBeans provider working.
>>
>> We're also interested in being able to provide JSON based services
>> from our XMLBeans data objects. It looks to me like the included JSON
>> provider is essentially the JAXB provider with some Jettison mapping.
>> I'm going to have a go at creating a JSON provider for XMLBeans
>> sources to see if that theory checks out.
>>
>> Brad.
>>
>> On Wed, Apr 23, 2008 at 6:14 PM, Sergey Beryozkin
>> <se...@iona.com> wrote:
>>>
>>>
>>> Hi
>>>
>>> If you're using Spring then please have a look at
>>>
>>> trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml.
>>> something like this will do :
>>> <jaxrs:server id="bookservice" address="/">
>>>
>>>
>>>
>>>
>>>     <jaxrs:serviceBeans>
>>>
>>>
>>>     <ref bean="petstore" />
>>>
>>>     <ref bean="bookstore" />
>>>   </jaxrs:serviceBeans>
>>>
>>>    <jaxrs:entityProviders>
>>>
>>>
>>>        <bean class="org.apache.cxf.systest.jaxrs.BadgerFishProvider" />
>>>   </jaxrs:entityProviders>
>>>  </jaxrs:server>
>>>
>>> Now, Jersey and other JAX_RS implementation would pick up the provider
>>> from
>>> the classpath, just annotating a custom provider with @Provider
>>> annotation
>>> would be sufficient. CXF is not capable of doing it yet. I'm not actually
>>> sure I like very much the idea of scanning the class path, should be fine
>>> in
>>> the simple scenarious but might cause classpath-like clash issues if say
>>> multiple custom providers for a certain type like Atom Feed or JAXB are
>>> availbale on the classpath. That said, this is something CXF will likely
>>> support, it's one of those areas where a patch would also be welcome.
>>>
>>> If you don't do Spring then you can do
>>>
>>> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>>> sf.setResourceClasses(CustomerService.class);
>>> sf.setAddress(http://localhost:9000/);
>>> // add you custom provider
>>> List<?> providers = ...;
>>> provider.add(new CustomProvider());
>>> sf.setEntityProviders(listOfProviders);
>>>
>>> sf.create();
>>>
>>>
>>> Hope it helps, Sergey
>>>
>>>
>>> ----- Original Message -----
>>> From: "Brad" <br...@javawork.co.uk>
>>> To: <cx...@incubator.apache.org>
>>> Sent: Wednesday, April 23, 2008 4:22 PM
>>> Subject: Re: Creating a REST service from a schema
>>>
>>>
>>>
>>> > Hi all,
>>> >
>>> > I've now created a simple custom provider for my XMLBeans classes as
>>> > suggest (similar to JAXBElementProvider).
>>> >
>>> > I'm now getting this error:
>>> >
>>> >    No message body writer found for response class : TestDocImpl
>>> >
>>> > I'm guessing that my provider hasn't been registered somewhere it
>>> > needs to be? I searched for references to JAXBElementProvider but
>>> > could only find one occurance in the constructor of
>>> > org.apache.cxf.jaxrs.provider,ProviderFactory. So, I added my provider
>>> > there but I think I need a few tips how to get it registered.
>>> >
>>> > Cheers,
>>> > Brad.
>>> >
>>> > On Tue, Feb 19, 2008 at 5:04 PM, Sergey Beryozkin
>>> > <se...@iona.com> wrote:
>>> >>
>>> >>
>>> >> Hi Brad
>>> >>
>>> >>
>>> >> > I prefer the XML first approach and would like to build a RESTful
>>> >> > service which either can use my already generated XMLBeans classes
>>> >> > (prefered option) or generate JAXB java binding classes from my
>>> >> > schema.
>>> >>
>>> >> No problems for a JAXB option, it should work just fine. CXF
>>> >> JAXBElementProvider checks if @XMLRootAnnotation is present.
>>> >> Fox XMLBeans, a simple custom provider would need to be added. Perhaps
>>> >> we
>>> >> should have it supported by default. Barry has added a system test
>>> showing
>>> >> how to write a JSON BadgerFish JAX-RS Provider  (I was actually very
>>> >> surprised to find out BadgerFish is a real thing which lives in the
>>> Jettison
>>> >> project)
>>> >>
>>> >> Cheers, Sergey
>>> >>
>>> >>
>>> >>
>>> >>  > Hi,
>>> >> >
>>> >> > I'm interested in using the jax-rs support in CXF. From the examples
>>> >> > I've seen it appears that I'm required to take that Java first
>>> >> > approach and let JAXB take care of the Java to XML mapping. Is this
>>> >> > correct?
>>> >> >
>>> >> > I prefer the XML first approach and would like to build a RESTful
>>> >> > service which either can use my already generated XMLBeans classes
>>> >> > (prefered option) or generate JAXB java binding classes from my
>>> >> > schema.
>>> >> >
>>> >> > Is this possible? The important things here for me are to have the
>>> >> > schema dictate what the XML looks like and to have it as a REST
>>> >> > service. If its not possible using JAX-RS, does CXF have an
>>> >> > alternative method to achieve the desired results?
>>> >> >
>>> >> > Thanks,
>>> >> > Brad.----------------------------
>>> >> IONA Technologies PLC (registered in Ireland)
>>> >> Registered Number: 171387
>>> >> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
>>> >> Ireland
>>> >>
>>> >>----------------------------
>>> IONA Technologies PLC (registered in Ireland)
>>> Registered Number: 171387
>>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>>>
>>>
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

Re: Creating a REST service from a schema

Posted by Brad <cf...@javawork.co.uk>.
Hi,

finally got round to adding my JAX-RS providers for xml and json using XMLBeans.

https://issues.apache.org/jira/browse/CXF-1634

As stated on the JIRA, completely untested other than "work on my
machine". They may prove useful as a starting point though.

Brad.

On Fri, May 16, 2008 at 2:05 PM, Sergey Beryozkin
<se...@iona.com> wrote:
> Hi Brad
>
>
>> Hi Sergey,
>>
>> just to let you know, my employer has given me permission to submit my
>> XMLBean providers to the CXF project.
>>
>> I've got two classes so far that produce and consume XML and JSON from
>> XMLBeans. I'm also going to be developing a provider class next week
>> to provide ATOM feeds.
>>
>> If you still think they'd be of use I'd be happy to submit a patch as
>> a starting point for XMLBean support within CXF.
>
> I think it would be great, as XMLBeans is a technology which can be used by
> different applications...Please submit a patch. One thing is that I may not
> be able to react quickly and apply it fast as currently I can only afford
> spending some limited time only outside of my working  hours on maintaining
> the CXF JAX-RS framework . I'm slowly moving ahead with a 0.7 api upgrade
> work and planning to accumulate those changes with your patches, as well as
> with any other patches we may've received during the next couple of weeks...
>
> About Atom. CXF currently ships some core Apache Abdera classes and a couple
> of basic Atom Feed/Entry providers, which makes it trivial to expose
> application-specific classes as Feeds or Entries, see for example this blog
> entry on how one can combine JAX-RS and Abdera :
>
> http://weblogs.java.net/blog/mhadley/archive/2008/02/integrating_jer_2.html
>
> This gives a total control to the developer with respect to how a given Feed
> or individual Entry is created.
> Now, another option is to basically do this :
>
> @ProduceMime("application/atom+feed")
> Bars getBars() {}
>
> Have you been thinking about creating a provider which can introspect a
> given application type like Bars and properly wrap it into an atom feed or
> entry ?
>
> Thanks, Sergey
>
>
>>
>> Brad.
>>
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

Re: Creating a REST service from a schema

Posted by Brad <cf...@javawork.co.uk>.
Hi Sergey,

going back to your earlier email, specifically the point anbout
introspecting a given application type.....yes I think this is what
I'd like to do.

At the moment I have a class with methods that return my XMLBean
objects. I now have providers for getting XML and JSON from the
XMLBean objects so that's great. We have a requirement to also provide
an ATOM feed off one of the methods. So this is where I'm thinking
about how I can write a provider which takes the same XMLBean object
and outputs an ATOM feed.

The JSON provider was fairly straight forward as I could use the
events from the XML stream parser to drive the JSON output. It was
just a case of echoing the document structure through the JSON writer.
The problem I'm seeing with the ATOM provider is that I have to
somehow output specific ATOM elements for arbitrary domain objects.
I'm starting to think there's no way of getting this working without
it being a solution specific to the project I'm working on.

My only idea so far has been to have it look for known element types
such as xlink:href and use them to build the feed structure but it
feels a bit hack-like. Well, more hack-like than I've made it so far
:-)

I'd appreciate any thoughts you may have on the subject.

Cheers,
Brad.

On Fri, May 16, 2008 at 2:05 PM, Sergey Beryozkin
<se...@iona.com> wrote:
> Hi Brad
>
>
>> Hi Sergey,
>>
>> just to let you know, my employer has given me permission to submit my
>> XMLBean providers to the CXF project.
>>
>> I've got two classes so far that produce and consume XML and JSON from
>> XMLBeans. I'm also going to be developing a provider class next week
>> to provide ATOM feeds.
>>
>> If you still think they'd be of use I'd be happy to submit a patch as
>> a starting point for XMLBean support within CXF.
>
> I think it would be great, as XMLBeans is a technology which can be used by
> different applications...Please submit a patch. One thing is that I may not
> be able to react quickly and apply it fast as currently I can only afford
> spending some limited time only outside of my working  hours on maintaining
> the CXF JAX-RS framework . I'm slowly moving ahead with a 0.7 api upgrade
> work and planning to accumulate those changes with your patches, as well as
> with any other patches we may've received during the next couple of weeks...
>
> About Atom. CXF currently ships some core Apache Abdera classes and a couple
> of basic Atom Feed/Entry providers, which makes it trivial to expose
> application-specific classes as Feeds or Entries, see for example this blog
> entry on how one can combine JAX-RS and Abdera :
>
> http://weblogs.java.net/blog/mhadley/archive/2008/02/integrating_jer_2.html
>
> This gives a total control to the developer with respect to how a given Feed
> or individual Entry is created.
> Now, another option is to basically do this :
>
> @ProduceMime("application/atom+feed")
> Bars getBars() {}
>
> Have you been thinking about creating a provider which can introspect a
> given application type like Bars and properly wrap it into an atom feed or
> entry ?
>
> Thanks, Sergey
>
>
>>
>> Brad.
>>
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

Re: Creating a REST service from a schema

Posted by Sergey Beryozkin <se...@iona.com>.
Hi Brad


> Hi Sergey,
>
> just to let you know, my employer has given me permission to submit my
> XMLBean providers to the CXF project.
>
> I've got two classes so far that produce and consume XML and JSON from
> XMLBeans. I'm also going to be developing a provider class next week
> to provide ATOM feeds.
>
> If you still think they'd be of use I'd be happy to submit a patch as
> a starting point for XMLBean support within CXF.

I think it would be great, as XMLBeans is a technology which can be used by different applications...Please submit a patch. One 
thing is that I may not be able to react quickly and apply it fast as currently I can only afford spending some limited time only 
outside of my working  hours on maintaining the CXF JAX-RS framework . I'm slowly moving ahead with a 0.7 api upgrade work and 
planning to accumulate those changes with your patches, as well as with any other patches we may've received during the next couple 
of weeks...

About Atom. CXF currently ships some core Apache Abdera classes and a couple of basic Atom Feed/Entry providers, which makes it 
trivial to expose application-specific classes as Feeds or Entries, see for example this blog entry on how one can combine JAX-RS 
and Abdera :

http://weblogs.java.net/blog/mhadley/archive/2008/02/integrating_jer_2.html

This gives a total control to the developer with respect to how a given Feed or individual Entry is created.
Now, another option is to basically do this :

@ProduceMime("application/atom+feed")
Bars getBars() {}

Have you been thinking about creating a provider which can introspect a given application type like Bars and properly wrap it into 
an atom feed or entry ?

Thanks, Sergey


>
> Brad.
>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland