Reputation: 6188
I have developed a RESTful application using Jersey and grizzly embedded server. The multipart file upload is working but I don't know how to serve the uploaded static files when the client requests them.
My question may sound a bit general but I think my problem is also quite general. I can provide the details of my project if they are necessary but I am looking for a general answer.
Upvotes: 0
Views: 639
Reputation: 1979
Here is the sample how you can add static and dynamic request processing:
ResourceConfig rc = new ResourceConfig().register(TestResource.class);
URI jerseyAppUri = UriBuilder.fromUri("http://0.0.0.0/api")
.port(8080).build();
// Jersey app at http://localhost:8080/api/...
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
jerseyAppUri, rc, false);
// Static content handler at http://localhost:8080/static/...
httpServer.getServerConfiguration().addHttpHandler(
new StaticHttpHandler("/home/user1/myapp/www/"), "/static");
// Dynamic content handler at http://localhost:8080/dynamic
httpServer.getServerConfiguration().addHttpHandler(
new HttpHandler() {
@Override
public void service(Request request, Response response) throws Exception {
response.getWriter().write("Hello World!");
}
}, "/dynamic");
httpServer.start();
Upvotes: 2