Non JSF request. Injected hibernateSession is NULL.
mbilalf.mbilalf.gmail.com May 28, 2008 3:33 PMHi,
I am using jboss-seam-2.0.1.GA with JDK1.6 deployed in jboss-4.2.2.GA
I have a https client that interacts with a servlet in seam based application. It is a simple servlet that is deployed along with seam.
Servlet calls a stateless session bean for required data.The hibernateSession injected by seam is available in one request but is null in other.
I wonder if request to a servlet other than FacesServlet has access to the seam components. If one request has the injected session the other should also get it
Here is the code
Servlet
public class TransportServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(reqType.equals(REQUEST_TYPE_A)) { handleRequestA(); } else if(reqType.equals(REQUEST_TYPE_B)) { handleRequestB(); }
web.xml
... <filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping> ... <servlet> <servlet-name>TransportServlet</servlet-name> <servlet-class>com.server.https.TransportServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TransportServlet</servlet-name> <url-pattern>/servlet/TransportServlet</url-pattern> </servlet-mapping>
Component.xml
<persistence:hibernate-session-factory name="hibernateSessionFactory"/> <persistence:managed-hibernate-session name="hibernateSession" auto-create="true" session-factory-jndi-name="java:/sessionFactory" />
Handler method calls a stateless session bean to get the required data. Session bean uses a DBService class that does hibernate request to the database.
Hibernate session is injected into the DBService class.
DBService class
@Name("locationService") public class LocationService { @In(create=true,required=true) Session hibernateSession; public List getPrinters(String locationId){ ... hibernateSession.createQuery(hsqlStr); ... } public Location getLocation(String locationId){ ... hibernateSession.createQuery(hsqlStr); ... } }
hibernateSession is injected fine when getPrinters() is called. But is found null in case of getLocation()
Can anyone help me out here!!
thanks in advance.