-------------------------------------------- On Fri, 12/23/16, janet vanderpuye <rhy...@gmail.com> wrote:
Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration To: "Swagger" <swagger-swaggersocket@googlegroups.com> Date: Friday, December 23, 2016, 12:39 AM Oh ok. Maybe I need to read up a bit on Jax-rs but I believe application was built using only servlets. I had only the Bootstrap class and ProfileServlets class, which were written using HttpServlets. Unless one of the default package imports was built on Jax-rs. Thanks for the tip, I will double check for that. On Thursday, 22 December 2016 17:30:02 UTC-5, Ron wrote:What I’m saying is that you can’t use swagger-core for both jax-rs resources and servlets in a single app. 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 14:26 To: Swagger <swagger-sw...@ googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Ok thanks. On a quick scan, I used the BeanConfig class under io.swagger.jaxrs.config in the Bootstrap.java servlet. Maybe that is where the conflict arises from. Do you have any suggestions on how to initialize swagger servlet( That is the main purpose of the Bootstrap class). 90% the examples and tutorials I saw used the web.xml option and I was trying to avoid that. On Thursday, 22 December 2016 17:04:52 UTC-5, Ron wrote: 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? 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 13:53 To: Swagger <swagger-sw...@googlegroups. com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration WHOOHOO! We have success! Thank you, guys. You are amazing. I had spent the better part of 16 hours on this before I admitted defeat. That aside, i have a couple of questionsDoes the beanConfig.setResourcePackage( "package name") take in only one package? If so, do I have to move all swagger resources into the package?What happens to my @ApiModel resource object which I have defined in another package? This is essentially a datatype so traditionally it is held in a different package from the servlets.I noticed that the documentation skipped the annotations i had for the HttpServlet.doGet() method. Is this normal? I was expecting it to list all functions and types that i had specified with the @ApiOperation, @ApiResponse, etc annotation. This is my current swagger.json output: { "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" ] } Many thanks for the help. On Thursday, 22 December 2016 16:10:02 UTC-5, Ron wrote: Try keeping onlybeanConfig.setResourcePackage( "com.coreservices.servlets"); 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 13:05 To: Swagger <swagger-sw...@googlegroups. com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Sorry, corrected package. Same result though 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 ); On Thursday, 22 December 2016 16:03:57 UTC-5, janet vanderpuye wrote: Thanks Ron. I tried that and no success. The new code for the bootstrap class was 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 ); Looking at the logs, it shows that at least it picked up my servlet package for scanning. Could it be an error in the way I declared the annotations? Log output is: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.resources io.swagger.jaxrs.json io.swagger.jaxrs.listing com.coreservices.servlets com.coreservices.datatypesDec 22, 2016 3:57:50 PM com.sun.jersey.api.core. ScanningResourceConfig logClassesINFO: Root resource classes found: class io.swagger.jaxrs.listing. AcceptHeaderApiListingResource class 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 On Thursday, 22 December 2016 15:47:24 UTC-5, Ron wrote: 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. 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 12:28 To: Swagger <swagger-sw...@googlegroups. com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration 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> 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:37 To: Swagger <swagger-sw...@googlegroups. com> 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 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 filehttp://host:7000/swagger-core ===> HTTP ERROR 405http://host:7000/swagger-core/ swagger.json ===> HTTP ERROR 404http://host:7000/user/swagger. json ===> HTTP ProfileServlet response, not swagger.jsonhttp://host:7000/user ===> HTTP ProfileServlet response, not swagger.jsonhttp://host:7000/swagger.json ===> HTTP ERROR 404http://host:7000/api/swagger. json ===> HTTP ERROR 404http://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(ServletC ontextHandler.SESSIONS); servletContextHandler. setContextPath("/"); server.setHandler( servletContextHandler); //Setup APIs ServletHolder apiservlet = servletContextHandler. addServlet(ProfileServlet.clas s, "/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<pre style="backg-- 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. 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. For more options, visit https://groups.google.com/d/optout. age 29 of 131separai de distana - el la Bucureti ea la Iai - se vedeau rar in schimb purtau o frecventa corespondena. [tatalui sau in 18 mar. 1881 la 31 de ani] Bucureti 18 martie 1881 Iubite Tata M-am bucurat mult primind scrisoarea d-tale in versuri i m-am intristat asemenea afland din ea ca nu eti tocmai bine. Altfel i eu am avut acele friguri de primavara atat de obicinuite in ara la noi. N-am raspuns numaidecat pentru ca m-a apucat proclamarea regatului 1 pe dinainte i-n asemenea imprejurari noi negustorii de gogoi i de braoave adica noi gazetarii suntem foarte ocupai 2 . A dori din toata inima sa vin acasa sa va vad dac-a gasi vrun om de incredere care sa-mi ie locul caci negustoria asta pe langa ca n-aduce nimic nici nu te ingaduie sa inchizi o zi doua dugheana i sa mai iei lumea-n cap ci-n toate zilele trebuie omul sa-i bata capul ca sa afle minciuni noua. Dac-oi putea scapa iubite tata fie acum fie la vara vin desigur acasa. il rog pe Nicu a sa-mi scrie mai des i sa nu se uite la aceea ca nu-i raspund caci daca am aa de puina vreme de scris i daca mi-e acru sufletul de cerneala i de condei citesc totui cu multa bucurie scrisorile ce le primesc de la d-voastra. Sarutandu-i manile i dorindu-i multa sanatate i voie buna raman al d-tale supus fiu Mihai 1. proclamarea regatului - Romania a fost proclamata regat - i Carol I incoronat rege - in 14 martie 1881. 2. noi gazetarii suntem foarte ocupai - Eminescu era pe atunci redactor-ef la ziarul conservator Timpul i scria ziarul in buna parte el singur. 29 Page 29 of 131 -- 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.