2014-01-15 6 views
1

내가 그리 즐 봉사 얻을 수 정적 콘텐츠그리즐리 + 정적 내용 + 서블릿 필터

나는 명명 된 서블릿

을 필터링하는 서블릿 필터를 만들 수 있습니다하지만 서블릿 필터가 정적을 필터링 할 수 없습니다 함유량. 어떻게해야합니까?

WebappContext webappContext = new WebappContext("grizzly web context", ""); 
FilterRegistration authFilterReg = webappContext.addFilter("Authentication Filter", org.package.AuthenticationFilter.class); 

// If I create a ServletContainer, I can add the filter to it like this: 
// authFilterReg.addMappingForServletNames(EnumSet.allOf(DispatcherType.class), "servletName"); 

HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(BASE_URI); 
webappContext.deploy(httpServer); 

// This works, but the content does not go through the authentication filter above 
httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler(absolutePath), "/static"); 

답변

1

WebappContext (웹 응용 프로그램)의 일환으로 등록 된 ServletFilters 만이 WebappContext (웹 응용 프로그램)에 관련 요청에 대해 실행됩니다 여기

내가 지금까지 가지고있는 코드입니다.

그래서 내가 본 해결책 중 하나는 WebappContext에 DefaultServlet [1]을 등록하고 StaticHttpHandler 대신 사용하는 것입니다. 뭔가 같은 :

ArraySet<File> set = new ArraySet<File>(File.class); 
set.add(new File(absolutePath)); 
ServletRegistration defaultServletReg = webappContext.addServlet("DefaultServlet", new DefaultServlet(set) {}); 
defaultServletReg.addMapping("/static"); 

[1] https://github.com/GrizzlyNIO/grizzly-mirror/blob/2.3.x/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/DefaultServlet.java

+0

당신이 내 회색 질문에서 봐 주시기 바랍니다 수 : http://stackoverflow.com/questions/35123194/jersey-2-render-swagger-static- 내용 제대로 -없이 - 후행 슬래시 – DerekY