1 Reply Latest reply on Feb 23, 2005 5:44 AM by Sunil Arora

    connect to session bean using visibroker for c++builder in j

    t 12 Newbie

      hello:
      I have written a c++ client using visibroker for c++builder to connet to the stateless sesion bean in jboss4.0. I using IOR that is printed out in the jboos initialize.the code is :
      ///////////////////////////////
      void InitCorba()
      {
      CORBA::ORB_var orb;
      try
      {
      if(orb!=NULL)
      return;
      result=NULL;

      orb = CORBA::ORB_init();
      CORBA::String_var ior = GetIORFromFile("");
      CORBA::Object_var obj = orb->string_to_object(ior);
      if (CORBA::is_nil(obj) )
      {
      MessageBox(GetActiveWindow(),"read IOR error","error",MB_OK);
      orb=NULL;
      return ;
      }

      CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj.in());
      if(CORBA::is_nil(nc))
      {
      orb=NULL;
      return ;
      }

      CosNaming::Name name;
      try
      {
      //for jboss
      name.length(1);
      name[0].id = CORBA::string_dup("facadeEJB");
      name[0].kind = CORBA::string_dup("");

      obj = nc->resolve(name);
      }
      catch (const CORBA::Exception& e)
      {
      }

      ::com::nari::resmaster::system::facade::facadeHome_var homeObject ;
      try
      {
      homeObject = ::com::nari::resmaster::system::facade::facadeHome::_narrow(obj);
      if ( CORBA::is_nil(homeObject))
      {
      orb=NULL;
      return ;
      }
      }
      catch (const CORBA::Exception& e)
      {
      AnsiString str;
      str= AnsiString(e._name() );
      MessageBox(GetActiveWindow(),str.c_str(),"??",MB_OK);
      orb=NULL;
      return ;
      }

      try
      {
      facadeRemotePtr = homeObject->create();
      }
      catch (const CORBA::Exception& e)
      {
      AnsiString str;
      str= AnsiString(e._name() );
      MessageBox(GetActiveWindow(),str.c_str(),"err",MB_OK);
      orb=NULL;
      return ;
      }
      }
      catch(const CORBA::Exception& e)
      {
      AnsiString str;
      str= AnsiString(e._name() );
      MessageBox(GetActiveWindow(),"err","info",MB_OK);
      orb=NULL;
      return ;
      }
      }

      //read IOR file
      CORBA::String_var GetIORFromFile(AnsiString iorFilePath)
      {
      int i;
      int iFilehnd ;
      int iFilelen;
      int iByteread;
      char *pzBuffer;
      AnsiString iordirectory;
      char SystemPath[MAX_PATH];
      AnsiString systemdir;
      try
      {

      iordirectory=getenv("NARIRES_HOME");
      if(iordirectory!="")
      {
      iFilehnd = FileOpen(iordirectory+"\\nameservice.ior",fmOpenRead);
      }

      if (iFilehnd == -1 || iordirectory=="")
      {
      memset(SystemPath,0x00,sizeof(SystemPath));
      GetSystemDirectory(SystemPath,MAX_PATH); systemdir = SystemPath;
      iFilehnd = FileOpen(systemdir+"\\nameservice.ior",fmOpenRead);
      if (iFilehnd == -1)
      {
      systemdir=GetCurrentDir();
      iFilehnd = FileOpen(systemdir+"\\nameservice.ior",fmOpenRead);
      if (iFilehnd == -1)
      {
      ShowMessage("nameservice.ior' not exists?");
      return "";
      }
      }
      };

      iFilelen = FileSeek(iFilehnd,0,2);
      FileSeek(iFilehnd,0,0);
      pzBuffer = new char[iFilelen+1];
      memset(pzBuffer,0x00,iFilelen+1);
      iByteread = FileRead(iFilehnd,pzBuffer,iFilelen);
      for(i=0;i<2;i++)
      {
      if(pzBuffer[strlen(pzBuffer)-1]==0x0a || pzBuffer[strlen(pzBuffer)-1]==0x0d)
      pzBuffer[strlen(pzBuffer)-1]='\0';
      }
      FileClose(iFilehnd);
      }
      catch (...)
      {
      ShowMessage("'nameservice.ior' error");
      return "";
      }
      CORBA::String_var ior = pzBuffer;
      return ior;
      }
      ////////////////////////////////////////////////
      ejb code:
      /////////////////
      package com.nari.resmaster.system.facade;

      import javax.ejb.*;

      public class facadeBean implements SessionBean
      {
      SessionContext sessionContext;

      public void ejbCreate() throws CreateException
      {
      }

      public void ejbRemove()
      {
      }

      public void ejbActivate()
      {
      }

      public void ejbPassivate()
      {
      }

      public void setSessionContext(SessionContext sessionContext)
      {
      this.sessionContext = sessionContext;
      }

      public String test()
      {
      System.out.print("client requect");
      return "Jboss_test";
      }

      public String processBuiz(String buizName, String xmlParam)
      {
      return "ok" +buizName+xmlParam;
      }
      }
      ///////////////////
      jboss.xml
      ////////////////

      <enterprise-beans>

      <ejb-name>facadeEJB</ejb-name>
      <jndi-name>facadeEJB</jndi-name>
      <invoker-bindings>

      <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>

      </invoker-bindings>

      </enterprise-beans>

      /////////////////////////////
      the result is:
      I have sucessfully connnect to the facadeEJB. when I call the method test(),Jboss's console print out "client requect",but the c++builder client get the err of "stack overflow" why?
      anyone could help me? thanks.