Is it possible to outject an object from a custom filter using the ContextualHttpServletRequest class?
I have a value I receive on the query string of a web request. The value is a database ID which I use to construct the object associated with the ID. I want to outject the object to a seam session context. It appears to outject correctly, but when I attempt to inject the object in other seam classes, the object is always null.
Here is some code:
new ContextualHttpServletRequest(httpRequest) { @Override public void process() throws IOException { setClient(em, clientID); } }.run();
Later in the class, we have this method:
private void setClient(EntityManager em, int clientID) { Client client = em.find(com.blah.Client.class, clientID); Contexts contexts = new Contexts(); SessionContext sessionContext = (SessionContext)contexts.getSessionContext(); sessionContext.set("client", client); System.out.println("Client Session value set: " + ((Client)sessionContext.get("client")).getDescription()); }
Everything appears to work to this point. When I call the sessionConext.get(client
) it has my object.
Now, when another seam component attempts to use an injected client object, the client object is null:
@In private Client client;
I am fairly new to Seam and don't understand what is happening with the ContextualHttpServletRequest object. I am not sure how/why it has access to Seam contexts. Do my objects get removed from the context when the filter finishes executing?
If not, how can I inject the client object into my other seam components?
I learned that if you are using an EJB, you must configure an interceptor or place an Interceptor annotation on the EJB class:
@Interceptors(SeamInterceptor.class)
This fixed the problem (but exposed others :)