Yeah the Api calls work. I can make calls to my servlets without error. Its just the swagger documentation is not generating any of my annotations.
On Thursday, 22 December 2016 15:25:14 UTC-5, Ron wrote: > > Okay, so it should work. > > > > Is your API itself accessible? Can you make any of the API calls > successfully? > > > > > > > > *From: *<swagger-sw...@googlegroups.com <javascript:>> on behalf of janet > vanderpuye <rhy...@gmail.com <javascript:>> > *Reply-To: *"swagger-sw...@googlegroups.com <javascript:>" < > swagger-sw...@googlegroups.com <javascript:>> > *Date: *Thursday, 22 December 2016 at 11:37 > *To: *Swagger <swagger-sw...@googlegroups.com <javascript:>> > *Subject: *Re: Cant locate swagger.json on java + embedded jetty + > httpservlet + swagger integration > > > > In my pom file, I have *1.19.1* > > > > <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> > > > On Thursday, 22 December 2016 14:34:08 UTC-5, Ron wrote: > > Which version of Jersey do you use? > > > > > > > > *From: *<swagger-sw...@googlegroups.com> on behalf of janet vanderpuye < > rhy...@gmail.com> > *Reply-To: *"swagger-sw...@googlegroups.com" < > swagger-sw...@googlegroups.com> > *Date: *Thursday, 22 December 2016 at 11:10 > *To: *Swagger <swagger-sw...@googlegroups.com> > *Subject: *Re: Cant locate swagger.json on java + embedded jetty + > httpservlet + swagger integration > > > > So for my servlets, I just tried: > > > > apiservlet = servletContextHandler.addServlet(ProfileServlet.class, > "/user/*"); > apiservlet.setInitOrder(3); > apiservlet.setInitParameter("com.sun.jersey.config.property.packages", > "com.coreservices.servlets;package com.coreservices.datatypes"); > > > > and > > > > 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"); > > > > I am still getting the default swagger response > > *{"swagger":"2.0","info":{"version":"1.0.0","title":""}}* > > Am I missing any annotation or configuration in the files? > > Secondly to access the swagger ui annotation for my custom servlet > "ProfileServlet.class", do I use the same url as " > http://host:7000/api/swagger.json"? > > > > Really appreciate the quick feedback on this > > > On Thursday, 22 December 2016 13:52:18 UTC-5, tony tam wrote: > > Sounds like the issue then is how it’s scanning your code. Put your API > package here: > > > > apiservlet.setInitParameter("com.sun.jersey.config.property.packages", > "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing"); > > so they can be scanned. > > > > On Dec 22, 2016, at 10:50 AM, janet vanderpuye <rhy...@gmail.com> wrote: > > > > Quick update. After modifying the initializeAPI method to the original > Servlet class in the blog(see below), I was able to get some response from > the swagger-ui on http://host:7000/api/swagger.json. But I it seems like > swagger wasnt able to parse my servlet annotations > > 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"); > *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; > } > > > On Thursday, 22 December 2016 13:31:03 UTC-5, janet vanderpuye wrote: > > I recently followed this blog > <https://gist.github.com/nosmokingpistol/302c4c3ef30f183cf70e> 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.json > > Main.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. > > > > -- > 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+unsubscr...@googlegroups.com <javascript:>. > 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+unsubscr...@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+unsubscr...@googlegroups.com <javascript:>. > 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.