You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Timothy Canavan <ti...@loyaltypartner.com> on 2012/10/10 12:28:07 UTC

JSON Support JAX-WS

What is the recommended was to provide JSON support for an existing contract first JAX-WS web service which uses JAXB for binding.

Should I simply use JAX-RS or integrate JSON into the JAX-WS stack somehow.


Tim


Re: JSON Support JAX-WS

Posted by Daniel Kulp <dk...@apache.org>.
From my standpoint: this is perfect (other than possibly annotating the interface instead of the class).  This is definitely one of the strengths of CXF.  Being able to easily support both SOAP and REST is a big plus.

Dan

On Oct 10, 2012, at 10:06 AM, Mark Streit <mc...@gmail.com> wrote:

> Yes - we did something like this:  ( a fictitious POC we did :-) )  But is
> worked just like it was supposed to following that link in the CXF
> documentation.
> 
> *For a class:*
> 
> @Path("/bookservice")
> @WebService(serviceName = "BookOrderManagerService", portName =
> "BookOrderManagerServicePort", endpointInterface =
> "com.acme.book.webservices.BookOrderManagerService")
> @HandlerChain(file = "handler-chain.xml")
> public class BookOrderManagerWS implements BookOrderManagerService  {
> 
> 
> *For a method:*
> 
>   @GET
>   @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
>   @Path("/{bookID}")
>   @WebMethod
>   public Book getBook(@PathParam("bookID") @WebParam(name = "bookID")
> String bookID) throws ServiceException {
> 
> 
> Hope this helps.  The CXF gurus out there might have other input (Daniel,
> Sergey, Glen ... )
> 
> On Wed, Oct 10, 2012 at 9:35 AM, Timothy Canavan <
> timothy.canavan_ext@loyaltypartner.com> wrote:
> 
>> Very interesting. So basically you define a service something like this.
>> 
>> @WebService // jaxws annotation.
>> @Path("json") // jaxrs annotation.
>> public class CustomerService implements CustomerSericePortType {
>> 
>>    @POST // jaxrs annotation.
>>    @Consumes({MediaType.APPLICATION_JSON}) // jaxrs annotation.
>>    @Produces({MediaType.APPLICATION_JSON}) // jaxrs annotation.
>>    @Path("getcustomer")
>>    public CustomerResponse authenticate(CustomerRequest body) {
>>        ...
>>    }
>> 
>> }
>> 
>> Tim
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: Mark Streit [mailto:mcs130@gmail.com]
>> Gesendet: Mittwoch, 10. Oktober 2012 14:40
>> An: users@cxf.apache.org
>> Betreff: Re: JSON Support JAX-WS
>> 
>> We tried exactly that... Having JAX-WS and JAX-RS annotations on same
>> service implementation class and it worked.   (Assuming that is what Sergey
>> is suggesting).
>> 
>> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-CombiningJAXWSandJAXRS
>> 
>> Mark
>> On Oct 10, 2012 7:22 AM, "Sergey Beryozkin" <sb...@gmail.com> wrote:
>> 
>>> On 10/10/12 11:28, Timothy Canavan wrote:
>>> 
>>>> What is the recommended was to provide JSON support for an existing
>>>> contract first JAX-WS web service which uses JAXB for binding.
>>>> 
>>>> Should I simply use JAX-RS or integrate JSON into the JAX-WS stack
>>>> somehow.
>>>> 
>>>> 
>>> Have a look at
>>> systests/transports/src/test/**java/org/apache/cxf/systest/
>>> **servlet/restful_service.xml,
>>> 
>>> alternatively, you can indeed introduce a JAX-RS endpoint and share
>>> the same service bean between JAXWS and JAXRS endpoints
>>> 
>>> Cheers, Sergey
>>> 
>>> 
>>>> Tim
>>>> 
>>>> 
>>>> 
>>> 
>>> --
>>> Sergey Beryozkin
>>> 
>>> Talend Community Coders
>>> http://coders.talend.com/
>>> 
>>> Blog: http://sberyozkin.blogspot.com
>>> 
>> 
> 
> 
> 
> -- 
> Mark
> *
> *

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: JSON Support JAX-WS

Posted by Mark Streit <mc...@gmail.com>.
Yes - we did something like this:  ( a fictitious POC we did :-) )  But is
worked just like it was supposed to following that link in the CXF
documentation.

*For a class:*

@Path("/bookservice")
@WebService(serviceName = "BookOrderManagerService", portName =
"BookOrderManagerServicePort", endpointInterface =
"com.acme.book.webservices.BookOrderManagerService")
@HandlerChain(file = "handler-chain.xml")
public class BookOrderManagerWS implements BookOrderManagerService  {


*For a method:*

   @GET
   @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
   @Path("/{bookID}")
   @WebMethod
   public Book getBook(@PathParam("bookID") @WebParam(name = "bookID")
String bookID) throws ServiceException {


Hope this helps.  The CXF gurus out there might have other input (Daniel,
Sergey, Glen ... )

On Wed, Oct 10, 2012 at 9:35 AM, Timothy Canavan <
timothy.canavan_ext@loyaltypartner.com> wrote:

> Very interesting. So basically you define a service something like this.
>
> @WebService // jaxws annotation.
> @Path("json") // jaxrs annotation.
> public class CustomerService implements CustomerSericePortType {
>
>     @POST // jaxrs annotation.
>     @Consumes({MediaType.APPLICATION_JSON}) // jaxrs annotation.
>     @Produces({MediaType.APPLICATION_JSON}) // jaxrs annotation.
>     @Path("getcustomer")
>     public CustomerResponse authenticate(CustomerRequest body) {
>         ...
>     }
>
> }
>
> Tim
>
> -----Ursprüngliche Nachricht-----
> Von: Mark Streit [mailto:mcs130@gmail.com]
> Gesendet: Mittwoch, 10. Oktober 2012 14:40
> An: users@cxf.apache.org
> Betreff: Re: JSON Support JAX-WS
>
> We tried exactly that... Having JAX-WS and JAX-RS annotations on same
> service implementation class and it worked.   (Assuming that is what Sergey
> is suggesting).
>
> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-CombiningJAXWSandJAXRS
>
> Mark
> On Oct 10, 2012 7:22 AM, "Sergey Beryozkin" <sb...@gmail.com> wrote:
>
> > On 10/10/12 11:28, Timothy Canavan wrote:
> >
> >> What is the recommended was to provide JSON support for an existing
> >> contract first JAX-WS web service which uses JAXB for binding.
> >>
> >> Should I simply use JAX-RS or integrate JSON into the JAX-WS stack
> >> somehow.
> >>
> >>
> > Have a look at
> > systests/transports/src/test/**java/org/apache/cxf/systest/
> > **servlet/restful_service.xml,
> >
> > alternatively, you can indeed introduce a JAX-RS endpoint and share
> > the same service bean between JAXWS and JAXRS endpoints
> >
> > Cheers, Sergey
> >
> >
> >> Tim
> >>
> >>
> >>
> >
> > --
> > Sergey Beryozkin
> >
> > Talend Community Coders
> > http://coders.talend.com/
> >
> > Blog: http://sberyozkin.blogspot.com
> >
>



-- 
Mark
*
*

AW: JSON Support JAX-WS

Posted by Timothy Canavan <ti...@loyaltypartner.com>.
Very interesting. So basically you define a service something like this.

@WebService // jaxws annotation. 
@Path("json") // jaxrs annotation.
public class CustomerService implements CustomerSericePortType {

    @POST // jaxrs annotation.
    @Consumes({MediaType.APPLICATION_JSON}) // jaxrs annotation.
    @Produces({MediaType.APPLICATION_JSON}) // jaxrs annotation.
    @Path("getcustomer")
    public CustomerResponse authenticate(CustomerRequest body) {
        ...
    }
    
}

Tim

-----Ursprüngliche Nachricht-----
Von: Mark Streit [mailto:mcs130@gmail.com] 
Gesendet: Mittwoch, 10. Oktober 2012 14:40
An: users@cxf.apache.org
Betreff: Re: JSON Support JAX-WS

We tried exactly that... Having JAX-WS and JAX-RS annotations on same
service implementation class and it worked.   (Assuming that is what Sergey
is suggesting).

http://cxf.apache.org/docs/jax-rs.html#JAX-RS-CombiningJAXWSandJAXRS

Mark
On Oct 10, 2012 7:22 AM, "Sergey Beryozkin" <sb...@gmail.com> wrote:

> On 10/10/12 11:28, Timothy Canavan wrote:
>
>> What is the recommended was to provide JSON support for an existing 
>> contract first JAX-WS web service which uses JAXB for binding.
>>
>> Should I simply use JAX-RS or integrate JSON into the JAX-WS stack 
>> somehow.
>>
>>
> Have a look at 
> systests/transports/src/test/**java/org/apache/cxf/systest/
> **servlet/restful_service.xml,
>
> alternatively, you can indeed introduce a JAX-RS endpoint and share 
> the same service bean between JAXWS and JAXRS endpoints
>
> Cheers, Sergey
>
>
>> Tim
>>
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>

Re: JSON Support JAX-WS

Posted by Mark Streit <mc...@gmail.com>.
We tried exactly that... Having JAX-WS and JAX-RS annotations on same
service implementation class and it worked.   (Assuming that is what Sergey
is suggesting).

http://cxf.apache.org/docs/jax-rs.html#JAX-RS-CombiningJAXWSandJAXRS

Mark
On Oct 10, 2012 7:22 AM, "Sergey Beryozkin" <sb...@gmail.com> wrote:

> On 10/10/12 11:28, Timothy Canavan wrote:
>
>> What is the recommended was to provide JSON support for an existing
>> contract first JAX-WS web service which uses JAXB for binding.
>>
>> Should I simply use JAX-RS or integrate JSON into the JAX-WS stack
>> somehow.
>>
>>
> Have a look at systests/transports/src/test/**java/org/apache/cxf/systest/
> **servlet/restful_service.xml,
>
> alternatively, you can indeed introduce a JAX-RS endpoint and share the
> same service bean between JAXWS and JAXRS endpoints
>
> Cheers, Sergey
>
>
>> Tim
>>
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>

Re: JSON Support JAX-WS

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 10/10/12 11:28, Timothy Canavan wrote:
> What is the recommended was to provide JSON support for an existing contract first JAX-WS web service which uses JAXB for binding.
>
> Should I simply use JAX-RS or integrate JSON into the JAX-WS stack somehow.
>

Have a look at 
systests/transports/src/test/java/org/apache/cxf/systest/servlet/restful_service.xml, 


alternatively, you can indeed introduce a JAX-RS endpoint and share the 
same service bean between JAXWS and JAXRS endpoints

Cheers, Sergey

>
> Tim
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com