Class ResourceHandler

  • All Implemented Interfaces:
    HttpServer.Handler

    public class ResourceHandler
    extends java.lang.Object
    implements HttpServer.Handler
    Handler implementation which implements dynamic resource provision. HTTP HEAD and GET methods are implemented.
    Since:
    7 Jan 2009
    Author:
    Mark Taylor
    • Constructor Detail

      • ResourceHandler

        public ResourceHandler​(HttpServer server,
                               java.lang.String basePath)
        Constructor.
        Parameters:
        server - HTTP server
        basePath - path from server root beneath which all resources provided by this handler will appear
    • Method Detail

      • addResource

        public java.net.URL addResource​(java.lang.String name,
                                        ServerResource resource)
        Adds a resource to this server.
        Parameters:
        name - resource name, for cosmetic purposes only
        resource - resource to make available
        Returns:
        URL at which resource can be found
      • removeResource

        public void removeResource​(java.net.URL url)
        Removes a resource from this server.
        Parameters:
        url - URL returned by a previous addResource call
      • serveRequest

        public HttpServer.Response serveRequest​(HttpServer.Request request)
        Description copied from interface: HttpServer.Handler
        Provides a response to an HTTP request. A handler which does not recognise the URL should simply return null; in this case there may be another handler which is able to serve the request. If the URL appears to be in this handler's domain but the request cannot be served for some reason, an error response should be returned.
        Specified by:
        serveRequest in interface HttpServer.Handler
        Parameters:
        request - HTTP request
        Returns:
        response response to request, or null