My last message had not a good format. Here my next try.

I implemented a servlet filter that is registered via http-whiteboard:

@Component(scope = ServiceScope.PROTOTYPE)
@HttpWhiteboardFilterPattern("/*")
public class LogSessionFilter implements Filter
{
    private static AtomicInteger m_Counter = new AtomicInteger();

    @Override
    public void doFilter(final ServletRequest request, final
    ServletResponse response, final FilterChain chain)
    throws IOException, ServletException
    {
        HttpServletRequest httpRequest = (HttpServletRequest)request;

        HttpSession session = httpRequest.getSession(true);
        m_Log.info("Session from servlet filter: "
        + session.getId()
        + ", invocationCounter = "
        + session.getAttribute("invocationCounter"));
        session.setAttribute("invocationCounter",
        Integer.toString(m_Counter.incrementAndGet()));

        chain.doFilter(httpRequest, response);
    }
}

And a jax-rs Resource (deployed with cxf) that logs the session information
from the http request

public class RestResourceHello
{
    private Logger m_Log = LoggerFactory.getLogger(getClass());

    @Context
    private HttpServletRequest m_Request;

    @GET
    @Path("hello")
    @Produces("text/plain")
    public String sayHello()
    {
        HttpSession session = m_Request.getSession(true);
        m_Log.info("Session for hello resource: "
        + session.getId()
        + ", invocationCounter = "
        + session.getAttribute("invocationCounter"));

        return "hello";
    }
}

I get the following output when accessing the rest service

09:42:46.919 INFO [qtp1047761018-751] Session for hello resource:
node0g3wjy0l2u36812cqxe9tohdpz3, invocationCounter = null
09:42:46.993 INFO [qtp1047761018-752] Session from servlet filter:
node0g3wjy0l2u36812cqxe9tohdpz3, invocationCounter = 19
09:43:12.572 INFO [qtp1047761018-758] Session for hello resource:
node0g3wjy0l2u36812cqxe9tohdpz3, invocationCounter = null
09:43:12.655 INFO [qtp1047761018-599] Session from servlet filter:
node0g3wjy0l2u36812cqxe9tohdpz3, invocationCounter = 20

It seems that jax-rs resource has not access to the http session
attributes., but the session id is the same. Is this a bug?

I deployed the sample on Karaf 4.3.6 and used cxf 3.4.5

Regards

Richard

Reply via email to