You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Raphael Vullriede <li...@vullriede.de> on 2013/02/28 05:47:09 UTC

Swagger and CXF

Hi,

for automated API documentation I tried to get Swagger  
(http://developers.helloreverb.com/swagger/) to work with CXF. It is  
really a beautiful way to document your rest services and it would be  
great if we can get this work with CXF. Currently it doesn't work  
because of the following problem:

Their implementation for API resource listing relies on the injection  
of two objects via @Context annotation:

javax.servlet.ServletConfig
javax.ws.rs.core.Application

The first one works, the second one doesn't and returns null instead.

When I look at the documentation at  
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,  
it seems Application is not supported for injection.

The ticket for Swagger is here:  
https://github.com/wordnik/swagger-core/issues/82
A sample app can be found here:  
https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf

To get the sample to work you have to add the sonatype snapshot  
repository (https://oss.sonatype.org/content/repositories/snapshots/)  
to you maven configuration.

After that you can run the sample with mvn tomcat:run and access the  
app under context /swagger-cxf

GET http://localhost:8080/swagger-cxf/api                       => CXF  
Servlet Endpoint
GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl            =>  
autogenerated WADL for CXF service /v1.0
GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1  =>  
example request for user resource

GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json    =>  
returns an NPE because of missing Application.

Does anybody have an idea how to get this work?

Thanks for your help,
Raphael




Re: Swagger and CXF

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Raphael
On 11/03/13 20:05, Raphael Vullriede wrote:
> Hi,
>
> On 03/07/2013 03:10 PM, sparklo wrote:
>> Hi Raphael,
>>
>> Any luck with it? I am having the exact same problem.
>>
>> Thanks,
>>
>> Randy
>
> Actually yes :-) I've played around a bit with using an own
> Application.class that detects the ressources via annotation scanning.
> You can find a working sample app here:
> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>
Very nice, I wonder, if using that Reflections project can be the 
fastest way to CXF supporting the optional auto-discovery of custom 
providers which do not need to be configured, which will work with or 
without Spring.

Re Applications, I've been also thinking of the JAX-RS factory bean 
creating a default Application if no custom Application has been set, 
specifically for the purpose of supporting the injection of Application.

Thanks, Sergey

>
> Best,
> Raphael
>

Re: Swagger and CXF

Posted by Nan Kang <ro...@gmail.com>.
Hi Raphael,

Thanks a lot for the working sample. I tried to follow your path but I was
still stucked half way through.

When I tried to access the api-docs.json file, I can see the
resourcePackage variable got passed into the BasicApplication.getClasses().
However, after it returned Set<Class<?>>, it went into ApiListing and threw
me an exception as:

>Caused by: java.lang.NoSuchMethodError:
>scala.collection.JavaConverters$.asScalaSetConverter(Ljava/util/Set;)Lscala/collection/JavaConverters$AsScala;

I checked my pom, and I have the scala-library artifact referenced
correctly. Any suggestions on what could be causing this? Thanks a lot!

Randy


On Mon, Mar 11, 2013 at 5:05 PM, Raphael Vullriede <
lists.raphael@vullriede.de> wrote:

> Hi,
>
>
> On 03/07/2013 03:10 PM, sparklo wrote:
>
>> Hi Raphael,
>>
>> Any luck with it? I am having the exact same problem.
>>
>> Thanks,
>>
>> Randy
>>
>
> Actually yes :-) I've played around a bit with using an own
> Application.class that detects the ressources via annotation scanning.
> You can find a working sample app here: https://github.com/rvullriede/**
> swagger-core/tree/master/**samples/swagger-java-sample-**app-cxf<https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf>
>
> Best,
> Raphael
>
>

Re: Swagger and CXF

Posted by Raphael Vullriede <li...@vullriede.de>.
Hi,

On 03/07/2013 03:10 PM, sparklo wrote:
> Hi Raphael,
>
> Any luck with it? I am having the exact same problem.
>
> Thanks,
>
> Randy

Actually yes :-) I've played around a bit with using an own 
Application.class that detects the ressources via annotation scanning.
You can find a working sample app here: 
https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf

Best,
Raphael


Re: Swagger and CXF

Posted by sparklo <ch...@gmail.com>.
Hi Raphael,

Any luck with it? I am having the exact same problem.

Thanks,

Randy



--
View this message in context: http://cxf.547215.n5.nabble.com/Swagger-and-CXF-tp5723874p5724240.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Swagger and CXF

Posted by Raphael Vullriede <li...@vullriede.de>.
Hi Sergey,

On 03/01/2013 05:47 PM, Sergey Beryozkin wrote:
> Hi,
> On 01/03/13 04:46, Raphael Vullriede wrote:
>> Hi Sergey,
>>
>>
>> On 02/28/2013 11:34 PM, Sergey Beryozkin wrote:
>>> Hi
>>> On 28/02/13 04:47, Raphael Vullriede wrote:
>>>> Hi,
>>>>
>>>> for automated API documentation I tried to get Swagger
>>>> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
>>>> really a beautiful way to document your rest services and it would be
>>>> great if we can get this work with CXF. Currently it doesn't work
>>>> because of the following problem:
>>>>
>>>> Their implementation for API resource listing relies on the 
>>>> injection of
>>>> two objects via @Context annotation:
>>>>
>>>> javax.servlet.ServletConfig
>>>> javax.ws.rs.core.Application
>>>>
>>>> The first one works, the second one doesn't and returns null instead.
>>>>
>>>> When I look at the documentation at
>>>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations, 
>>>>
>>>>
>>>> it seems Application is not supported for injection.
>>>>
>>>
>>> What resource class is Application expected to be injected in ? I've
>>> looked at a sample app and haven't seen Application reference. I'm
>>> pretty sure the injection of Application classes is supported - we
>>> have tests for that - specifically when Application is provided as
>>> part of CXFNonSpringJaxrsServlet,
>>
>> It is expected to be injected into the ApiListingResource, which need
>> this to auto-detect all other ressource listings. It is defined in
>> applicationContext.xml:
>>
>> <!-- Swagger API listing resource -->
>> <bean id="swaggerRessource"
>> class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />
>>
> This is class is not visible in your GIT repo

Correct, this class is part of the swagger distribution (declared as 
dependecy in my pom.xml). If you want to have a look, it can be found here:
https://github.com/rvullriede/swagger-core/blob/master/modules/swagger-jersey-jaxrs/src/main/scala/com/wordnik/swagger/jersey/listing/ApiListing.scala#L31

It is in Scala, though.
>
>> and registered like this (after follwing your suggesting and using
>> JAXRSServerFactoryBean directly):
>>
>> <bean class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean"
>> init-method="create">
>> <property name="address" value="/v1.0" />
>> <property name="serviceBeans">
>> <list>
>> <ref bean="userRessource" />
>> <ref bean="swaggerRessource" />
>> </list>
>> </property>
>> <property name="providers">
>> <list>
>> <ref bean="jsonProvider" />
>> </list>
>> </property>
>> </bean>
>>
>>>
>>> Note JAXRSServerFactoryBean has a setApplication method - so if the
>>> factory has this property set then the injection of Application, if
>>> required, will be done.
>>>
>>> < snip />
>>>
>>> and inject Application if any,
>>
>> I've seen the setApplication() method but I don't really know what I
>> should define here. I didn't find any implementation of Application in
>> CXF that I could instantiate manually.
>>
>
> The JAX-RS endpoint can be started from Spring and in such cases no 
> explicit Application is available, Application is what developers are 
> supposed to provide if no Spring or other injection support is available.
>
> For example, 
> http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
>
> and at the moment a custom Application can be registered with 
> CXFNonSpringJaxrsServlet,
>
> So when you use Spring, no Application is available, as Spring context 
> gives the runtime the info Application would give it otherwise if no 
> Spring were used.
>
> Perhaps, CXF could've syntesized Application if "@Context Application" 
> were available, but that probably would go a bit too far, as in most 
> cases one would inject Application itself to get to some application 
> properties like "defaultName" (in the linked resource), etc.
>
> I think the workaround, when also working with Spring, is to create a 
> basic Application and only list resource class objects as it probably 
> all Swagger needs and set it on the factory, in addition to the above 
> injection of resources/providers - that won't affect the endpoint 
> initialization, not at the moment.

Alright, I will try that.

Thanks,
Raphael



> Cheers, Sergey
>
>
>
>
>> Thanks,
>> Raphael
>>
>>
>>>> The ticket for Swagger is here:
>>>> https://github.com/wordnik/swagger-core/issues/82
>>>> A sample app can be found here:
>>>> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf 
>>>>
>>>>
>>>>
>>>>
>>>> To get the sample to work you have to add the sonatype snapshot
>>>> repository 
>>>> (https://oss.sonatype.org/content/repositories/snapshots/) to
>>>> you maven configuration.
>>>>
>>>> After that you can run the sample with mvn tomcat:run and access 
>>>> the app
>>>> under context /swagger-cxf
>>>>
>>>> GET http://localhost:8080/swagger-cxf/api => CXF Servlet Endpoint
>>>> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl => autogenerated
>>>> WADL for CXF service /v1.0
>>>> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1 =>
>>>> example request for user resource
>>>>
>>>> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json => 
>>>> returns
>>>> an NPE because of missing Application.
>>>>
>>>> Does anybody have an idea how to get this work?
>>>>
>>>> Thanks for your help,
>>>> Raphael
>>>>
>>>>
>>>>
>>>
>>>
>>


Re: Swagger and CXF

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 01/03/13 04:46, Raphael Vullriede wrote:
> Hi Sergey,
>
>
> On 02/28/2013 11:34 PM, Sergey Beryozkin wrote:
>> Hi
>> On 28/02/13 04:47, Raphael Vullriede wrote:
>>> Hi,
>>>
>>> for automated API documentation I tried to get Swagger
>>> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
>>> really a beautiful way to document your rest services and it would be
>>> great if we can get this work with CXF. Currently it doesn't work
>>> because of the following problem:
>>>
>>> Their implementation for API resource listing relies on the injection of
>>> two objects via @Context annotation:
>>>
>>> javax.servlet.ServletConfig
>>> javax.ws.rs.core.Application
>>>
>>> The first one works, the second one doesn't and returns null instead.
>>>
>>> When I look at the documentation at
>>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,
>>>
>>> it seems Application is not supported for injection.
>>>
>>
>> What resource class is Application expected to be injected in ? I've
>> looked at a sample app and haven't seen Application reference. I'm
>> pretty sure the injection of Application classes is supported - we
>> have tests for that - specifically when Application is provided as
>> part of CXFNonSpringJaxrsServlet,
>
> It is expected to be injected into the ApiListingResource, which need
> this to auto-detect all other ressource listings. It is defined in
> applicationContext.xml:
>
> <!-- Swagger API listing resource -->
> <bean id="swaggerRessource"
> class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />
>
This is class is not visible in your GIT repo

> and registered like this (after follwing your suggesting and using
> JAXRSServerFactoryBean directly):
>
> <bean class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean"
> init-method="create">
> <property name="address" value="/v1.0" />
> <property name="serviceBeans">
> <list>
> <ref bean="userRessource" />
> <ref bean="swaggerRessource" />
> </list>
> </property>
> <property name="providers">
> <list>
> <ref bean="jsonProvider" />
> </list>
> </property>
> </bean>
>
>>
>> Note JAXRSServerFactoryBean has a setApplication method - so if the
>> factory has this property set then the injection of Application, if
>> required, will be done.
>>
>> < snip />
>>
>> and inject Application if any,
>
> I've seen the setApplication() method but I don't really know what I
> should define here. I didn't find any implementation of Application in
> CXF that I could instantiate manually.
>

The JAX-RS endpoint can be started from Spring and in such cases no 
explicit Application is available, Application is what developers are 
supposed to provide if no Spring or other injection support is available.

For example, 
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java

and at the moment a custom Application can be registered with 
CXFNonSpringJaxrsServlet,

So when you use Spring, no Application is available, as Spring context 
gives the runtime the info Application would give it otherwise if no 
Spring were used.

Perhaps, CXF could've syntesized Application if "@Context Application" 
were available, but that probably would go a bit too far, as in most 
cases one would inject Application itself to get to some application 
properties like "defaultName" (in the linked resource), etc.

I think the workaround, when also working with Spring, is to create a 
basic Application and only list resource class objects as it probably 
all Swagger needs and set it on the factory, in addition to the above 
injection of resources/providers - that won't affect the endpoint 
initialization, not at the moment.

Cheers, Sergey




> Thanks,
> Raphael
>
>
>>> The ticket for Swagger is here:
>>> https://github.com/wordnik/swagger-core/issues/82
>>> A sample app can be found here:
>>> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>>>
>>>
>>>
>>> To get the sample to work you have to add the sonatype snapshot
>>> repository (https://oss.sonatype.org/content/repositories/snapshots/) to
>>> you maven configuration.
>>>
>>> After that you can run the sample with mvn tomcat:run and access the app
>>> under context /swagger-cxf
>>>
>>> GET http://localhost:8080/swagger-cxf/api => CXF Servlet Endpoint
>>> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl => autogenerated
>>> WADL for CXF service /v1.0
>>> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1 =>
>>> example request for user resource
>>>
>>> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json => returns
>>> an NPE because of missing Application.
>>>
>>> Does anybody have an idea how to get this work?
>>>
>>> Thanks for your help,
>>> Raphael
>>>
>>>
>>>
>>
>>
>

Re: Swagger and CXF

Posted by Raphael Vullriede <li...@vullriede.de>.
Hi Sergey,


On 02/28/2013 11:34 PM, Sergey Beryozkin wrote:
> Hi
> On 28/02/13 04:47, Raphael Vullriede wrote:
>> Hi,
>>
>> for automated API documentation I tried to get Swagger
>> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
>> really a beautiful way to document your rest services and it would be
>> great if we can get this work with CXF. Currently it doesn't work
>> because of the following problem:
>>
>> Their implementation for API resource listing relies on the injection of
>> two objects via @Context annotation:
>>
>> javax.servlet.ServletConfig
>> javax.ws.rs.core.Application
>>
>> The first one works, the second one doesn't and returns null instead.
>>
>> When I look at the documentation at
>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations, 
>>
>> it seems Application is not supported for injection.
>>
>
> What resource class is Application expected to be injected in ? I've 
> looked at a sample app and haven't seen Application reference.  I'm 
> pretty sure the injection of Application classes is supported - we 
> have tests for that - specifically when Application is provided as 
> part of CXFNonSpringJaxrsServlet,

It is expected to be injected into the ApiListingResource, which need 
this to auto-detect all other ressource listings. It is defined in 
applicationContext.xml:

<!-- Swagger API listing resource -->
<bean id="swaggerRessource" 
class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />

and registered like this (after follwing your suggesting and using 
JAXRSServerFactoryBean directly):

     <bean class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean" 
init-method="create">
         <property name="address" value="/v1.0" />
         <property name="serviceBeans">
             <list>
                 <ref bean="userRessource" />
                 <ref bean="swaggerRessource" />
             </list>
         </property>
         <property name="providers">
             <list>
                 <ref bean="jsonProvider" />
             </list>
         </property>
     </bean>

>
> Note JAXRSServerFactoryBean has a setApplication method - so if the 
> factory has this property set then the injection of Application, if 
> required, will be done.
>
> < snip />
>
> and inject Application if any,

I've seen the setApplication() method but I don't really know what I 
should define here. I didn't find any implementation of Application in 
CXF that I could instantiate manually.

Thanks,
Raphael


>> The ticket for Swagger is here:
>> https://github.com/wordnik/swagger-core/issues/82
>> A sample app can be found here:
>> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf 
>>
>>
>>
>> To get the sample to work you have to add the sonatype snapshot
>> repository (https://oss.sonatype.org/content/repositories/snapshots/) to
>> you maven configuration.
>>
>> After that you can run the sample with mvn tomcat:run and access the app
>> under context /swagger-cxf
>>
>> GET http://localhost:8080/swagger-cxf/api => CXF Servlet Endpoint
>> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl => autogenerated
>> WADL for CXF service /v1.0
>> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1 =>
>> example request for user resource
>>
>> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json => returns
>> an NPE because of missing Application.
>>
>> Does anybody have an idea how to get this work?
>>
>> Thanks for your help,
>> Raphael
>>
>>
>>
>
>


Re: Swagger and CXF

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 28/02/13 04:47, Raphael Vullriede wrote:
> Hi,
>
> for automated API documentation I tried to get Swagger
> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
> really a beautiful way to document your rest services and it would be
> great if we can get this work with CXF. Currently it doesn't work
> because of the following problem:
>
> Their implementation for API resource listing relies on the injection of
> two objects via @Context annotation:
>
> javax.servlet.ServletConfig
> javax.ws.rs.core.Application
>
> The first one works, the second one doesn't and returns null instead.
>
> When I look at the documentation at
> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,
> it seems Application is not supported for injection.
>

What resource class is Application expected to be injected in ? I've 
looked at a sample app and haven't seen Application reference.  I'm 
pretty sure the injection of Application classes is supported - we have 
tests for that - specifically when Application is provided as part of 
CXFNonSpringJaxrsServlet,

Note JAXRSServerFactoryBean has a setApplication method - so if the 
factory has this property set then the injection of Application, if 
required, will be done.

If you use Spring only, then try to use JAXRSServerFactory bean directly 
instead of using jaxrs:endpoint, example

<bean class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean" 
init-method="create">
          <property name="address" value="/register"/>
          <property name="serviceBeans">
              <list>
                <ref bean="userRegistrationService"/>
              </list>
          </property>
          <property name="providers">
              <list>
                <ref bean="someprovider"/>
              </list>
          </property>
      </bean>

and inject Application if any,


Let us know how it goes please
Sergey




> The ticket for Swagger is here:
> https://github.com/wordnik/swagger-core/issues/82
> A sample app can be found here:
> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>
>
> To get the sample to work you have to add the sonatype snapshot
> repository (https://oss.sonatype.org/content/repositories/snapshots/) to
> you maven configuration.
>
> After that you can run the sample with mvn tomcat:run and access the app
> under context /swagger-cxf
>
> GET http://localhost:8080/swagger-cxf/api => CXF Servlet Endpoint
> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl => autogenerated
> WADL for CXF service /v1.0
> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1 =>
> example request for user resource
>
> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json => returns
> an NPE because of missing Application.
>
> Does anybody have an idea how to get this work?
>
> Thanks for your help,
> Raphael
>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Swagger and CXF

Posted by Thorsten Höger <li...@hoegernet.de>.
Hi,
you can have a look at a sample project on bitbucket:
https://bitbucket.org/taimos/metering-server

The interesting files are DocFeature, UnitHandlingAPI and beans.xml

The generated RestDoc (available via HTTP OPTIONS) can be found in the file restdoc.

A real life example can be found with "curl -X OPTIONS https://www.tuwadest.com/apip"

This is the public API of an in production CXF project of a bank in Germany.

Regards,
Thorsten

Am 28.02.2013 10:41, schrieb Raphael Vullriede:
> Hi Thorsten,
>
> Quoting Thorsten Höger <li...@hoegernet.de>:
>
>> For documenting REST-API I can also suggest using RestDoc. It can be
>> foun on http://www.restdoc.org.
>> It works perfectly with CXF.
>
> It's off-topic, but if you show me a showcase with a real API and an example app
> integrated with CXF I'll give it a try! The projects seems to be quite young and I
> couldn't find much information about it.
>
> I'd still like to get Swagger to work with CXF though.
>
> Thanks,
> Raphael
>
>
>
>> Am 28.02.2013 05:47, schrieb Raphael Vullriede:
>>> Hi,
>>>
>>> for automated API documentation I tried to get Swagger
>>> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
>>> really a beautiful way to document your rest services and it would be
>>> great if we can get this work with CXF. Currently it doesn't work
>>> because of the following problem:
>>>
>>> Their implementation for API resource listing relies on the injection
>>> of two objects via @Context annotation:
>>>
>>> javax.servlet.ServletConfig
>>> javax.ws.rs.core.Application
>>>
>>> The first one works, the second one doesn't and returns null instead.
>>>
>>> When I look at the documentation at
>>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,
>>> it seems Application is not supported for injection.
>>>
>>> The ticket for Swagger is here:
>>> https://github.com/wordnik/swagger-core/issues/82
>>> A sample app can be found here:
>>> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>>>
>>>
>>> To get the sample to work you have to add the sonatype snapshot
>>> repository (https://oss.sonatype.org/content/repositories/snapshots/)
>>> to you maven configuration.
>>>
>>> After that you can run the sample with mvn tomcat:run and access the
>>> app under context /swagger-cxf
>>>
>>> GET http://localhost:8080/swagger-cxf/api                       => CXF
>>> Servlet Endpoint
>>> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl            =>
>>> autogenerated WADL for CXF service /v1.0
>>> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1  =>
>>> example request for user resource
>>>
>>> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json    =>
>>> returns an NPE because of missing Application.
>>>
>>> Does anybody have an idea how to get this work?
>>>
>>> Thanks for your help,
>>> Raphael
>>>
>>>
>>>
>
>


Re: Swagger and CXF

Posted by Raphael Vullriede <li...@vullriede.de>.
Hi Thorsten,

Quoting Thorsten Höger <li...@hoegernet.de>:

> For documenting REST-API I can also suggest using RestDoc. It can be
> foun on http://www.restdoc.org.
> It works perfectly with CXF.

It's off-topic, but if you show me a showcase with a real API and an  
example app integrated with CXF I'll give it a try! The projects seems  
to be quite young and I couldn't find much information about it.

I'd still like to get Swagger to work with CXF though.

Thanks,
Raphael



> Am 28.02.2013 05:47, schrieb Raphael Vullriede:
>> Hi,
>>
>> for automated API documentation I tried to get Swagger
>> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
>> really a beautiful way to document your rest services and it would be
>> great if we can get this work with CXF. Currently it doesn't work
>> because of the following problem:
>>
>> Their implementation for API resource listing relies on the injection
>> of two objects via @Context annotation:
>>
>> javax.servlet.ServletConfig
>> javax.ws.rs.core.Application
>>
>> The first one works, the second one doesn't and returns null instead.
>>
>> When I look at the documentation at
>> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,
>> it seems Application is not supported for injection.
>>
>> The ticket for Swagger is here:
>> https://github.com/wordnik/swagger-core/issues/82
>> A sample app can be found here:
>> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>>
>> To get the sample to work you have to add the sonatype snapshot
>> repository (https://oss.sonatype.org/content/repositories/snapshots/)
>> to you maven configuration.
>>
>> After that you can run the sample with mvn tomcat:run and access the
>> app under context /swagger-cxf
>>
>> GET http://localhost:8080/swagger-cxf/api                       => CXF
>> Servlet Endpoint
>> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl            =>
>> autogenerated WADL for CXF service /v1.0
>> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1  =>
>> example request for user resource
>>
>> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json    =>
>> returns an NPE because of missing Application.
>>
>> Does anybody have an idea how to get this work?
>>
>> Thanks for your help,
>> Raphael
>>
>>
>>



Re: Swagger and CXF

Posted by Thorsten Höger <li...@hoegernet.de>.
Hi,

For documenting REST-API I can also suggest using RestDoc. It can be
foun on http://www.restdoc.org.
It works perfectly with CXF.

Regards,
Thorsten

Am 28.02.2013 05:47, schrieb Raphael Vullriede:
> Hi,
>
> for automated API documentation I tried to get Swagger
> (http://developers.helloreverb.com/swagger/) to work with CXF. It is
> really a beautiful way to document your rest services and it would be
> great if we can get this work with CXF. Currently it doesn't work
> because of the following problem:
>
> Their implementation for API resource listing relies on the injection
> of two objects via @Context annotation:
>
> javax.servlet.ServletConfig
> javax.ws.rs.core.Application
>
> The first one works, the second one doesn't and returns null instead.
>
> When I look at the documentation at
> http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Contextannotations,
> it seems Application is not supported for injection.
>
> The ticket for Swagger is here:
> https://github.com/wordnik/swagger-core/issues/82
> A sample app can be found here:
> https://github.com/rvullriede/swagger-core/tree/master/samples/swagger-java-sample-app-cxf
>
> To get the sample to work you have to add the sonatype snapshot
> repository (https://oss.sonatype.org/content/repositories/snapshots/)
> to you maven configuration.
>
> After that you can run the sample with mvn tomcat:run and access the
> app under context /swagger-cxf
>
> GET http://localhost:8080/swagger-cxf/api                       => CXF
> Servlet Endpoint
> GET http://localhost:8080/swagger-cxf/api/v1.0?_wadl            =>
> autogenerated WADL for CXF service /v1.0
> GET http://localhost:8080/swagger-cxf/api/v1.0/user.json/user1  =>
> example request for user resource
>
> GET http://localhost:8080/swagger-cxf/api/v1.0/api-docs.json    =>
> returns an NPE because of missing Application.
>
> Does anybody have an idea how to get this work?
>
> Thanks for your help,
> Raphael
>
>
>