Swagger Configuration for Apache CXF (Non Spring)

1,578 views
Skip to first unread message

Sharath Kumar

unread,
Jul 13, 2014, 11:27:51 PM7/13/14
to swagger-sw...@googlegroups.com
Hi All,

I am using Apache Tomee 1.6 with JAX-RS (Apache CSF). My application is built using JSF and JPA. I am not using Spring. I would be extremely grateful to the people here if I can get some information on how to configure web.xml to obtain the REST API documentation. On the Swagger tutorial I see only configuration of applicationcontext.xml. I presume I cannot use this since I am not using Spring. Any help would be greatly appreciated.

Thanks and Regards

Sharath

Ron

unread,
Jul 14, 2014, 6:41:35 AM7/14/14
to swagger-sw...@googlegroups.com
Hi Sharath,

I don't have that much experience with CXF (yet), though I'm going to write a new tutorial soon with it (and Swagger, of course).
If you'd like, we can walk step by step and get it to work for you.

To start with, can you share your current web.xml?


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sharath Kumar

unread,
Jul 14, 2014, 6:44:38 AM7/14/14
to swagger-sw...@googlegroups.com
Hi Ron,

Thank you so much for the mail. Below is the configuration I have on my Web.xml. I get the error class not found for ApiListingResourceJSON . Not sure why that is happening though


<servlet>
      <servlet-name>CXFServlet</servlet-name>
      <servlet-class>
         org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
      </servlet-class>
 <init-param>
 <param-name>jaxrs.serviceClasses</param-name>
 <param-value>
com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON;         
 </param-value>
</init-param>
<init-param>
  <param-name>jaxrs.providers</param-name>
  <param-value>
    com.wordnik.swagger.jaxrs.json.JacksonJsonProvider
    com.wordnik.swagger.jaxrs.listing.ResourceListingProvider
