3 Replies Latest reply on Apr 28, 2014 8:21 AM by Marek Novotny

    ClassCastException thrown on Component.getInstance(GateAction.class, true)

    Lokesh Paunikar Newbie

      I am new in Seam. I am using Rest services and in one of my rest service I am trying to get Instance by Component like,


      GateActionIntf gateAction = (GateActionIntf) Component.getInstance(GateActionImpl.class, true);

       

      So with this I got error java.lang.IllegalStateException: No application context active

      then to resolve this I call Lifecycle.beginCall() and Lifecycle.endCall() methods as below,

      Lifecycle.beginCall(); 
      GateActionIntf gateAction = (GateActionIntf) Component.getInstance(GateActionImpl.class, true); 
      Lifecycle.endCall();

       

      Where GateActionIntf is an Interface and GateActionImpl is seam component which implements GateActionIntf. But now I am getting ClassCastException.

      Note : In my web service project I don't have any component.xml and seams based configuration, I have just added jboss-seam jar

      Is that possible to get instance like that, without any component.xml and seams configuration? Again just highlighting I am getting the Instance but while type casting throws ClassCastException. Any help or comments would be appreciated.

       

       

      GateActionIntf ==>


      public interface GateActionIntf

      {

        Response performThisOperation( Operation operation, final DataModel dataModel );

      }

       

       

      GateActionImpl ==>

       

      @Name(value = "getAction")

      @AutoCreate

      @Scope(ScopeType.STATELESS)

      public class GateActionImpl

        implements GateActionIntf

      {

        public Response performThisOperation( Operation operation, DataModel dataModel )

        {

          return new Response( operation.getOperationId(), false );

        }

       

      }