All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.ubibi.jettyboot.framework.rest.ClassPathResourceHandler Maven / Gradle / Ivy

There is a newer version: 1.0.50
Show newest version
package cn.ubibi.jettyboot.framework.rest;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;

public class ClassPathResourceHandler extends ResourceHandler {


    public ClassPathResourceHandler(){
        this("public");
    }


    public ClassPathResourceHandler(String pathPrefix)  {
        super();

        pathPrefix = (pathPrefix.charAt(0) == '/' ? pathPrefix.substring(1) : pathPrefix);

        URL xx = this.getClass().getClassLoader().getResource(pathPrefix);
        System.out.println("ClassPathResourceHandler:  " + xx);
        this.setBaseResource(Resource.newResource(xx));
        this.setCacheControl("max-age=31536000,public");
    }


    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
        super.handle(target,baseRequest,request,response);
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy