I have been trying to use swagger to document my jaxrs-resteasy service. I want to configure this programmatically in a embedded jetty server setting. Here are my Resource,Server and Application classes. I can access http://127.0.0.1:9091/rest/hello and verify that my rest service is working.. but when i try to access http://127.0.0.1:9091/rest/api-docs i cant get it working, but see a 404 not found instead. Can someone point me towards what i could be doing wrong while configuring Swagger.
Resource file
@Api(value = "/", description = "Index")
@Path("/")
public class Index {
@GET
@ApiOperation(
value = "call Index",
response = Response.class,
responseContainer = "Object"
)
@Produces("text/html")
public Response index() throws URISyntaxException {
File f = new File(System.getProperty("user.dir")+"/index.html");
String mt = new MimetypesFileTypeMap().getContentType(f);
return Response.ok(f, mt).build();
}
@GET
@Path("/hello")
@ApiOperation(
value = "hello Get",
response = Response.class,
responseContainer = "Object"
)
public Response helloGet() {
return Response.status(200).entity("HTTP GET method called").build();
}
}
Server
public class JettyServer {
public static void main(String[] args) throws IOException {
Server server = new Server(9091);
final HandlerList handlers = new HandlerList();
ServletHolder h = new ServletHolder(new HttpServletDispatcher());
h.setInitParameter("javax.ws.rs.Application", "com.all.MyServices");
// h.setInitOrder(1);
ServletContextHandler restContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
restContextHandler.setContextPath("/rest");
restContextHandler.addServlet(h, "/*");
handlers.addHandler(restContextHandler);
server.setHandler(handlers);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Service file
public class MyServices extends Application {
private static Set<Index> services = new HashSet<>();
public MyServices() {
System.out.println( "Initializing Swagger BeanConfig" );
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0");
beanConfig.setResourcePackage( Index.class.getPackage().getName() );
beanConfig.setBasePath( "http://localhost:9091/api" );
beanConfig.setDescription( "My RESTful services" );
beanConfig.setTitle( "My RESTful API" );
beanConfig.setScan( true );
services.add(new Index());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Set getSingletons() {
return services;
}
@SuppressWarnings("rawtypes")
public static Set getServices() {
return services;
}
}I imagine you have more experience with that than me, but that should give you the direction you should be looking at.
--
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.
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/abc","description":"Index"}],"info":{"title":"My RESTful API","description":"My RESTful services"}}
is the actual response i am getting, but i was expecting this showed up with a UI.
Anusha
--
--
--
--
--
{
apiVersion: "4.0.0.0",
swaggerVersion: "2.0",
basePath: "http://localhost:5555",
resourcePath: null,
apis: [
{
path: "/api/docs/Values",
description: "No Documentation Found.",
operations: [ ]
},
{
path: "/api/docs/Home",
description: "No Documentation Found.",
operations: [ ]
}
]}
{"apiVersion":"1.0","swaggerVersion":"1.2","info":{"title":"Swagger Title","description":"My Swagger page"}}This is the service,
@GET
@Path("/hello")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(
value = "get hello",
response = Response.class,
responseContainer = "Object"
)
@Wrapped(element = "network-services")
public Response getHello() {
}
I added annotation to the model too.
@XmlRootElement(name = "network-service")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
@ApiModel( value = "NetworkService", description = "Network Service Model" )
public class NetworkService {
@XmlElement(name = "service-id")
@JsonProperty("service-id")
@ApiModelProperty( value = "Network service's id", required = true )
private String serviceId;
}
For the Swagger UI file, I copied all the folders under dist folder to my src/main/webapp, and changed the url to be "http://localhost:8085/swagger/api-docs"
Is there something I'm missing here.
thank you.To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
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+unsubscri...@googlegroups.com.
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-swaggers...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/","description":"Manage Swagger UI"}],"info":{"title":"Swagger Title","description":"My Swagger page"}}To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/","description":"Rest Service"},{"path":"/root","description":"Manage Swagger UI"}],"info":{"title":"Swagger Title","description":"My Swagger page"}}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-swaggers...@googlegroups.com.
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/root","description":"Manage Swagger UI"}],"info":{"title":"Swagger Title","description":"My Swagger page"}}To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
I don't know the context root of your application, so it's difficult to say.Have you tried http://localhost:8085/ directly?
On 26 November 2014 at 23:18, Amanda Lee <amanda...@gmail.com> wrote:
Hi, Ron, you are right. I deleted another api with "Rest service" description, and did a build.Here is the swagger documentation "http://localhost:8085/swagger/api-docs"{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/root","description":"Manage Swagger UI"}],"info":{"title":"Swagger Title","description":"My Swagger page"}}but I still get exception for "http://localhost:8085/swagger/", "http://localhost:8085/swagger/root", and 404 error for "http://localhost:8085/root",
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+unsubscri...@googlegroups.com.
Hi, Ron, when I open the index.html under my webapp folder, it shows like this, it can show the Rest API I add annotation to. But this GET method returns 404 error. The Request URL is "http://localhost:8085/api/network-services/hello", when I browse this url, it returns 404 error.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
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+unsubscri...@googlegroups.com.
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-swaggers...@googlegroups.com.
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.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
I'd suggest googling further then. I'm pretty much out of ideas for now.
On 2 December 2014 at 22:04, Amanda Lee <amanda...@gmail.com> wrote:
Hi, Ron, I tried "swaggerHandler.setResourceBase("webapp");", and print out the resourceBase, it shows: "file:/C:/workspace/projectName/webapp". For "swaggerHandler.setResourceBase("/webapp");", it print out the resourcebase "file:/C:/webapp". They both throw the "couldn't find resource for the full path....". I'm testing with the url "http://localhost:8085/swagger/" for the page.
On Tuesday, December 2, 2014 2:55:45 PM UTC-5, Ron R wrote:
Then perhaps swaggerHandler.setResourceBase("webapp"); or swaggerHandler.setResourceBase("/webapp"); would work.
On 2 December 2014 at 21:53, Amanda Lee <amanda...@gmail.com> wrote:
Hi, Ron, I extracted the jar file, here is its structure. I checked the webapp folder, it contains all the Swagger UI files(under dist folder from github).
On Tuesday, December 2, 2014 2:43:02 PM UTC-5, Ron R wrote:Right, it's a jar because it uses embedded jetty and is not a deployable web app, forgot about it.I don't know if the setResourceBase would work properly with a URI. When setting it, that's definitely not the path. Extract the jar and check its internal structure.
--
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+unsubscri...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.