com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider
  </param-value>
 </init-param>
 <!-- enables schema validation -->
 <init-param>
  <param-name>jaxrs.schemaLocations</param-name>
  <param-value>
    classpath:/WEB-INF/schemas/schema1.xsd
    classpath:/WEB-INF/schemas/schema2.xsd            
  </param-value>
 </init-param> 
 <!-- registers CXF in interceptors -->
 
 <!-- registers extension mappings -->
 <init-param>
  <param-name>jaxrs.extensions</param-name>
  <param-value>
    xml=application/xml
    json=application/json
  </param-value>
 </init-param>
 <!-- registers contextual properties -->
 <init-param>
  <param-name>jaxrs.properties</param-name>
  <param-value>
    property1=value
    property2=value
  </param-value>
 </init-param>
  <init-param>
      <param-name>api.version</param-name>
      <param-value>1.0</param-value>
    </init-param>
    <init-param>
      <param-name>swagger.api.version</param-name>
      <param-value>1.3</param-value>
    </init-param>
    <init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/api/doc</param-value>
     </init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
      <servlet-name>CXFServlet</servlet-name>
      <url-pattern>/api/*</url-pattern>
</servlet-mapping>


Please let me know if you need the full web.xml . Really appreciate the quick response and the offer of help :) 

Thanks and Regards

Sharath
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Jul 14, 2014, 6:48:04 AM7/14/14
to swagger-sw...@googlegroups.com
Do you use maven as a dependency manager? If so, can you attach the pom.xml?
If you use a different dependency manager, please provide its relevant configuration file.
If you use no dependency manager, please provide a list of dependencies you have in the project.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Sharath Kumar

unread,
Jul 15, 2014, 1:23:39 AM7/15/14
to swagger-sw...@googlegroups.com
Hi Ron,

 we are using the Maven.  This is the dependency that we have used...

                <dependency>
  <groupId>com.wordnik</groupId>
  <artifactId>swagger-jaxrs_2.10</artifactId>
  <version>1.3.0</version>
</dependency>

The problem seems to be with the deployment of the classes. I see that all the required jars are downloaded but they are not getting deployed to the Tomee instance. Is there anything I am missing in this dependency?
 
Thanks and Regards

Sharath

 


You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Jul 15, 2014, 1:42:53 AM7/15/14
to swagger-sw...@googlegroups.com
Only that it's an old version. Should be 1.3.7.
If it's not being deployed to the Tomee instance, there's probably an issue with the packaging done by maven.

Sharath Kumar

unread,
Jul 15, 2014, 4:06:27 AM7/15/14
to swagger-sw...@googlegroups.com
Hi Ron,

Thanks for the information. Will update the version and will try to check why Maven is not packaging properly. Will update you on how it goes.

Thanks and Regards

Sharath

Sharath Kumar

unread,
Jul 24, 2014, 3:47:52 AM7/24/14
to swagger-sw...@googlegroups.com
Hi Ron,

I copied the Swagger Jars onto my Tomee Lib. I get the following error when I try to access the API- docs

"No message body writer has been found for response class ResourceListing."

In my Tomee logs, I get the following error

Jul 24, 2014 1:16:55 PM org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage WARNING: No message body writer has been found for response class ResourceListing.

I would be extremely grateful to you if you could help me out on this.

Thanks and Regards

Sharath

Ron

unread,
Jul 24, 2014, 3:55:16 AM7/24/14
to swagger-sw...@googlegroups.com
I would highly recommend packaging swagger with your WAR and not deploy it to your application server's common library directory.
The reason for that is that Swagger uses some static classes which cannot be shared between web applications (one application would override the other).

The error you're getting is most likely due to missing dependencies. I strongly advice you to stick with maven to manage that.

Sharath Kumar

unread,
Jul 24, 2014, 5:55:04 AM7/24/14
to swagger-sw...@googlegroups.com
Hi Ron, when I try this through Maven, I get an error when my server starts (Class not found). Is it because of the scope? Should I set it to anything other than compile?

Thanks and Regards

Sharath

Ron

unread,
Jul 24, 2014, 6:24:31 AM7/24/14
to swagger-sw...@googlegroups.com
No, compile should be fine. Can you attach your pom.xml (with the swagger dependencies)?

Sharath Kumar

unread,
Jul 25, 2014, 12:43:39 AM7/25/14
to swagger-sw...@googlegroups.com
Hi Ron,

I think the problem is that I have not specified the in and out interceptor in my web.xml. Is that causing the issue? If so, what interceptors can I add and where can I find them?

Thanks and Regards

Sharath

Ron

unread,
Jul 25, 2014, 1:17:20 AM7/25/14
to swagger-sw...@googlegroups.com
You can take a look at its web.xml and see if something's missing.

Sharath Kumar

unread,
Jul 25, 2014, 3:14:19 AM7/25/14
to swagger-sw...@googlegroups.com
Hi Ron,

As per your advice I removed the jars from my Tomee - Lib folder and am now deploying it purely through maven. I have also added the filter and filterImpl from the sample code.

I still seem to be getting the same issue. Any suggestions. Attached is my pom.xml.

 
swagger-pom.xml

Ron

unread,
Jul 25, 2014, 4:06:09 AM7/25/14
to swagger-sw...@googlegroups.com
Okay, we've been going over it for a few days now, and I'm a bit confused, so let's try concentrating all the information together.

Please tell me, when running with a maven bundled swagger application, exactly what error or problem you're experiencing. If you're getting a java exception, please provide a full stack trace (not just the error).
I have your pom, which is okay, but please attach your web.xml too and any other configuration files that may be relevant (if you use spring or perhaps cxf has additional configuration files).

Once I have all the information, I hope I'll be able to guide you into solving it.

Sharath Kumar

unread,
Jul 25, 2014, 5:28:04 AM7/25/14
to swagger-sw...@googlegroups.com
Hi Ron,

Attached is the errors I get in the web page and in the tomee logs.

In Tomee Logs : 


Jul 25, 2014 2:43:29 PM org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage
WARNING: No message body writer has been found for response class ResourceListing.



Inline image 1

My Web.xml


<?xml version="1.0" encoding="UTF-8"?>
version="3.0" id="Prod">
<display-name>Prod</display-name>
<description>My app description</description>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
      <servlet-name>CXFServlet</servlet-name>
      <servlet-class>
         org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
      </servlet-class>
 <init-param>
 <param-name>jaxrs.serviceClasses</param-name>
 <param-value>
com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON        
 </param-value>
</init-param>
<init-param>
  <param-name>jaxrs.providers</param-name>
  <param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,
  com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,
  com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider
  </param-value>
 </init-param>
 <!-- enables schema validation -->
 <init-param>
  <param-name>jaxrs.schemaLocations</param-name>
  <param-value>
    classpath:/WEB-INF/schemas/schema1.xsd
    classpath:/WEB-INF/schemas/schema2.xsd            
  </param-value>
 </init-param> 
<!--  registers CXF in interceptors
 
        <!-- configure a security filter -->
    <init-param>
      <param-name>swagger.security.filter</param-name>
      <param-value>com.cwm.swagger.util.ApiAuthorizationFilterImpl</param-value>
    </init-param>
  
<load-on-startup>5</load-on-startup>
</servlet>

<servlet-mapping>
      <servlet-name>CXFServlet</servlet-name>
      <url-pattern>/api/*</url-pattern>
</servlet-mapping>

<!-- add the origin filter for JQuery CORS support -->
  <filter>
    <filter-name>ApiOriginFilter</filter-name>
    <filter-class>com.cwm.swagger.util.ApiOriginFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>ApiOriginFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping> 
<context-param>
 <param-name>javax.faces.PROJECT_STAGE</param-name>
 <param-value>Development</param-value>
</context-param>

   <context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
      </description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>false</param-value>
</context-param>

<session-config>
<session-timeout>10</session-timeout>
</session-config>
<error-page>
 <exception-type>javax.faces.application.ViewExpiredException</exception-type>
 <location>/faces/grp/default/pages/common/SessionTimeout.xhtml</location>
</error-page>

<context-param>
   <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
   <param-value>true</param-value>
</context-param>
</web-app>

Thanks and Regards

Sharath

Ron

unread,
Jul 25, 2014, 8:26:33 AM7/25/14
to swagger-sw...@googlegroups.com
Unfortunately, I don't have a CXF sample to test with at the moment (at least not one without Spring), so it may take slower to solve.
The problem is that the Swagger-core Provider classes aren't being registered.

Can you try replacing (in your web.xml) this - 

<init-param>
  <param-name>jaxrs.providers</param-name>
  <param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,
  com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,
  com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider
  </param-value>
 </init-param>

with this (note how the commas are removed):


  <init-param>
  <param-name>jaxrs.providers</param-name>
  <param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider
  com.wordnik.swagger.jaxrs.listing.ResourceListingProvider
  com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider
  </param-value>
 </init-param>

and let me know if it changes anything?

Sharath Kumar

unread,
Jul 25, 2014, 8:34:46 AM7/25/14
to swagger-sw...@googlegroups.com
Hi Ron,

I tried that. It does not seem to help as I am getting the same error response.

Thanks and Regards

Sharath

Ron

unread,
Jul 25, 2014, 8:37:17 AM7/25/14
to swagger-sw...@googlegroups.com
Is there any chance you could create a small sample project (single resource, single operation) that reproduces this issue and share it?
It would be much easier for me to try and solve it this way, and I admit I'm curious to know why it doesn't work.

I just don't really have experience with CXF so producing such a sample may take me much longer (plus, there's no guarantee I'll encounter the same problem).

Sharath Kumar

unread,
Jul 25, 2014, 8:42:37 AM7/25/14
to swagger-sw...@googlegroups.com
Sure Ron,

Sounds good. Will create a sample project and share it with you asap.

Thanks and Regards

Sharath

Satv

unread,
Oct 10, 2014, 5:18:19 AM10/10/14
to swagger-sw...@googlegroups.com
Hello,  Did anyone have any luck with this ?

I'm using CXF too, but non Spring. The only cxf related example in here doesn't really help. I would appreciate a small tutorial or step-by-step instructions on how to setup swagger with cxf and non-spring.

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop
...

Ron

unread,
Oct 10, 2014, 5:21:50 AM10/10/14
to swagger-sw...@googlegroups.com
If you can give me some more details about your CXF application, I may be able to help.
Do you use web.xml to configure it or some other way?
If web.xml, what's your configuration? If the other way, what's that too?

Also, I'm not sure regarding CXF (and possibly the specific version you use), do you use JAX-RS 1 or JAX-RS 2?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 10, 2014, 10:22:30 AM10/10/14
to swagger-sw...@googlegroups.com
Hello Ron,

The setup is more or less the same as above with some minor differences.
I use Jetty 7 with JAX-RS ( CXF 2.7.x ).  And no Spring.

I have maven for dependency management, and here's the pom.xml snippet :

        <dependency>
              <groupId>com.wordnik</groupId>
              <artifactId>swagger-core_2.10</artifactId>
             <version>1.3.0</version>
              <scope>compile</scope>
        </dependency>

        <dependency>
          <groupId>com.wordnik</groupId>
          <artifactId>swagger-jaxrs_2.10</artifactId>
          <version>1.3.0</version>
          <scope>compile</scope>
        </dependency>

       
Although I have a web.xml I don't directly use it to configure the servlets. Rather the servlet-mapping etc. is done via a Guice servlet.
So I set the server init-params in code like this :
       
        m.put("jaxrs.serviceClasses", "com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON");
        m.put("jaxrs.providers", "com.wordnik.swagger.jaxrs.json.JacksonJsonProvider, com.wordnik.swagger.jaxrs.listing.ResourceListingProvider, com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider");
        m.put("jaxrs.extensions", "json=application/json");
        m.put("api.version", "1.0");
        m.put("swagger.api.version", "1.3");
        m.put("swagger.api.basepath", "http://localhost/webapp/rest/");
        serve("/webapp/rest/*").with(CXFRestServlet.class, m);

The CXFRestServlet extends CXFNonSpringJaxrsServlet and so on. My rest APIs are available at /webapp/rest/<path> and I have all the annotations in place.

When I hit http://localhost/webapp/rest/api-docs/ what I get is :

{"apiVersion":"0.0","swaggerVersion":"1.2"}

I don't see any errors/exceptions as such in the logs. Perhaps my servlet config are not read in properly ? I also don't use the ApiAuthorizationFilter as of now. The ApiOriginFilter is mapped to /*

Please correct me if I got it wrong somewhere.
Thanks.
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.

Satv

unread,
Oct 10, 2014, 10:26:05 AM10/10/14
to swagger-sw...@googlegroups.com
Also, afaik cxf 2.7.x is compliant to both JAX-RS 1 and JAX-RS 2

Ron

unread,
Oct 10, 2014, 10:48:03 AM10/10/14
to swagger-sw...@googlegroups.com
You're actually facing a different issue than the original poster, since you're getting a response from api-docs. The problem is that the scanning is not being initialized.

First of all, you should change the dependency version to 1.3.10. You don't need swagger-core directly.
        <dependency>
          <groupId>com.wordnik</groupId>
          <artifactId>swagger-jaxrs_2.10</artifactId>
          <version>1.3.10</version>
          <scope>compile</scope>
        </dependency>


Regarding JAX-RS 1 or 2, it seems CXF 2.7 has some support for JAX-RS 2. The main question here is whether you're using @BeanParam which was introduced in JAX-RS 2.
If you're using @BeanParameter, you should change the dependency to the following:
        <dependency>
          <groupId>com.wordnik</groupId>
          <artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
          <version>1.3.10</version>
          <scope>compile</scope>
        </dependency>


There's actually a sample of how to use Swagger with Guice. It's based on Jersey 2 but the concept is the same.
The relevant parts should be:
https://github.com/wordnik/swagger-core/blob/master/samples/java-jersey2-guice/src/main/java/com/wordnik/swagger/sample/SwaggerExampleGuiceContextListener.java



--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 10, 2014, 11:30:10 AM10/10/14
to swagger-sw...@googlegroups.com
Yes, I tried most of the versions of 1.3.x. I started out with 1.3.10, but I was experimenting with 1.3.0 while posting the above.

And no, I'm not using BeanParam annotation.

I actually had a Jersey servlet, but had to switch to cxf recently. The Jersey based one used to work okay with swagger-jersey-jaxrs 1.3.0.  And I didn't have to explicitly scan. Just have a listener, and configure the servlet (and part of the config from web.xml) it was good to go. But I will try the example you posted.
Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Oct 10, 2014, 11:32:03 AM10/10/14
to swagger-sw...@googlegroups.com
The main question is whether you used Guice with Jersey or not, as that affects the configuration process. But please 1.3.0 is a very old version with many missing features and bugs, so it really is better to use 1.3.10.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 10, 2014, 11:41:01 AM10/10/14
to swagger-sw...@googlegroups.com
Yes, I used with Guice with Jersey. But part of the servlet configuration was done from web.xml. So the scanning process was oblivious for me.

1.3.0 - Yes, I understand. I'm using 1.3.10 now. Let me try to set the GuiceContextListener properly as per your example.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Oct 10, 2014, 11:42:19 AM10/10/14
to swagger-sw...@googlegroups.com
I see, well, that sample I referred you to uses a different method so perhaps try it first.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 10, 2014, 12:22:05 PM10/10/14
to swagger-sw...@googlegroups.com
I still have the same problem.
 
Then the bootstrap() method is mostly setting Authorization scopes. Is it really necessary ? I want to keep things simple now, and make sure it works.

Herer's my Guice servlet configuration looking like now:

        m.put("jaxrs.serviceClasses",  MyEndpoint.class.getName() + ", com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON");
        m.put("jaxrs.providers", MyJacksonJsonProvider.class.getName() + ", com.wordnik.swagger.jaxrs.json.JacksonJsonProvider, com.wordnik.swagger.jaxrs.listing.ResourceListingProvider, com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider");

        m.put("jaxrs.extensions", "json=application/json");
        m.put("swagger.api.version", "1.3");
        // m.put("swagger.api.basepath", "http://localhost/webapp/rest/");
          
        serve("/webapp/rest/*").with(CXFRestServlet.class, m);

        ReflectiveJaxrsScanner scanner = new ReflectiveJaxrsScanner();
        scanner.setResourcePackage(getClass().getPackage().getName());
        ScannerFactory.setScanner(scanner);
       
        SwaggerConfig config = ConfigFactory.config();
        config.setApiVersion("1.0.0");
        config.setBasePath("http://localhost/webapp/rest/");
        ConfigFactory.setConfig(config);
       
        // FilterFactory.setFilter(new ApiAuthorizationFilterImpl());
        ScannerFactory.setScanner(new DefaultJaxrsScanner());
        ClassReaders.setReader(new DefaultJaxrsApiReader());

I omitted a few things. (ApiOriginFilter is set from web.xml etc.).

So at the moment, what I get is like this :

{"apiVersion":"1.0.0","swaggerVersion":"1.2"}

I'm not sure why the swaggerVersion is showing up as 1.2, even though it is actually 1.3.
Is there anything else that I need to do to initiate scanning ?

Ron

unread,
Oct 10, 2014, 12:37:26 PM10/10/14
to swagger-sw...@googlegroups.com
Okay, that actually looks better.

You don't need the authorization part if there's no authorization on your API.

swaggerVersion should indeed be 1.2. I know it's confusing but that's the version of the spec. 1.3 is the version of the swagger-core library and that doesn't correspond with the specification version.

I have to ask, do you have any @Api and @ApiOperation annotations in your code? Are those classes being scanned by CXF (that is, can you access their exposed API)?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 13, 2014, 5:36:08 AM10/13/14
to swagger-sw...@googlegroups.com
Ron, Thanks for the pointers.

The annotations are very well in place. It used to work with my earlier Jersey based setup as well.
But now I notice some exceptions while accessing the APIs ( I have plenty of exposed APIs, most of them were working, so didn't notice the exceptions so far)

With the swagger integration, I hit this error while accessing some APIs.

javax.ws.rs.InternalServerErrorException: com.fasterxml.jackson.databind.JsonMappingException: Class com.sun.proxy.$Proxy281 has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation

    at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:396)
    at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:303)
    at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:155)
    at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:86)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Class com.sun.proxy.$Proxy281 has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation

    at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1042)
    at com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:554)
    at com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:69)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:706)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:522)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:632)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:541)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:632)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:610)
    at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:622)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1317)

I'm clueless as to what cause this. Some online search revealed that old jackson versions can result in this (I'm having jackson-core-2.4.3, jackson-jaxrs-json-provider-2.4.3, jackson-annotations-2.4.1 etc.).
And I'm not sure if this is the reason why swagger spec generation fails.

Ron

unread,
Oct 13, 2014, 6:19:59 AM10/13/14
to swagger-sw...@googlegroups.com
Can you share the output of 'mvn dependency:tree'?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 13, 2014, 6:53:24 AM10/13/14
to swagger-sw...@googlegroups.com
Here you go.
mvn_dependency.txt

Ron

unread,
Oct 13, 2014, 7:02:50 AM10/13/14
to swagger-sw...@googlegroups.com
It looks like hbase is relying on an old version of jackson but that shouldn't be related to the problem here since jackson 1 and jackson 2 switched package names as far as I know.
You can try explicitly excluding Swagger's jackson's dependency as it depends on an older one, just in case.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 13, 2014, 8:21:49 AM10/13/14
to swagger-sw...@googlegroups.com
The swagger's jackson dependencies which are conflicting are already omitted and is using the latest (2.4.3) and I don't think that is the issue.
I also switched to older versions of jackson (2.4.1, 2.3.0 etc) for my code that too didn't help.

The thing is that, I only hit this exception when swagger is enabled. So perhaps there are still version conflicts there.

Ron

unread,
Oct 13, 2014, 8:36:13 AM10/13/14
to swagger-sw...@googlegroups.com
I suspect this is related to the integration with Guice.
Since we've had a few iterations, I'm not sure which snippet is current, and it would be much easier to see the full guice/cxf initialization code, so if you can share that, that would be great.

Another option is you can create a sample app that reproduces the problem and I'll just work on that directly.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 13, 2014, 9:53:35 AM10/13/14
to swagger-sw...@googlegroups.com
Full guice/cxf initialization code - attached. Perhaps the 'configureServlets()' is what is of interest for you.

Sample app - the current application is quite huge and complex, with lots of dependencies. Will see if I can reproduce the problem at a small scale.
On the other hand, if there is a step-by-step guide for users to integrate in a cxf (non-spring) environment, that would be great - because I think I'm missing some steps.
If it works for me, I will be very happy to maintain such a guide as well in swagger repository.
CXFServerModule.java

Ron

unread,
Oct 13, 2014, 10:38:53 AM10/13/14
to swagger-sw...@googlegroups.com
Obviously, this would break your own application, but for the sake of testing, can you remove your own JacksonJsonProvider and try to access the swagger endpoint?

As for the documentation, I'm rewriting the whole set up thing and we have a priority set and I can't say that CXF+Guice is on the top of that list.
However, I hope that with the working sample that we will get, I could use that as a basis for the documentation.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Satv

unread,
Oct 13, 2014, 12:05:20 PM10/13/14
to swagger-sw...@googlegroups.com


On Monday, October 13, 2014 4:38:53 PM UTC+2, Ron R wrote:
Obviously, this would break your own application, but for the sake of testing, can you remove your own JacksonJsonProvider and try to access the swagger endpoint?

Nope. Doesn't work. I have a strong feeling that this has to do with the versions of swagger-jaxrs that I use. Will trial-and-error with other versions.
 
As for the documentation, I'm rewriting the whole set up thing and we have a priority set and I can't say that CXF+Guice is on the top of that list.
However, I hope that with the working sample that we will get, I could use that as a basis for the documentation.
Okay. Sure.
 

Ron

unread,
Oct 13, 2014, 12:07:59 PM10/13/14
to swagger-sw...@googlegroups.com
Let me know if you find anything, but our samples that use that swagger-jaxrs version work fine. It could be that a later version of jackson breaks compatibility and to test that you can try excluding your own version of jackson (though I don't know if your application depends on some of its features and may not compile without your version).

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Sharath Kumar

unread,
Feb 13, 2015, 6:06:50 AM2/13/15
to swagger-sw...@googlegroups.com
Hi Ron,

I started using Tomee 1.7 with the same configuration as above and it looks like Swagger is working. 


You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Sharath Kumar

unread,
Feb 13, 2015, 6:08:23 AM2/13/15
to swagger-sw...@googlegroups.com
Attached is the screen shot 

Inline image 1                



Do you think this means Swagger is working. Also how do I integrate with Swagger UI. Do I just copy the html file from the dist and host it on some server. Also does it make a CORS request? 

Thanks and Regards

Sharath

tony tam

unread,
Feb 13, 2015, 9:41:21 AM2/13/15
to swagger-sw...@googlegroups.com
That means the swagger resource listing is being enabled, but you are not triggering any of your classes to be scanned.  Without reading the whole thread, I suggest either looking at how this is done programmatically with BeanConfig, or via web.xml
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wHzJQjXQLqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Sharath Kumar

unread,
Feb 17, 2015, 2:43:37 AM2/17/15
to swagger-sw...@googlegroups.com
Hi Tony,

Thanks for the response. Attached is my web.xml. Where do I specify the classes to be scanned?

version="3.0" id="wallet">
<display-name>wallet</display-name>
<description>Application for authenticating cardholders</description>

<servlet>
     <servlet-name>CXFServlet</servlet-name>
     <servlet-class>
        org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
     </servlet-class>
 <init-param>
 <param-name>jaxrs.serviceClasses</param-name>
 <param-value>
com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON        
 </param-value>
</init-param>
<init-param>
 <param-name>jaxrs.providers</param-name>
 <param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,
 com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,
 com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider
 </param-value>
</init-param>
<init-param>
 <param-name>jaxrs.schemaLocations</param-name>
 <param-value>
   classpath:/WEB-INF/schemas/schema1.xsd
   classpath:/WEB-INF/schemas/schema2.xsd            
 </param-value>
</init-param> 
   <init-param>
     <param-name>swagger.security.filter</param-name>
     <param-value>com.cwm.swagger.util.ApiAuthorizationFilterImpl</param-value>
   </init-param>
 
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
     <servlet-name>CXFServlet</servlet-name>
     <url-pattern>/api/*</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

<context-param>
   <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
   <param-value>1</param-value>
</context-param>
<context-param>
   <param-name>facelets.REFRESH_PERIOD</param-name>
   <param-value>1</param-value>
</context-param>
<context-param>
   <param-name>facelets.DEVELOPMENT</param-name>
<session-timeout>1000</session-timeout>
<cookie-config>
<domain>ca.com</domain>
<max-age>86400</max-age>
</cookie-config>
</session-config>
<error-page>
 <exception-type>javax.faces.application.ViewExpiredException</exception-type>
 <location>/faces/grp/default/pages/common/SessionTimeout.xhtml</location>
</error-page>

<context-param>
   <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
   <param-value>true</param-value>
</context-param>
</web-app>



Thanks and Regards

Sharath

To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron Ratovsky

unread,
Feb 17, 2015, 4:47:03 AM2/17/15
to swagger-sw...@googlegroups.com
Which version of CXF do you use? Do you define anywhere the JAX-RS resources CXF should scan?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Sharath Kumar

unread,
Feb 17, 2015, 4:56:47 AM2/17/15
to swagger-sw...@googlegroups.com
Hi Ron,

We are using the Apache Tomee 1.7 Jee container. I checked the lib, it contains CXF version 2.6.14. I do not seem to have defined the JAX-RS resources to be scanned anywhere explicitly.

Thanks and Regards

Sharath

Ron Ratovsky

unread,
Feb 17, 2015, 5:01:02 AM2/17/15
to swagger-sw...@googlegroups.com
In that case, I believe you'd have to use the BeanConfig to configure Swagger and tell it which resources to scan, otherwise it will not know what's out there.

Sharath Kumar

unread,
Feb 17, 2015, 5:06:15 AM2/17/15
to swagger-sw...@googlegroups.com
Hi Ron,

Thanks. Will try that out and get back to you if I face any problems.

Thanks and Regards

Sharath

Sharath Kumar

unread,
Feb 18, 2015, 12:32:17 AM2/18/15
to swagger-sw...@googlegroups.com
Hi Ron,

Inline image 1     


Am getting the following now after using BeanConfig. I have only added the @Api and @Produces to my class. However I do not see the apis being listed here. Is there anything else that I need to do?

Thanks and Regards

Sharath

Sharath Kumar

unread,
Feb 18, 2015, 12:52:22 AM2/18/15
to swagger-sw...@googlegroups.com
This is how I have configured it...it still does not seem to be scanning my resources though

                BeanConfig beanConfig = new BeanConfig();
       beanConfig.setVersion( "1.0.2" );
       beanConfig.setResourcePackage( "com.ca.cwm.rs" ); // replace with your packages
       beanConfig.setBasePath( "http://localhost:3080/wallet/api/v1/nfc/hce/" );
       beanConfig.setDescription( "My RESTful resources" );
       beanConfig.setTitle( "My RESTful API" );
       beanConfig.setScan( true );


Thanks and Regards

Sharath

Ron Ratovsky

unread,
Feb 18, 2015, 4:42:00 AM2/18/15
to swagger-sw...@googlegroups.com
You need to add @ApiOperation on the operations you want to expose. Can you try that?

Sharath Kumar

unread,
Feb 18, 2015, 4:52:56 AM2/18/15
to swagger-sw...@googlegroups.com
That worked Ron...Thanks a ton...Now I just need to take the stuff from Dist folder of Swagger UI and put it in this server to integrate with the UI right?

Ron Ratovsky

unread,
Feb 18, 2015, 4:59:58 AM2/18/15
to swagger-sw...@googlegroups.com
Sure. Do you use maven?

Sharath Kumar

unread,
Feb 18, 2015, 5:13:19 AM2/18/15
to swagger-sw...@googlegroups.com

Yes Ron I use Maven...does the annotation @Api change the behaviour of @Path because I seemed to get some Jax-RS exception while accessing my REST API

Ron Ratovsky

unread,
Feb 18, 2015, 5:22:10 AM2/18/15
to swagger-sw...@googlegroups.com
No. @Api (or any of the swagger-core annotations) do not affect the JAX-RS library.

A for swagger-ui, you just need to drop the contents of the /dist dir to your webapp dir, and modify the 'url' parameter of the SwaggerUi object in the index.html to point at the url of the api-docs.

Sharath Kumar

unread,
Feb 19, 2015, 7:35:32 AM2/19/15
to swagger-sw...@googlegroups.com
Thanks for the information Ron. Will try this out and let you know if I have any doubts.

Thanks and Regards

Sharath
Reply all
Reply to author
Forward
0 new messages