I'm trying to configure my Jersey 1.x REST project to produce Swagger documentation. Actually the REST works well but the swagge doesn't work. I'm running the project on WAS 8.5 and when I go with the browser at the URL:
http://localhost:9082/TestSwagger/swagger.yaml
the server returns a 404 error.
I post the libs included in the project and the interested java files for some help:
Included libs:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>TestSwagger</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>it.test.application.TestApplication</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Class that extends from javax.ws.rs.core.Application:
package it.test.application;
import io.swagger.jaxrs.config.BeanConfig;
import it.test.rest.impl.TestServiceImpl;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class TestApplication extends Application {
public TestApplication() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:9082");
beanConfig.setBasePath("/TestSwagger");
beanConfig.setResourcePackage("it.test.rest.impl");
beanConfig.setScan(true);
}
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(TestServiceImpl.class);
classes.add(io.swagger.jaxrs.listing.ApiListingResource.class);
classes.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
return classes;
}
}
TestServiceImpl.java that contains the implementation of the REST service and the swagger annotation:
package it.test.rest.impl;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Contact;
import io.swagger.annotations.ExternalDocs;
import io.swagger.annotations.Info;
import io.swagger.annotations.License;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import it.test.bean.ReturnBean;
import it.test.rest.TestService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@SwaggerDefinition(
info = @Info(
description = "Test",
version = "1",
title = "Test",
termsOfService = "",
contact = @Contact(
name = "Test",
email = "test@test.it",
url = "http://test"
),
license = @License(
name = "Apache 2.0",
url = "http://www.apache.org/licenses/LICENSE-2.0"
)
),
consumes = {"application/json", "application/xml"},
produces = {"application/json", "application/xml"},
schemes = {SwaggerDefinition.Scheme.HTTP},
tags = {
@Tag(name = "Private", description = "Tag used to denote operations as private")
},
externalDocs = @ExternalDocs(value = "EXT DOC", url = "http://test")
)
@Path("/test/servizi")
public class TestServiceImpl implements TestService {
@Override
@GET
@ApiOperation(value = "Get Hello",
response = TestServiceImpl.class)
@Path("/hello")
@Produces({MediaType.APPLICATION_JSON})
public ReturnBean getHello() throws Exception {
ReturnBean returnBean = new ReturnBean();
returnBean.setRitorno("HELLO");
return returnBean;
}
}
As Paul Samsotha suggested, with the add of rest
in the URL it works!