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