Implementing a sign-in transaction

To implement a sign-in operation, do the following:
  1. Define the sign-in operation in signInOp.xml is as follows:
    <signInOp.xml>
      <operation id="signInOp" context="signInCtx" implClass="com.ibm.btt.sample.operation.SignInOp">
          <refFormat name="csReplyFormat" refId="signInSendFmt" />
      </operation>
    </signInOp.xml>
    Note: The definition of refFormat supports Rich Client sample. The refFormat is a prerequisite and the name attribute must be csReplyFormat.
  2. Define the sign-in context in dsectxt.xml:
    <context id="signInCtx" type="op">
      <refKColl refId="signInData" />
    </context>
  3. Define the sign-in data element in dsedata.xml:
    <kColl id="signInData">
      <refData refId="userId" />
      <refData refId="pw" />
      <refData refId="locale" />
      <refData refId="dse_errorMessages" />
      <field id="dse_replyPage" />
      <field id="outcome" />
      <field id="errorCode" />
    </kColl>
  4. Define the sign-in data format in dsefmts.xml.
    • Format definition used for sign-in transaction in Rich Client.
      <fmtDef id="signInSendFmt">
        <record>
          <constant value="Tx01" />
          <fString dataName="dse_errorMessages" />
          <delim delimChar="#" />
        </record>
      </fmtDef>
      <fmtDef id="signInRecFmt">
        <record>
          <fString dataName="userId" />
          <delim delimChar="#" />
          <fString dataName="pw" />
          <delim delimChar="#" />
          <fString dataName="locale" />
        </record>
      </fmtDef>
    • Format definition used for signin transaction in Web 2.0 channel.
      <fmtDef id="SignInXMLFmt">
        <fXML dataName="signInData">
          <fString dataName="userId" />
          <fString dataName="pw" />
          <fString dataName="locale" />
        </fXML>
      	</fmtDef>
  5. Define the sign-in invoker in invoker.xml.
    <EJB id="logoninvoker" jNDI="ejb/com/ibm/btt/e2e/business/SignInBeanHome" 
      beanName="com.ibm.btt.e2e.business.SignInBean" method="execute">
      <parameters>
        <parameter id="ctx" type="com.ibm.btt.base.Context" />
      </parameters>
    </EJB>
  6. Implement the execute() method of the sign-in transaction.
    1. Implement the execute() method of the sign-in operation in <toolkit_root>/samples/BTTMultiChannleSample/SampleBusiness/com.ibm.btt.sample.operation.SignInOp.java.
      //Set the page to display for HTML channel
        getContext().setValueAt(HtmlConstants.REPLYPAGE, "signin.jsp");
        setValueAt("errorCode", HtmlException.OK);
        Context sessionCtx=getContext().getParent();
        if (signIn(getValueAt("userId").toString(), getValueAt("pw").toString(), getValueAt("locale").toString())) {
            Invoker invoker = (Invoker) InvokerFactory.getDefaultInvokerFactory().createInvoker("logoninvoker");
            getContext().unchain();
            Object[] params ={getContext()};
            Context invokerResult=(Context)invoker.execute(params);
            getContext().setKeyedCollection(invokerResult.getKeyedCollection());
            getContext().chainTo(sessionCtx);
            updateSessionContext(sessionCtx); 
      		 	     if("zh_CN".equals((String)getContext().getValueAt("locale"))){
      		 		       getParent().setValueAt("dse_locale",Locale.CHINA);	
      		 	     }else{
      		 		       getParent().setValueAt("dse_locale",Locale.US);	
      		 	     }
      			     getParent().setValueAt("locale",  getContext().getValueAt("locale"));
            getParent().setValueAt("locale",  getContext().getValueAt("locale"));
            getParent().setValueAt("userId", getContext().getValueAt("userId"));
        }    
    2. Implement the execute() method of sign-in invoker in <toolkit_root>/samples/BTTMultiChannleSample/BTTSampleEJB/com.ibm.btt.e2e.business.SignInBeanBean.java:
      public Context execute(Context ctx) throws BTTSAEException, Exception{
      		  ctx.setValueAt("outcome","succcess");
      		  return ctx;
      	}
      Note: Do not pass the entire context tree as an EJB parameter when using SAEJB because it might affect performance.