You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jason Chaffee <jc...@ebates.com> on 2010/04/28 23:44:54 UTC
filtering elements in jaxrs
I would like the consumer of my API to be able witch fields (elements)
they actually want returned in an effort to keep the content as small as
possible, similar to what Solr allows in search. What is the best way
to accomplish this with JAX-RS and CXF?
Jason
Re: filtering elements in jaxrs
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Another option is about experimenting with custom XMLStreamWriters. I'm not
sure if it is the best option at all but you might want to be aware of it.
Example, in the custom ResponseHandler filter you can have a UriInfo context
injected (so that you can check for a current user has actually requested)
and then register a custom XMLStreamWriter which will block certain
fields/elements, here is a sample output filter registering a stax writer
which will be noticed and used by JAXBElementProvider :
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
cheers, Sergey
On Thu, Apr 29, 2010 at 1:26 AM, Mike O'Neil <mt...@gmail.com> wrote:
> Jason,
> The simplest thing to do is simply set only the fields in your bean that
> the
> client is interested in, since null fields are ignored by JAXB. I do this
> programatically via a simple switch statement, where each case calls the
> proper setter for the field the user is interested in (for instance in a
> class which converts a ResultSet or a SolrDocument into your bean).
>
> Mike
>
> On Wed, Apr 28, 2010 at 6:58 PM, KARR, DAVID (ATTSI) <dk...@att.com>
> wrote:
>
> > > -----Original Message-----
> > > From: Jason Chaffee [mailto:jchaffee@ebates.com]
> > > Sent: Wednesday, April 28, 2010 2:45 PM
> > > To: users@cxf.apache.org
> > > Subject: filtering elements in jaxrs
> > >
> > > I would like the consumer of my API to be able witch fields (elements)
> > > they actually want returned in an effort to keep the content as small
> > > as
> > > possible, similar to what Solr allows in search. What is the best way
> > > to accomplish this with JAX-RS and CXF?
> >
> > When you get down to it, you have to have some way in your service
> > interface for the client to specify they want this alternate response.
> > There are numerous ways to do it, either through the request path, or
> > through additional request parameters. You just have to decide what's
> > the most convenient strategy between you and the client. There is no
> > magic here.
> >
>
Re: filtering elements in jaxrs
Posted by Mike O'Neil <mt...@gmail.com>.
Jason,
The simplest thing to do is simply set only the fields in your bean that the
client is interested in, since null fields are ignored by JAXB. I do this
programatically via a simple switch statement, where each case calls the
proper setter for the field the user is interested in (for instance in a
class which converts a ResultSet or a SolrDocument into your bean).
Mike
On Wed, Apr 28, 2010 at 6:58 PM, KARR, DAVID (ATTSI) <dk...@att.com> wrote:
> > -----Original Message-----
> > From: Jason Chaffee [mailto:jchaffee@ebates.com]
> > Sent: Wednesday, April 28, 2010 2:45 PM
> > To: users@cxf.apache.org
> > Subject: filtering elements in jaxrs
> >
> > I would like the consumer of my API to be able witch fields (elements)
> > they actually want returned in an effort to keep the content as small
> > as
> > possible, similar to what Solr allows in search. What is the best way
> > to accomplish this with JAX-RS and CXF?
>
> When you get down to it, you have to have some way in your service
> interface for the client to specify they want this alternate response.
> There are numerous ways to do it, either through the request path, or
> through additional request parameters. You just have to decide what's
> the most convenient strategy between you and the client. There is no
> magic here.
>
RE: filtering elements in jaxrs
Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
> -----Original Message-----
> From: Jason Chaffee [mailto:jchaffee@ebates.com]
> Sent: Wednesday, April 28, 2010 2:45 PM
> To: users@cxf.apache.org
> Subject: filtering elements in jaxrs
>
> I would like the consumer of my API to be able witch fields (elements)
> they actually want returned in an effort to keep the content as small
> as
> possible, similar to what Solr allows in search. What is the best way
> to accomplish this with JAX-RS and CXF?
When you get down to it, you have to have some way in your service
interface for the client to specify they want this alternate response.
There are numerous ways to do it, either through the request path, or
through additional request parameters. You just have to decide what's
the most convenient strategy between you and the client. There is no
magic here.