I'm trying to deploy Jersey-Spring based REST API using Grizzly's com.sun.grizzly.http.embed.GrizzlyWebServer
. I also want to serve static content using the same. Here is what I have:
String host = "localhost";
int port = 8081;
// For jersey + Spring
ServletAdapter jAdapter = new ServletAdapter("jersey");
jAdapter.setContextPath("/api");
jAdapter.setServletInstance(new SpringServlet());
jAdapter.addContextParameter("contextConfigLocation", "classpath:spring-context.xml");
jAdapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
jAdapter.addServletListener("org.springframework.web.context.request.RequestContextListener");
// create GrizzlyWebServer
GrizzlyWebServer grizzlyServer = new GrizzlyWebServer(host, port, "webapp", false);
// add jersey adapter
grizzlyServer.addGrizzlyAdapter(jAdapter, new String[]{"/api"});
// start server
grizzlyServer.start();
System.out.println("Start running server(host: " + host + ",port: " + Integer.toString(port));
System.out.println("Press any key to stop the server.");
// hang on
System.in.read();
// stop
grizzlyServer.stop();
The "Jersey Adapter" works fine but I am not able to get the static content present in "webapp" folder to be served (404 Error).
My project folder structure is as follows:
GrizzlyTest
-- src
| |
| -- main
| |
| -- java
| -- resources
| |
| -- webapp
| | |
| | -- index.html
| -- spring-context.xml
|
-- pom.xml
Am I making a mistake in providing the path for "webapp" in the line new GrizzlyWebServer(host, port, "webapp", false);
??
Or, is there any other way to serve static content ??
WebappContext
may explain this:if (!(h instanceof StaticHttpHandler))
(grizzly-http-servlet-2.3.17.jar). Thoughts? Thanks. – Lavellelaven