void AmB2BCallerSession::createCalleeSession() {
  AmB2BCalleeSession* callee_session = newCalleeSession();  
  if (NULL == callee_session) 
    return;

  AmSipDialog& callee_dlg = callee_session->dlg;

  other_id = AmSession::getNewId();
  
  callee_dlg.local_tag    = other_id;
  callee_dlg.callid       = AmSession::getNewId() + "@" + AmConfig::LocalIP;

  callee_dlg.local_party  = dlg.remote_party;
  callee_dlg.remote_party = dlg.local_party;
  callee_dlg.remote_uri   = dlg.local_uri;

  if (AmConfig::LogSessions) {
    INFO("Starting B2B callee session %s app %s\n",
	 callee_session->getLocalTag().c_str(), invite_req.cmd.c_str());
  }

  MONITORING_LOG5(other_id.c_str(), 
		  "app",  invite_req.cmd.c_str(),
		  "dir",  "out",
		  "from", callee_dlg.local_party.c_str(),
		  "to",   callee_dlg.remote_party.c_str(),
		  "ruri", callee_dlg.remote_uri.c_str());

  callee_session->start();

  AmSessionContainer* sess_cont = AmSessionContainer::instance();
  sess_cont->addSession(other_id,callee_session);
}
string AmSessionContainer::startSessionUAC(const AmSipRequest& req, string& app_name, AmArg* session_params) {

  auto_ptr<AmSession> session;
  try {
    session.reset(createSession(req, app_name, session_params));
    if(session.get() != 0) {
      session->dlg->initFromLocalRequest(req);
      session->setCallgroup(req.from_tag);
      
      switch(addSession(req.from_tag,session.get())) {
	
      case AmSessionContainer::Inserted:
	// successful case
	break;
	
      case AmSessionContainer::ShutDown:
	throw AmSession::Exception(AmConfig::ShutdownModeErrCode,
				   AmConfig::ShutdownModeErrReason);
	
      case AmSessionContainer::AlreadyExist:
	throw AmSession::Exception(482,
				   SIP_REPLY_LOOP_DETECTED);
	
      default:
	ERROR("adding session to session container\n");
	throw string(SIP_REPLY_SERVER_INTERNAL_ERROR);
      }
      
      MONITORING_LOG5(req.from_tag, 
		      "app", app_name.c_str(),
		      "dir", "out",
		      "from", req.from.c_str(),
		      "to", req.to.c_str(),
		      "ruri", req.r_uri.c_str());
      
      if (int err = session->sendInvite(req.hdrs)) {
	ERROR("INVITE could not be sent: error code = %d.\n", err);
	AmEventDispatcher::instance()->delEventQueue(req.from_tag);
	MONITORING_MARK_FINISHED(req.from_tag.c_str());
	return "";
      }
      
      if (AmConfig::LogSessions) {      
	INFO("Starting UAC session %s app %s\n",
	     req.from_tag.c_str(), app_name.c_str());
      }
      try {
	session->start();
      } catch (...) {
	AmEventDispatcher::instance()->delEventQueue(req.from_tag);
	throw;
      }
    }
  } 
  catch(const AmSession::Exception& e){
    ERROR("%i %s\n",e.code,e.reason.c_str());
    return "";
  }
  catch(const string& err){
    ERROR("startSession: %s\n",err.c_str());
    return "";
  }
  catch(...){
    ERROR("unexpected exception\n");
    return "";
  }

  session.release();
  return req.from_tag;
}