2 Replies Latest reply on May 30, 2008 2:10 PM by Muhammad Bilal Fazal

    Non JSF request. Injected hibernateSession is NULL.

    Muhammad Bilal  Fazal Newbie

      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


      public class TransportServlet extends HttpServlet {
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           if(reqType.equals(REQUEST_TYPE_A)) {
           else if(reqType.equals(REQUEST_TYPE_B)) {


              <filter-name>Seam Filter</filter-name>
              <filter-name>Seam Filter</filter-name>


      <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
          <persistence:managed-hibernate-session name="hibernateSession" 

      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

      public class LocationService {
          @In(create=true,required=true) Session hibernateSession;
          public List getPrinters(String locationId){
          public Location getLocation(String locationId){

      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.

        • 1. Re: Non JSF request. Injected hibernateSession is NULL.
          Nicklas Karlsson Master

          Tried ContextualHttpServletRequest and accessing the components through Components?

          • 2. Re: Non JSF request. Injected hibernateSession is NULL.
            Muhammad Bilal  Fazal Newbie


            I tried it, but got another problem. The data is not being read from the request now.
            My servlet with  ContextualHttpServletRequest is like this

            public void doPost( final HttpServletRequest request, final HttpServletResponse response) throws ServletException{
            new ContextualHttpServletRequest() {
               public void process() {
                 HttpSession session = request.getSession();
                 ServerResponse res = null;
                 String reqType = request.getHeader(ServerDefinitions.REQUEST_TYPE);
                 System.out.println("----------- reqType: "+reqType);
                 String contentLen = request.getHeader(ServerDefinitions.CONTENT_LENGTH);
                 System.out.println("Request content Length :" + contentLen);
                 String sessID = request.getHeader(ServerDefinitions.SESSION_ID);
                 is = request.getInputStream();
                 byte[] by = new byte[BUFFER_SIZE];
                 int noOfBytes = 0;
                 StringBuffer buf = new StringBuffer();
                 bout = new ByteArrayOutputStream();
                 while ((noOfBytes = is.read(by)) != -1) {
                     bout.write(by, 0 , noOfBytes);
                     by = bout.toByteArray();
                     buf.append(new String(by,     
                     bout = new ByteArrayOutputStream();
                     by = new byte[BUFFER_SIZE];
                 String data = buf.toString();
                 System.out.println("$$$ RequestData :- "+data);
                 if (reqType.equals(RequestTypes.A)) {
                 }else if(reqType.equals(RequestTypes.B)) {

            Another thought. Does SeamContext initialize when we request a simple servlet ?

            Best Regards,
            thanks for your time.