I recently followed this blog to integrate swagger in my embedded jetty project but after running, I'm not able to access the swagger.json file on any path combination. Accessing the servlets for the resources work with no error but I get the following errors when I try to get the swagger.json file
http://host:7000/swagger-core ===> HTTP ERROR 405
http://host:7000/swagger-core/swagger.json ===> HTTP ERROR 404
http://host:7000/user/swagger.json ===> HTTP ProfileServlet response, not swagger.json
http://host:7000/user ===> HTTP ProfileServlet response, not swagger.json
http://host:7000/swagger.json ===> HTTP ERROR 404
http://host:7000/api/swagger.json ===> HTTP ERROR 404
http://host:7000/ ===> Static swagger sample page (Pet store), not swagger.jsonMain.java
public static void main(String[] args) throws Exception {
Server server = initializeApi(properties);
server.start();
logger.info("Api resource service started");
server.join();
}
private static Server initializeApi(Properties properties) {
logger.info("Initializing user profile server...");
new UserDao();
Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT)));
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
server.setHandler(servletContextHandler);
//Setup APIs
ServletHolder apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*");
apiservlet.setInitOrder(1);
apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing");
logger.info("User profile server initialized.");
// Setup Swagger servlet
ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultJaxrsConfig.class, "/swagger-core");
swaggerServlet.setInitOrder(2);
swaggerServlet.setInitParameter("api.version", "1.0.0");
// Setup Swagger-UI static resources
String resourceBasePath = Main.class.getResource("/webapp").toExternalForm();
servletContextHandler.setWelcomeFiles(new String[] {"index.html"});
servletContextHandler.setResourceBase(resourceBasePath);
servletContextHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*");
return server;
}
}ProfileServlet.java
@SwaggerDefinition(
info = @Info(
title = "User Profile Servlet",
version = "1.0.0",
description = "Servlet that handles basic CRUD operations to the user profile data source",
contact = @Contact(name = "XYZ", email = "XYZ", url = "XYZ"),
termsOfService = "XYZ",
license = @License(name = "XYZ", url = "XYZ")
),
basePath = "/",
consumes = {"application/json"},
produces = {"application/json"},
schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
tags = {@Tag(name = "users", description = "CRUD operations on user datatype")}
)
@Api(value = "/user", description = "performs CRUD operations on a user profile")
public class ProfileServlet extends HttpServlet {
Logger logger = Logger.getLogger(ProfileServlet.class.getSimpleName());
public ProfileServlet(){
}
@ApiOperation(httpMethod = "GET", value = "Returns a list of the user profile datatype", notes = "", response = UserDatatype.class, nickname = "getUser", tags = ("User"))
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Succssful retrieval of user profiles", response = UserDatatype.class),
@ApiResponse(code = 500, message = "Internal server error")
})
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "profile id", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "firstname", value = "First name of user", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "lastname", value = "Last name of user", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "phone", value = "phone number of user", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "signup", value = "Sign up date of user, in dd-MM-yyyy forma", required = false, dataType = "java.sql.Date", paramType = "query")
})
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
RpcLogTemplate logTemplate = new RpcLogTemplate(req.getRemoteHost(),req.getParameter("client"), req.getParameter("clientapp"), Config.localhost, Config.SERVICE_INSTANCE, Config.SERVICE_APP, req.getParameterMap(), new Date().getTime() );
logger.debug("Received request: GET");
handleGet(req, resp, logTemplate);
logTemplate.setResponseTimestamp(new Date().getTime());
//LoggerService.INSTANCE.addLog(logTemplate);
}
private void handleGet(HttpServletRequest request, HttpServletResponse response, RpcLogTemplate logTemplate) throws IOException {
Gson gson = new Gson();
String param = null;
param = request.getParameter("id");
if(param!= null){
logger.info("Query by ID received. All other params would be ignored");
UserDatatype userDatatype = UserDao.INSTANCE.findById(param);
if(userDatatype == null){
response.setStatus(HttpServletResponse.SC_OK);
logger.info("Null object returned");
return;
}else{
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter printWriter = response.getWriter();
printWriter.write(gson.toJson(userDatatype, UserDatatype.class));
printWriter.flush();
printWriter.close();
}
}else{
Map<String, String> queryString = new HashMap<>();
//TODO: optimize this
param = request.getParameter("firstname");
if(param != null)
queryString.put("firstname", param);
param = request.getParameter("lastname");
if(param != null)
queryString.put("lastname", param);
param = request.getParameter("phone");
if(param != null)
queryString.put("phone", param);
param = request.getParameter("signup");
if(param != null)
queryString.put("signup", param);
UserDatatype[] userDatatypes = UserDao.INSTANCE.findByParams(queryString);
if(userDatatypes == null){
response.setStatus(HttpServletResponse.SC_OK);
logger.info("Null object returned");
return;
}else{
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter printWriter = response.getWriter();
printWriter.write(gson.toJson(userDatatypes, UserDatatype[].class));
printWriter.flush();
printWriter.close();
}
}
}
}Bootstrap.java
public class Bootstrap extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:7000");
beanConfig.setBasePath("/");
beanConfig.setResourcePackage("io.swagger.resources");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}}
All help appreciated.
http://host:7000/api/swagger.json ===> {"swagger":"2.0","info":{"version":"1.0.0","title":""}}
private static Server initializeApi(Properties properties) {
logger.info("Initializing user profile server...");
new UserDao();
Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT)));
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
server.setHandler(servletContextHandler);
//Setup APIs
ServletHolder apiservlet = servletContextHandler.addServlet(ServletContainer.class, "/api/*");
apiservlet.setInitOrder(1);
apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing");
apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*");
//apiservlet.setInitOrder(1); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing");
so they can be scanned.--
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.
apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*");
apiservlet.setInitOrder(3);
apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.coreservices.servlets;package com.coreservices.datatypes");apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*");
apiservlet.setInitOrder(3);
apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing;com.coreservices.servlets;package com.coreservices.datatypes");
{"swagger":"2.0","info":{"version":"1.0.0","title":""}}
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Which version of Jersey do you use?
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.
--
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.
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19.1</version>
</dependency>
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 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.
Okay, so it should work.
Is your API itself accessible? Can you make any of the API calls successfully?
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.
--
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.
--
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.
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 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 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.
Looking back, you have a Bootstrap class with the line
beanConfig.setResourcePackage("io.swagger.resources");
Change “io.swagger.resources” to the package(s) of your resources and that should allow it to pick them up and scan them.
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.
--
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.
--
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.
--
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.
beanConfig.setResourcePackage("com.api.resources");
beanConfig.setResourcePackage("io.swagger.jaxrs.json");
beanConfig.setResourcePackage("io.swagger.jaxrs.listing");
beanConfig.setResourcePackage("com.gh.cive.coreservices.servlets");
beanConfig.setResourcePackage("com.gh.cive.coreservices.datatypes");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
308 [main] INFO Main - User profile server initialized.Dec 22, 2016 3:57:50 PM com.sun.jersey.api.core.PackagesResourceConfig initINFO: Scanning for root resource and provider classes in the packages:com.api.resourcesio.swagger.jaxrs.jsonio.swagger.jaxrs.listingcom.coreservices.servletscom.coreservices.datatypesDec 22, 2016 3:57:50 PM com.sun.jersey.api.core.ScanningResourceConfig logClassesINFO: Root resource classes found:class io.swagger.jaxrs.listing.AcceptHeaderApiListingResourceclass io.swagger.jaxrs.listing.ApiListingResourceDec 22, 2016 3:57:50 PM com.sun.jersey.api.core.ScanningResourceConfig logClassesINFO: Provider classes found:class io.swagger.jaxrs.listing.SwaggerSerializersDec 22, 2016 3:57:50 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiateINFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'2277 [main] INFO Main - user profile service started
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 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 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 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.
beanConfig.setResourcePackage("com.api.resources");
beanConfig.setResourcePackage("io.swagger.jaxrs.json");
beanConfig.setResourcePackage("io.swagger.jaxrs.listing");
beanConfig.setResourcePackage("com.coreservices.servlets");
beanConfig.setResourcePackage("com.coreservices.datatypes");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
<pre style="backg
Try keeping only
beanConfig.setResourcePackage("com.coreservices.servlets");
--
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.
{
"swagger" : "2.0",
"info" : {
"description" : "Servlet that handles basic CRUD operations to the user profile data source",
"version" : "1.0.2",
"title" : "User Profile Servlet",
"termsOfService" : "XYZ",
"contact" : {
"name" : "XYZ",
"url" : "XYZ",
"email" : "XYZ"
},
"license" : {
"name" : "XYZ",
"url" : "XYZ"
}
},
"host" : "localhost:7000",
"basePath" : "/",
"tags" : [ {
"name" : "users",
"description" : "CRUD operations on user datatype"
} ],
"schemes" : [ "http", "https" ],
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ]
}
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
The package input should be able to accept comma separated values, so you can try that.
You can’t mix servlets and jax-rs resources for scanning as they use different scanners that can’t really co-exist. Do you use both?
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.
--
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.
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 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.
What I’m saying is that you can’t use swagger-core for both jax-rs resources and servlets in a single app.
Ok thanks.
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.
--
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.
--
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.
Ok thanks.
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 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 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.
Huh, I misread it as you using jersey. You need to use a different dependency then and a different set up process.
We don’t really have documentation for it, but there’s a sample - https://github.com/swagger-api/swagger-samples/tree/master/java/java-servlet
Ok thanks.
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.
--
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.
--
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.
--
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.
import org.apache.log4j.Logger;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import io.swagger.servlet.listing.ApiDeclarationServlet;
import io.swagger.servlet.config.DefaultServletConfig;
.
.
.
logger.info("Initializing user profile server...");
new UserDao();
Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT)));
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
server.setHandler(servletContextHandler);
//Custom servlet
ServletHolder apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*");
apiservlet.setInitOrder(3);
logger.info("User profile server initialized.");
// Swagger servlet reader
ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultServletConfig.class, "/swagger-core");
swaggerServlet.setInitOrder(2);
swaggerServlet.setInitParameter("api.version", "1.0.0");
//swaggerServlet.setInitParameter("swagger.resource.package", "com.coreservices.servlets,com.coreservices.datatypes"); NOTE::THIS DOES NOT WORK
swaggerServlet.setInitParameter("swagger.resource.package","com.coreservices.servlets");
swaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:7000");
// Swagger api declaration
servletContextHandler.addServlet(ApiDeclarationServlet.class, "/api/*");
return server;
}Ok thanks.
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 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 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 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.
If scanning multiple packages isn’t working for you, you should open a ticket on the project. We may have some basic bugs with servlet implementation as that’s less commonly used.
The scanning should definitely pick up anything that has the @Api annotations on it. The only reason it wouldn’t is if they are not in the package you’ve set to be scanned.
Have you had a look at the servlet sample?
Ok thanks.
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.
--
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.
--
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.
--
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.
--
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.
The web.xml is not the only way to configure it, and I think you’ve went with different approach(es). What did you end up using?
--
import org.eclipse.jetty.server.Server;import org.eclipse.jetty.servlet.ServletContextHandler;import org.eclipse.jetty.servlet.ServletHolder;import io.swagger.servlet.listing.ApiDeclarationServlet;import io.swagger.servlet.config.DefaultServletConfig;
Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT))); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); server.setHandler(servletContextHandler);
//Custom servlet ServletHolder apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); apiservlet.setInitOrder(3); logger.info("User profile server initialized.");
// Swagger servlet reader ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultServletConfig.class, "/swagger-core"); swaggerServlet.setInitOrder(2); swaggerServlet.setInitParameter("api.version", "1.0.0"); //swaggerServlet.setInitParameter("swagger.resource.package", "com.coreservices.servlets,com.coreservices.datatypes"); swaggerServlet.setInitParameter("swagger.resource.package","com.coreservices.servlets"); swaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:7000");
// Swagger api declaration servletContextHandler.addServlet(ApiDeclarationServlet.class, "/api/*"); server.start();import io.swagger.annotations.*;import org.apache.log4j.Logger;
import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
/** * Created on 12/21/2016. */@SwaggerDefinition( info = @Info( title = "User Profile Servlet", version = "1.0.0", description = "Servlet that handles basic CRUD operations to the user profile data source", contact = @Contact(name = "XYZ", email = "XYZ", url = "XYZ"), termsOfService = "XYZ", license = @License(name = "XYZ", url = "XYZ") ), basePath = "/", consumes = {"application/json"}, produces = {"application/json"}, schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, tags = {@Tag(name = "users", description = "CRUD operations on user datatype")})@Api(value = "/user", description = "performs CRUD operations on a user profile")public class ProfileServlet extends HttpServlet { Logger logger = Logger.getLogger(ProfileServlet.class.getSimpleName());
@ApiOperation(httpMethod = "GET", value = "Returns a [list of the] user profile datatype", notes = "", response = UserDatatype.class, nickname = "getUser", tags = ("User")) @ApiResponses(value = { @ApiResponse(code = 200, message = "Succssful retrieval of user profiles", response = UserDatatype.class), @ApiResponse(code = 500, message = "Internal server error") }) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "profile id", required = false, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "firstname", value = "First name of user", required = false, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "lastname", value = "Last name of user", required = false, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "phone", value = "phone number of user", required = false, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "signup", value = "Sign up date of user, in dd-MM-yyyy forma", required = false, dataType = "java.sql.Date", paramType = "query") }) @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RpcLogTemplate logTemplate = new RpcLogTemplate(req.getRemoteHost(),req.getParameter("client"), req.getParameter("clientapp"), Config.localhost, Config.SERVICE_INSTANCE, Config.SERVICE_APP, req.getParameterMap(), req.getRequestURI(), new Date().getTime() ); logger.debug("Received request: GET"); logger.debug("Request URI: " + req.getRequestURI()); logger.debug("Request servlet path: " + req.getServletPath()); handleGet(req, resp, logTemplate); logTemplate.setResponseTimestamp(new Date().getTime()); logTemplate.setResponseCode(Integer.toString(resp.getStatus())); Main.loggerService.addLog(logTemplate); }}<?xml version="1.0" encoding="UTF-8"?><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.coreservice.dataservice</groupId> <artifactId>ServiceUserProfile</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <jetty.version>9.4.0.v20161208</jetty.version> </properties> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!--Jetty dependencies start --> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>${jetty.version}</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> <version>${jetty.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-servlet</artifactId> <version>1.5.10</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.7</version> </dependency> <dependency> <groupId>com.jolbox</groupId> <artifactId>bonecp</artifactId> <version>0.8.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.2.2.RELEASE</version> </dependency>
<!--Jetty dependencies end --> </dependencies>
<!-- Download the Swagger-UI project --> <build> <plugins> <plugin> <groupId>com.googlecode.maven-download-plugin</groupId> <artifactId>download-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <id>swagger-ui</id> <phase>validate</phase> <goals> <goal>wget</goal> </goals> <configuration> <unpack>true</unpack> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- Load the Swagger-UI components into the src/main/webapp/ directory to enable viewing/testing of the API routes. Accessible at http://<host>:<port>/swagger. --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-resources</id> <phase>initialize</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/src/main/resources/webapp</outputDirectory> <resources> <resource> <directory>${project.build.directory}/swagger-ui-master/dist</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build>
</project>
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Okay, since you mentioned using two packages isn’t working, what happens if you only set com.coreservices.servlet for the resource packing?
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.
--
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 the ‘resource scanning’ that is.
At this point, I’d ask that you provide a sample app that reproduces it – would be difficult to try and debug it otherwise.
--
{ "swagger": "2.0", "info": { "description": "Servlet that handles basic CRUD operations to the user profile data source", "version": "1.0.0",