Search in sources :

Example 11 with HttpCallContext

use of com.peterphi.std.guice.web.HttpCallContext in project stdlib by petergeneric.

the class GuiceServlet method service.

@Override
protected final void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    final HttpCallContext ctx = HttpCallContext.set(req, resp, getServletContext());
    try {
        // Share the call id to log4j
        Tracing.start(ctx.getLogId(), ctx.isVerbose());
        // If necessary set up Guice
        if (!ready.get()) {
            if (registry == null)
                registry = new GuiceRegistry(new GuiceBuilder().withRole(new WebappGuiceRole(getServletConfig())));
            registry.register(this, true);
        }
        // Make the call
        doService(req, resp);
    } finally {
        HttpCallContext.clear();
        Tracing.clear();
    }
}
Also used : HttpCallContext(com.peterphi.std.guice.web.HttpCallContext) WebappGuiceRole(com.peterphi.std.guice.web.rest.setup.WebappGuiceRole) GuiceBuilder(com.peterphi.std.guice.apploader.impl.GuiceBuilder) GuiceRegistry(com.peterphi.std.guice.apploader.impl.GuiceRegistry)

Example 12 with HttpCallContext

use of com.peterphi.std.guice.web.HttpCallContext in project stdlib by petergeneric.

the class SessionScoping method seed.

public <T> void seed(Key<T> key, T instance) {
    final String name = key.toString();
    final HttpCallContext ctx = HttpCallContext.get();
    final HttpSession session = ctx.getRequest().getSession();
    synchronized (session) {
        if (exists(key))
            throw new IllegalArgumentException("Cannot seed Session scope with instance for " + key + ": Session scope already has an instance of this key!");
        if (instance != null)
            session.setAttribute(name, instance);
        else
            session.setAttribute(name, NullObject.INSTANCE);
    }
}
Also used : HttpCallContext(com.peterphi.std.guice.web.HttpCallContext) HttpSession(javax.servlet.http.HttpSession)

Aggregations

HttpCallContext (com.peterphi.std.guice.web.HttpCallContext)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpSession (javax.servlet.http.HttpSession)4 Provider (com.google.inject.Provider)2 Timer (com.codahale.metrics.Timer)1 GuiceBuilder (com.peterphi.std.guice.apploader.impl.GuiceBuilder)1 GuiceRegistry (com.peterphi.std.guice.apploader.impl.GuiceRegistry)1 WebappGuiceRole (com.peterphi.std.guice.web.rest.setup.WebappGuiceRole)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 Cookie (javax.servlet.http.Cookie)1 NotFoundException (javax.ws.rs.NotFoundException)1 ServletContainerDispatcher (org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher)1