cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Coder One <coder_...@yahoo.com>
Subject Re: Really the Real One -- CXF 2.1 and REST Annotation
Date Wed, 04 Jun 2008 03:33:36 GMT
Thanks :)


--- On Tue, 6/3/08, Arul Dhesiaseelan <arul@fluxcorp.com> wrote:

> From: Arul Dhesiaseelan <arul@fluxcorp.com>
> Subject: Re: Really the Real One -- CXF 2.1 and REST Annotation
> To: users@cxf.apache.org
> Date: Tuesday, June 3, 2008, 11:14 AM
> Try this, in case if you do not choose to use QueryParam:
> 
> ConsumeMime can take only media types, not path params.
> 
> @POST
> @Path("/accountService")
> @ConsumeMime("application/json")
> public GetAccountRsp getAccount(GetAccountReq aReq) {
> //you can retrieve the acctId and ownerName here
> }
> 
> You need to post GetAccountReq pojo as JSON request in this
> case to the URL:
> http://localhost:port/accountService
> 
> If you choose to use query param, try this:
> 
> @GET
> @Path("/accountService")
> @ProduceMime("text/plain")
> public Response
> getAccount(@QueryParam("acctId")String acctId,
> @QueryParam("ownerName")String ownerName) {
> //construct Response and return			
> }
> 
> Invoke this method using GET at the URL:
> http://localhost:port/accountService?acctId=123&ownerName=test
> 
> Arul
> 
> Coder One wrote:
> > This is great info.  Thanks...sorry for being a bit
> "thick" here, but I have gone through the
> "samples" directory for JAX-RS and can't find
> what I need...
> >
> > @GET
> > @Path("/accountService")
> > @ConsumeMime("application/json/{aReq}")
> > public GetAccountRsp
> getAccount(@PathParam("aReq") GetAccountReq
> aReq);
> >
> >
> > class GetAccountReq
> > {
> >   private String acctId;
> >   private String ownerName;
> > }
> >
> > Since this is a get, how do I actually pass the acctId
> and ownerName to the method?  With a PUT/POST, the
> "serialized version", whether XML or JSON, would
> be attached to the request body.
> >
> > Where do I put the req parameter data for a GET
> request?  I assume I need something like
> /accountService?xyz=jsonized-GetAccountReq  ?
> >
> > What would xyz be?
> >
> > Thanks...
> >
> > --- On Tue, 6/3/08, Sergey Beryozkin
> <sergey.beryozkin@iona.com> wrote:
> >
> >   
> >> From: Sergey Beryozkin
> <sergey.beryozkin@iona.com>
> >> Subject: RE: Really the Real One -- CXF 2.1 and
> REST Annotation
> >> To: users@cxf.apache.org, coder_lol@yahoo.com
> >> Date: Tuesday, June 3, 2008, 4:47 AM
> >> Hi
> >>
> >> Consider this example :
> >>
> >> @Path("/")
> >> @ConsumeMime("application/json")
> >> public class TestResource {
> >>     @Path("{a}")
> >>     @PUT
> >>     public void update(@PathParam("a")
> >> StringHolder a, MessageBody request)
> >> {}
> >> }
> >>
> >> And we have a request
> >>
> >> PUT /2
> >> Content-Type : application/json
> >> {json message body}
> >>
> >> First, '2' will need to be converted into
> a
> >> StringHolder somehow, and as
> >> StringHolder is not a String nor a primitive type,
> it will
> >> be checked if it
> >> has a constructor with String or a valueOf method.
> These
> >> rules apply to
> >> parameters which match annotations such as
> @PathParam,
> >> @QueryParam,
> >> @HeaderParam and @CookieParam. Support for more
> advanced
> >> rules is on the
> >> map.
> >>
> >> Next, the actual json message will need to be
> converted
> >> into a MessageBody
> >> instance. It's the job of the message body
> reader. The
> >> one which ships with
> >> CXF will expect that MessageBody will be
> JAXB-annotated and
> >> it will use
> >> Jettison under the hood to convert the request
> text to the
> >> MessageBody.
> >>
> >> One can override this conversion procedure for
> JSON by
> >> providing a custom
> >> message body reader...
> >>
> >> Would you like too deal with Json handling
> directly in the
> >> application
> >> method ?
> >>
> >> Cheers, Sergey
> >>
> >>
> >>
> >> -----Original Message-----
> >> From: Coder One [mailto:coder_lol@yahoo.com] 
> >> Sent: 03 June 2008 07:16
> >> To: users@cxf.apache.org
> >> Subject: Re: Really the Real One -- CXF 2.1 and
> REST
> >> Annotation
> >>
> >>
> >>     
> >>> If you'd like to reuse existing types like
> >>>       
> >> GetMsgReq
> >>     
> >>> then the only way for them be used at the
> moment as
> >>>       
> >> holders
> >>     
> >>> of the URI/Query parameters is for type like
> GetMsgReq
> >>>       
> >> to
> >>     
> >>> either have a constructor with String arg or a
> static
> >>> valueOf(String) method.
> >>>       
> >> What would be the format of the String?  JSON?
> >>
> >> Thanks...
> >>
> >>
> >> ----------------------------
> >> IONA Technologies PLC (registered in Ireland)
> >> Registered Number: 171387
> >> Registered Address: The IONA Building, Shelbourne
> Road,
> >> Dublin 4, Ireland
> >>     
> >
> >
> >       
> >
> >
> > ________________________________
> > Scanned by MessageLabs for Flux
> > ________________________________
> >


      


Mime
View raw message