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






Reply via email to