cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffdavis <jeffdavis7...@gmail.com>
Subject Can't Generate swagger.json With CXFNonSpringJaxrsServlet
Date Thu, 04 Aug 2016 21:26:41 GMT
I am attempting to integrate swagger with a legacy REST service implemented
using an older version of CXF.  I've attempted several configurations but
can't get the swagger.json to generate.  Guidance on getting this resolved
is greatly appreciated.  Please see project code below:

*HelloService.java*

package swaggerRest;

import javax.ws.rs.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Path("/sample")
@Api(value = "/sample", description = "Sample REST for Swagger Testing")
public class HelloService {
 @GET
 @Path("hello")
 @ApiOperation(value = "Get hello message", response = String.class)
 public String sayHello(){
 return "Hello World";
 }
}

*web.xml*

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">

  <display-name>swaggerRest</display-name>
  
  <context-param>
    <param-name>contextParam</param-name>
    <param-value>contextParamValue</param-value>
  </context-param>
  
  <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>swaggerRest.HelloService</param-value>
    </init-param>
    <init-param>
      <param-name>jaxrs.features</param-name>
      <param-value>org.apache.cxf.jaxrs.swagger.Swagger2Feature
(basePath=/rest)</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

*pom.xml*

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>swaggerRest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <dependencies>
    
    <dependency>
         <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-extension-providers</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description</artifactId>
      <version>3.1.7</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-jaxrs</artifactId>
      <version>1.1.1</version>
    </dependency>  
  
    
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-jaxrs</artifactId>
        <version>1.5.8</version>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.5.9</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>swagger-ui</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency> 
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
      <version>3.1.7</version>
    </dependency> 
  </dependencies>
 
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>



--
View this message in context: http://cxf.547215.n5.nabble.com/Can-t-Generate-swagger-json-With-CXFNonSpringJaxrsServlet-tp5771073.html
Sent from the cxf-user mailing list archive at Nabble.com.

Mime
View raw message