Search in sources :

Example 1 with DefaultSessionContextProvider

use of org.polymap.core.runtime.session.DefaultSessionContextProvider in project polymap4-core by Polymap4.

the class WebDavServer method service.

public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
    Timer timer = new Timer();
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    DefaultSessionContextProvider contextProvider = FsPlugin.getDefault().sessionContextProvider;
    try {
        Request request = new io.milton.servlet.ServletRequest(req, servletRequest.getServletContext());
        Response response = new io.milton.servlet.ServletResponse(resp);
        threadRequest.set(request);
        threadResponse.set(response);
        Auth auth = request.getAuthorization();
        log.debug("Auth: " + auth);
        // map/create session context
        req.getSession(true);
        if (auth != null) {
            contextProvider.mapContext(auth.getUser(), true);
            log.debug("SessionContext: " + SessionContext.current());
        }
        httpManager.process(request, response);
        log.debug("Request: " + Request.Header.ACCEPT_ENCODING.code + ": " + request.getHeaders().get(Request.Header.ACCEPT_ENCODING.code) + " --> Response: " + Response.Header.CONTENT_ENCODING.code + ": " + response.getHeaders().get(Response.Header.CONTENT_ENCODING.code));
        log.debug("Response: " + response.getStatus());
    } finally {
        if (contextProvider.currentContext() != null) {
            contextProvider.unmapContext();
        }
        threadRequest.set(null);
        threadResponse.set(null);
        servletResponse.getOutputStream().flush();
        servletResponse.flushBuffer();
    }
    log.info("WebDAV request: " + timer.elapsedTime() + "ms");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Response(io.milton.http.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Timer(org.polymap.core.runtime.Timer) Auth(io.milton.http.Auth) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(io.milton.http.Request) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultSessionContextProvider(org.polymap.core.runtime.session.DefaultSessionContextProvider)

Example 2 with DefaultSessionContextProvider

use of org.polymap.core.runtime.session.DefaultSessionContextProvider in project polymap4-core by Polymap4.

the class FsPlugin method start.

public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    // init cacheDir
    cacheDir = new File(CorePlugin.getDataLocation(this), "cache");
    log.info("Cleaning cache dir: " + cacheDir.getAbsolutePath() + " ...");
    FileUtils.deleteDirectory(cacheDir);
    cacheDir.mkdirs();
    // register session context provider
    this.sessionContextProvider = new DefaultSessionContextProvider();
    SessionContext.addProvider(sessionContextProvider);
// // start WorkbenchState listener
// log.info( "Starting " + WorkbenchState.class.getSimpleName() + " listener ..." );
// WorkbenchState.startup();
}
Also used : DefaultSessionContextProvider(org.polymap.core.runtime.session.DefaultSessionContextProvider) File(java.io.File)

Aggregations

DefaultSessionContextProvider (org.polymap.core.runtime.session.DefaultSessionContextProvider)2 Auth (io.milton.http.Auth)1 Request (io.milton.http.Request)1 Response (io.milton.http.Response)1 File (java.io.File)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Timer (org.polymap.core.runtime.Timer)1