import com.ibm.btt.services.jdbcjournalservice.Journal; import com.ibm.btt.services.jdbcjournalservice.JournalService; import com.ibm.btt.services.jdbcservicesinfra.DSESQLException;to
import com.ibm.btt.services.jdbc.DSESQLException; import com.ibm.btt.services.jdbc.journal.Journal; import com.ibm.btt.services.jdbc.journal.JournalService;
public Hashtable execute(BTTSystemData sysData, String uid) throws BTTSAEException, Exception, java.rmi.RemoteException;to
public String execute(String request) throws BTTSAEException, Exception, java.rmi.RemoteException;
In AccountStatementBean.java, remove import com.ibm.btt.services.jdbcjournalservice.*;, and modify:
public class AccountStatementBean extends StatelessSingleActionto
public class AccountStatementBean extends BaseJavaSampleBeanand remove super.ejbCreate() and super.ejbRemove();:
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData, String uid) throws BTTSAEException, Exception { initialize(sysData); Hashtable result = new Hashtable(); IndexedCollection ic = null; int i,j = 0; Context sessionCtx = null; //if instanceID != null , get sessionCtx if( getInstanceId() != null ) sessionCtx = Context.getContextByInstanceID(getInstanceId()); //if operationCtx has no parent and sessionCtx is not null, do chain if(getContext().getParent() == null && sessionCtx != null) getContext().chainTo(sessionCtx); //write input paramater into current context setValueAt("AccountNumber",uid); executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); result.put("TrxReplyCode",getContext().getValueAt("TrxReplyCode")); ic = (IndexedCollection)getContext().getElementAt("accountStatementDetails"); j = ic.size(); result.put("ICollSize",new Integer(j).toString()); for(i=0;i<j;i++{ result.put("OpnDate"+i,ic.getValueAt(i+".OpnDate")); result.put("OpnDescription"+i,ic.getValueAt(i+".OpnDescription")); result.put("OpnAmount"+i,ic.getValueAt(i+".OpnAmount")); result.put("OpnBalance"+i,ic.getValueAt(i+".OpnBalance")); } result.put("TrxErrorMessage",getContext().getValueAt("TrxErrorMessage")); close(); return result; }to:
public String execute(String request) throws BTTSAEException, Exception { initialize(); //extract data into operation context FormatElement fmt = new FormatElement(); fmt.setName(getName()+"ReqFmt"); fmt.unformat(request,getContext()); //genflow executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); //generate the response data fmt.setName(getName()+"RepFmt"); String result = fmt.format(getContext()); //release operation context close(); return result; }
Remove executeJournalHostRequestDataStep(),executeSendHostStep(),executeJournalHostReplyDataStep() and initialize() method.
In CustomerSearch.java:
Modifypublic Hashtable execute(BTTSystemData sysData, String uid) to public String execute(String request)
In CustomerSearchBean.java, remove import com.ibm.btt.services.jdbcjournalservice.*;, and modify:
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData, String uid) throws BTTSAEException,Exception { initialize(sysData); Hashtable result = new Hashtable(); IndexedCollection ic = null; int i,j = 0; Context sessionCtx = null; //if instanceID != null , get sessionCtx if( getInstanceId() != null ) sessionCtx = Context.getContextByInstanceID(getInstanceId()); //if operationCtx has no parent and sessionCtx is not null, do chain if(getContext().getParent() == null && sessionCtx != null) getContext().chainTo(sessionCtx); System.out.println(sessionCtx); //write input paramater into current context setValueAt("CustomerId",uid); executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); result.put("TrxReplyCode",getContext().getValueAt("TrxReplyCode")); result.put("CustomerName",getContext().getValueAt("CustomerName")); ic = (IndexedCollection)getContext().getElementAt("accounts"); j = ic.size(); result.put("ICollSize",new Integer(j).toString()); for(i=0;i<j;i++){ result.put("AccountNumber"+i,ic.getValueAt(i+".AccountNumber")); result.put("Type"+i,ic.getValueAt(i+".Type")); result.put("Name"+i,ic.getValueAt(i+".Name")); result.put("Balance"+i,ic.getValueAt(i+".Balance")); } result.put("TrxErrorMessage",getContext().getValueAt("TrxErrorMessage")); close(); return result; }
public String execute(String request) throws BTTSAEException,Exception { //initialize initialize(); //extract data into operation context FormatElement fmt = new FormatElement(); fmt.setName(getName()+"ReqFmt"); fmt.unformat(request,getContext()); //genflow executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); //generate the response data fmt.setName(getName()+"RepFmt"); String result = fmt.format(getContext()); //release operation context close(); return result; }
Remove executeJournalHostRequestDataStep(),executeSendHostStep(),executeJournalHostReplyDataStep() and initialize() method.
In Deposit.java, modify public Hashtable execute(BTTSystemData sysData, String uid,String date,String amount) to public Context execute(Context ctx), and add import com.ibm.btt.base.Context;
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData, String uid,String date,String amount) throws BTTSAEException, Exception { initialize(sysData); Hashtable result = new Hashtable(); IndexedCollection ic = null; int i,j = 0; Context sessionCtx = null; //if instanceID != null , get sessionCtx if( getInstanceId() != null ) sessionCtx = Context.getContextByInstanceID(getInstanceId()); //if operationCtx has no parent and sessionCtx is not null, do chain if(getContext().getParent() == null && sessionCtx != null) getContext().chainTo(sessionCtx); //write input paramater into current context //write input paramater into current context setValueAt("AccountNumber",uid); setValueAt("Date",date); setValueAt("Amount",amount); executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); result.put("TrxReplyCode",getContext().getValueAt("TrxReplyCode")); result.put("AccountBalance",getContext().getValueAt("AccountBalance")); result.put("TrxErrorMessage",getContext().getValueAt("TrxErrorMessage")); close(); return result; }
public Context execute(Context ctx) throws BTTSAEException, Exception { setContext(ctx); executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); //release context and clear operation setContext(null); close(); return ctx; }
Remove executeJournalHostRequestDataStep(),executeSendHostStep(),executeJournalHostReplyDataStep() and initialize() method.
In EndSessionAction.java, modify public Hashtable execute(BTTSystemData sysData) to public void execute().
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData) throws BTTSAEException,Exception { initialize(sysData); Hashtable result = new Hashtable(); Context sessionCtx ; //if instanceID != null if( getInstanceId() != null ){ // Removes the context and its parent (the parent session context) sessionCtx = Context.getContextByInstanceID(getInstanceId()); if(sessionCtx instanceof Context) sessionCtx.prune(); } close(); return result; }
public void execute() throws BTTSAEException,Exception { //get session context doSessionPropagation(); //if instanceID != null if( getInstanceId() != null ){ Context sessionCtx = Context.getContextByInstanceID(getInstanceId()); if(sessionCtx instanceof Context) sessionCtx.prune(); } }
Remove initialize(BTTSystemData sysData) method
In StartupJavaSessionAction.java, add import com.ibm.btt.base.Context;, and modify public Hashtable execute(BTTSystemData sysData,String wksContext,String wksParentContext) to public Context execute(Context ctx)
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData, String wksContext,String wksParentContext) throws BTTSAEException, Exception { initialize(sysData); Hashtable ha = new Hashtable(); try { setupSessionContext(); ha.put("InstanceID", getInstanceId()); close(); } catch (BTTSAEException ex) { ex.printStackTrace(); throw new DSEInvalidRequestException(DSEException.critical, getClass().getName(), "Not able to create the session context " + " in " + getName() + " \n" + ex.toString()); } return ha; }
public Context execute(Context ctx) throws BTTSAEException, Exception { try { //setup session context setupSessionContext(); //set the instance back to presentation layer ctx.setValueAt("instanceId",getInstanceId()); close(); return ctx; } catch (BTTSAEException ex) { ex.printStackTrace(); throw new DSEInvalidRequestException(DSEException.critical, getClass().getName(),"Not able to create the session context " + " in " + getName() + " \n" + ex.toString()); } }
Remove initialize(BTTSystemData sysData) method.
In Withdrawal.java, modify public Hashtable execute(BTTSystemData sysData, String uid,String date,String amount) to public String execute(String request)
public void ejbCreate() throws BTTSAEException { super.ejbCreate(); } public void ejbRemove() { super.ejbRemove(); }
public Hashtable execute(BTTSystemData sysData, String uid,String date,String amount) throws BTTSAEException, Exception { initialize(sysData); Hashtable result = new Hashtable(); IndexedCollection ic = null; int i,j = 0; Context sessionCtx = null; //if instanceID != null , get sessionCtx if( getInstanceId() != null ) sessionCtx = Context.getContextByInstanceID(getInstanceId()); //if operationCtx has no parent and sessionCtx is not null, do chain if(getContext().getParent() == null && sessionCtx != null) getContext().chainTo(sessionCtx); //write input paramater into current context setValueAt("AccountNumber",uid); setValueAt("Date",date); setValueAt("Amount",amount); executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); result.put("TrxReplyCode",getContext().getValueAt("TrxReplyCode")); result.put("AccountBalance",getContext().getValueAt("AccountBalance")); result.put("TrxErrorMessage",getContext().getValueAt("TrxErrorMessage")); close(); return result; }
public String execute(String request) throws BTTSAEException, Exception { //create context and chains to session ctx initialize(); //extract data into operation context FormatElement fmt = new FormatElement(); fmt.setName(getName()+"ReqFmt"); fmt.unformat(request,getContext()); //genflow executeJournalHostRequestDataStep(); executeSendHostStep(); executeJournalHostReplyDataStep(); //generate the response data fmt.setName(getName()+"RepFmt"); String result = fmt.format(getContext()); //release operation context close(); return result; }
Remove executeJournalHostRequestDataStep(),executeSendHostStep(),executeJournalHostReplyDataStep() and initialize() method.
package com.ibm.btt.samples.appl.business; import javax.resource.cci.Connection; import javax.resource.cci.ConnectionFactory; import javax.resource.cci.Interaction; import javax.resource.cci.InteractionSpec; import com.ibm.btt.formatter.client.FormatElement; import com.ibm.btt.samples.business.sna.lu0.DummyLu0ConnectionSpec; import com.ibm.btt.samples.business.sna.lu0.DummyLu0InteractionSpec; import com.ibm.btt.samples.business.sna.lu0.DummyLu0Record; import com.ibm.btt.server.bean.StatelessSingleAction; import com.ibm.btt.services.jdbc.journal.Journal; public class BaseJavaSampleBean extends StatelessSingleAction { /** * Writes a record into the journal. */ public void executeJournalHostRequestDataStep() throws Exception { Journal journal; setValueAt("HostBuff",((FormatElement) getFormat(getName()+"SendFmt")).format(getContext()));//$NON-NLS-2$//$NON-NLS-1$ // writes to the journal using the appropriate format journal = (Journal)getService("Journal"); assignService("test",journal); Journal j = (Journal) getService("test"); journal.addRecord(getContext(),"preSendJournalFmt");//$NON-NLS-1$ System.out.println("Journal HostRequest"+getName()+" ok"); return; } /** * Sends data to the host using a synchronous method * and waits for the reply. */ public void executeSendHostStep() throws Exception { javax.naming.Context initialContext = null; ConnectionFactory connectionFactory = null; if (initialContext == null) { initialContext = new javax.naming.InitialContext(); connectionFactory = (ConnectionFactory) initialContext.lookup("snalu0"); } // START TRANSACTION long begin = System.currentTimeMillis(); // For testing Component-managed authentication. DummyLu0ConnectionSpec lu0ConnectionSpec = new DummyLu0ConnectionSpec(); lu0ConnectionSpec.setUserName("sna"); lu0ConnectionSpec.setPassword("sna"); Connection connection = connectionFactory.getConnection(lu0ConnectionSpec); System.out.println("connection created..."); // Beginning of testing SYNC_SEND_RECEIVE Interaction interaction = connection.createInteraction(); System.out.println("interaction created..."); DummyLu0InteractionSpec interactionSpec = new DummyLu0InteractionSpec(); DummyLu0Record in = new DummyLu0Record(); DummyLu0Record out = new DummyLu0Record(); //getRequestData(); in.setData((String)getValueAt("HostBuff")); System.out.println("data to host: : "+in.getData()); interactionSpec.setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE); interactionSpec.setExecutionTimeout(10000); interaction.execute(interactionSpec, in, out); System.out.println("data from host: : "+out.getData()); interaction.close(); System.out.println("interaction closed..."); connection.close(); System.out.println("connection closed..."); com.ibm.btt.formatter.client.FormatElement fromHost = (com.ibm.btt.formatter.client.FormatElement) getFormat(getName()+"RecFmt"); //$NON-NLS-1$ fromHost.unformat(out.getData(),getContext()); System.out.println("SendHost ok"); } /** * Writes the data received from the host into the journal, * applying the appropriate format. */ public void executeJournalHostReplyDataStep() throws Exception { Journal journal; journal = (Journal)getService("Journal"); journal.addRecord(getContext(), "afterRecJournalFmt");//$NON-NLS-1$ System.out.println("JournalHostReply"+getName()+" ok"); return; } }
In JavaAccountStatementInvoker.java, modify:
import java.util.Map; import java.util.Hashtable; import javax.ejb.EJBHome; import com.ibm.btt.base.BTTSystemData; import com.ibm.btt.base.Context; import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidArgumentException; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.*; import com.ibm.btt.cs.servlet.CSConstants; import com.ibm.btt.samples.appl.business.*; /** * This class implements a business processor invoker. * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaWithdrawalInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ public Object executeEJB() throws Exception{ //** Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = (Withdrawal) getBeanInvokerProxy();; BTTSystemData sys = getSystemData(); Map result = bean.execute( getSystemData(), (String) getEjbParameter("AccountNumber"), (String)getEjbParameter("Date"), (String) getEjbParameter("Amount")); return result; } public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Get AccountNumber value Tokenizer tokens = getDelimitedTokenizer(requestData); BeanInvokerFormatter formatter = getFormatter(); String s = formatter.unformatString((String)tokens.nextToken("#"),null); getEjbParameters().put("AccountNumber", s); //** Get Date value java.util.Date aDate = formatter.unformatDate((String)tokens.nextToken("#"),true,"ymd",true,"/"); getEjbParameters().put("Date", aDate.toString()); //** Get Amount value //Double amt = (Double) formatter.unformatFloat((String)tokens.nextToken("#"),4,null); Float amt = (Float) formatter.unformatFloat((String)tokens.nextToken("#")); getEjbParameters().put("Amount", amt.toString()); //** Get BranchId value // s = formatter.unformatString((String)tokens.nextToken("#"),null); // getEjbParameters().put("BranchId", s); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Map haResult = (Map)ejbResult; BeanInvokerFormatter formatter = getFormatter(); String responseString = ""; try { responseString = formatter.formatString((String)haResult.get("TrxReplyCode"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("AccountBalance"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("TrxErrorMessage"), null); responseString = formatter.addDelimiter(responseString, "#"); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return responseString; } public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ //** 1: Get EJBHome Object WithdrawalHome home = (WithdrawalHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = null; try{ bean = (Withdrawal)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
To:
import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.samples.appl.business.AccountStatement; import com.ibm.btt.samples.appl.business.AccountStatementHome; public class JavaAccountStatementInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest { /** * @see com.ibm.btt.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { getEjbParameters().put("request",requestData); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.btt.cs.invoker.base.BeanInvokerImpl#executeEJB() */ public Object executeEJB() throws Exception { AccountStatement bean = (AccountStatement)getBeanInvokerProxy(); //call remote EJB mthod. The parameters can be retrieved from parameters hashtable String request = (String)getEjbParameter("request"); return bean.execute(request); } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { return ejbResult; } /** * @see com.ibm.btt.cs.invoker.base.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ try{ //Get EJBHome Object AccountStatementHome home = (AccountStatementHome)getHomeObject(); //Create Bean Proxy. If this bean is not existed in pool, then create new one manually AccountStatement bean = null; bean = (AccountStatement)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
In JavaCustomerSearchInvoker.java, modife:
import java.util.Hashtable; import com.ibm.btt.cs.invoker.base.*; import com.ibm.btt.base.*; import com.ibm.btt.clientserver.*; import com.ibm.btt.cs.servlet.*; import com.ibm.btt.samples.appl.business.*; /** * Java Invoker for CustomerSearch * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaCustomerSearchInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest { /** * @see com.ibm.btt.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Get CustomerId value Tokenizer tokens = getDelimitedTokenizer(requestData); BeanInvokerFormatter formatter = getFormatter(); String s = formatter.unformatString((String)tokens.nextToken("#"), ""); getEjbParameters().put("CustomerId", s); //** Code Generated end here } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } } /** * @see com.ibm.btt.cs.invoker.base.BeanInvokerImpl#executeEJB() */ public Object executeEJB() throws Exception { CustomerSearch bean = (CustomerSearch)getBeanInvokerProxy(); Hashtable result = new Hashtable(); String customerId = null; //call remote EJB mthod. The parameters can be retrieved from parameters hashtable //if the EJB method result is NOT hashtable, customer should put the result into Hashtable manually customerId = (String)getEjbParameter("CustomerId"); result = (Hashtable)bean.execute(getSystemData(),customerId); return result; } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Hashtable haResult = (Hashtable)ejbResult; BeanInvokerFormatter formatter = getFormatter(); int i,j; String responseString = ""; String formatAs = ""; try { responseString = formatter.formatString((String)haResult.get("TrxReplyCode"),formatAs); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("CustomerName"),formatAs); responseString = formatter.addDelimiter(responseString, "#"); j = Integer.parseInt((String)haResult.get("ICollSize")); for(i=0;i<j;i++){ responseString += formatter.formatString((String)haResult.get("AccountNumber"+i),formatAs); responseString = formatter.addDelimiter(responseString, "@"); responseString += formatter.formatString((String)haResult.get("Type"+i),formatAs); responseString = formatter.addDelimiter(responseString, "@"); responseString += formatter.formatString((String)haResult.get("Name"+i),formatAs); responseString = formatter.addDelimiter(responseString, "@"); responseString += formatter.formatString((String)haResult.get("Balance"+i),formatAs); responseString = formatter.addDelimiter(responseString, "@"); } responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("TrxErrorMessage"),formatAs); responseString = formatter.addDelimiter(responseString, "#"); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return responseString; } /** * @see com.ibm.btt.cs.invoker.base.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ //Get EJBHome Object CustomerSearchHome home = (CustomerSearchHome)getHomeObject(); //Create Bean Proxy. If this bean is not existed in pool, then create new one manually CustomerSearch bean = null; try{ bean = (CustomerSearch)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
To:
import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.samples.appl.business.CustomerSearch; import com.ibm.btt.samples.appl.business.CustomerSearchHome; public class JavaCustomerSearchInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest { /** * @see com.ibm.btt.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { getEjbParameters().put("request",requestData); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.btt.cs.invoker.base.BeanInvokerImpl#executeEJB() */ public Object executeEJB() throws Exception { CustomerSearch bean = (CustomerSearch)getBeanInvokerProxy(); //call remote EJB mthod. The parameters can be retrieved from parameters hashtable String request = (String)getEjbParameter("request"); //result = (Hashtable)bean.execute(getSystemData(),customerId); return bean.execute(request); } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { return ejbResult; } /** * @see com.ibm.btt.cs.invoker.base.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ try{ //Get EJBHome Object CustomerSearchHome home = (CustomerSearchHome)getHomeObject(); //Create Bean Proxy. If this bean is not existed in pool, then create new one manually CustomerSearch bean = null; bean = (CustomerSearch)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
import java.util.Map; import java.util.Hashtable; import javax.ejb.EJBHome; import com.ibm.btt.base.BTTSystemData; import com.ibm.btt.base.Context; import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidArgumentException; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.*; import com.ibm.btt.cs.servlet.CSConstants; import com.ibm.btt.samples.appl.business.*; /** * This class implements a business processor invoker. * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaDepositInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ public Object executeEJB() throws Exception{ //** Create Bean Proxy. If this bean is not existed in pool, then create new one manually Deposit bean = (Deposit) getBeanInvokerProxy();; BTTSystemData sys = getSystemData(); Map result = bean.execute( getSystemData(), (String) getEjbParameter("AccountNumber"), (String)getEjbParameter("Date"), (String) getEjbParameter("Amount") ); return result; } public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Get AccountNumber value Tokenizer tokens = getDelimitedTokenizer(requestData); BeanInvokerFormatter formatter = getFormatter(); String s = formatter.unformatString((String)tokens.nextToken("#"),null); getEjbParameters().put("AccountNumber", s); //** Get Date value java.util.Date aDate = formatter.unformatDate((String)tokens.nextToken("#"),true,"ymd",true,"/"); getEjbParameters().put("Date", aDate.toString()); //** Get Amount value Float amt = (Float) formatter.unformatFloat((String)tokens.nextToken("#")); getEjbParameters().put("Amount", amt.toString()); //** Get BranchId value // s = formatter.unformatString((String)tokens.nextToken("#"),null); // getEjbParameters().put("BranchId", s); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Map haResult = (Map)ejbResult; BeanInvokerFormatter formatter = getFormatter(); String responseString = ""; try { responseString = formatter.formatString((String)haResult.get("TrxReplyCode"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("AccountBalance"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("TrxErrorMessage"), null); responseString = formatter.addDelimiter(responseString, "#"); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return responseString; } public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ //** 1: Get EJBHome Object DepositHome home = (DepositHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually Deposit bean = null; try{ bean = (Deposit)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
To:
import com.ibm.btt.base.Constants; import com.ibm.btt.base.Context; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.formatter.client.FormatElement; import com.ibm.btt.samples.appl.business.Deposit; import com.ibm.btt.samples.appl.business.DepositHome; public class JavaDepositInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ public Object executeEJB() throws Exception{ //** Create Bean Proxy. If this bean is not existed in pool, then create new one manually Deposit bean = (Deposit) getBeanInvokerProxy();; Context ctx = (Context) getEjbParameter("Context"); ctx = bean.execute(ctx); return ctx; } public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //create operation context Context ctx = new Context("depositServerCtx",false); ctx.chainTo(Context.getContextByInstanceID(getSystemData().getInstanceId())); //unformat value into context FormatElement fmt = new FormatElement(); fmt.setName("depositReqFmt"); fmt.unformat(requestData, ctx); getEjbParameters().put("Context", ctx); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { String responseString = ""; try { FormatElement fmt = new FormatElement(); fmt.setName("depositRepFmt"); responseString = fmt.format((Context) ejbResult); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } return responseString; } public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ try{ //** 1: Get EJBHome Object DepositHome home = (DepositHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually Deposit bean = null; bean = (Deposit)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
In JavaEndSessionInvoker.java, modify:
import java.util.Hashtable; import com.ibm.btt.cs.invoker.base.*; import com.ibm.btt.cs.invoker.cache.*; import com.ibm.btt.base.*; import com.ibm.btt.clientserver.*; import com.ibm.btt.cs.servlet.*; import com.ibm.btt.samples.appl.business.*; import com.ibm.btt.sm.CSSessionHandler; /** * Java Invoker for EndSession * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaEndSessionInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest { /** * Constructor for JavaEndSessionInvoker. */ public JavaEndSessionInvoker() { super(); } /** * @see com.ibm.btt.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Code Generated end here } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } } /** * Removes the session entry in the * sessions table and the context hierarchy created in the initial * operation (EndSessionServerOp). * The operation context of this operation will be automatically * removed by the client server mechanism during the close() process. */ public Object executeEJB() throws Exception { String sessionCtxName = "javaSessionCtx"; // // Removes the session entry in the sessions table CSSessionHandler.removeSession(getSystemData().getSessionId()); // Context.removeSession((String)getEjbParameter(Constants.SESSION_ID));//$NON-NLS-1$ // // Removes the context and its parent (the parent session context) // Context.getContextNamed(sessionCtxName).prune(); EndSessionAction bean = (EndSessionAction)getBeanInvokerProxy(); Hashtable result = bean.execute(getSystemData()); //** Clear Bean Invoker Proxy Cache BeanInvokerProxyCache proxyCache = (BeanInvokerProxyCache)InvokerCacheFactory.getInstance(InvokerCacheFactory.BEAN_INVOKER_PROXY_CACHE); proxyCache.clear((String)getEjbParameter(Constants.SESSION_ID)); return result; } /** * @see com.ibm.btt.cs.invoker.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ //** 1: Get EJBHome Object EndSessionActionHome home = (EndSessionActionHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually EndSessionAction bean = null; try{ bean = (EndSessionAction)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Hashtable haResult = (Hashtable)ejbResult; String responseString = ""; return responseString; } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
To:
import javax.servlet.http.HttpSession; import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.cs.invoker.cache.BeanInvokerProxyCache; import com.ibm.btt.cs.invoker.cache.InvokerCacheFactory; import com.ibm.btt.samples.appl.business.EndSessionAction; import com.ibm.btt.samples.appl.business.EndSessionActionHome; import com.ibm.btt.sm.CSSessionHandler; public class JavaEndSessionInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest { private Object sessionObject = null; /** * Constructor for JavaEndSessionInvoker. */ public JavaEndSessionInvoker() { super(); } /** * @see com.ibm.btt.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { } /** * Removes the session entry in the * sessions table and the context hierarchy created in the initial * operation (EndSessionServerOp). * The operation context of this operation will be automatically * removed by the client server mechanism during the close() process. */ public Object executeEJB() throws Exception { // Removes the session entry in the sessions table EndSessionAction bean = (EndSessionAction)getBeanInvokerProxy(); bean.execute(); CSSessionHandler.removeSession((HttpSession)sessionObject); //** Clear Bean Invoker Proxy Cache BeanInvokerProxyCache proxyCache = (BeanInvokerProxyCache)InvokerCacheFactory.getInstance(InvokerCacheFactory.BEAN_INVOKER_PROXY_CACHE); proxyCache.clear(getSystemData().getSessionId()); return null; } /** * @see com.ibm.btt.cs.invoker.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ try{ //** 1: Get EJBHome Object EndSessionActionHome home = (EndSessionActionHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually EndSessionAction bean = null; bean = (EndSessionAction)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { return ""; } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { this.sessionObject = sessionObject; } }
In JavaStartupSessionInvoker.java, modify:
import java.util.Hashtable; import javax.ejb.EJBHome; import javax.ejb.EJBObject; import javax.servlet.http.HttpSession; import com.ibm.btt.base.BTTSystemData; import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerFormatter; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.cs.invoker.base.Tokenizer; import com.ibm.btt.cs.servlet.CSConstants; import com.ibm.btt.samples.appl.business.StartupJavaSessionAction; import com.ibm.btt.samples.appl.business.StartupJavaSessionActionHome; import com.ibm.btt.sm.CSSessionHandler; import com.ibm.btt.sm.SessionEntry; /** * Java Invoker for StartupSession * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaStartupSessionInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ private Object sessionObject = null; /** * Customer should add thier code here to access the Single Action EJB */ public Object executeEJB() throws Exception{ Hashtable result = new Hashtable(); //** 1: Call back-end server to logon first StartupJavaSessionAction bean = (StartupJavaSessionAction) getBeanInvokerProxy();; BTTSystemData sys = getSystemData(); result = bean.execute(getSystemData(),"", ""); // Get instnace ID String instanceID = (String)result.get("InstanceID"); //** 2: If logon success, Create Session Entry, and then put into SessionManagement SessionEntry se = new SessionEntry(); se.setSessionId(getSystemData().getSessionId()); se.setHttpSession((HttpSession)sessionObject); se.setCurrentContext(instanceID); se.setIpAddress((String)getEjbParameter("ipAddress")); se.setTID((String)getEjbParameter("TID")); CSSessionHandler.addSession(se); result = getEjbParameters(); return result; } /** * @see com.ibm.dse.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Code Generated begin here //***** Parse RequestData according to the format definition in client side /*-- <fmtDef id="startupReqFmt"> <record> <fString dataName="TID"/> <delim delimChar="#"/> <fString dataName="WKSContext"/> <delim delimChar="#"/> <fString dataName="WKSParentContext"/> <delim delimChar="#"/> <fString dataName="permanentConnectionForEvents"/> <delim delimChar="#"/> <fString dataName="ipAddress"/> <delim delimChar="#"/> <fInteger dataName="eventsPort"/> <delim delimChar="#"/> </record> </fmtDef> --*/ //** Get TID value Tokenizer tokens = getDelimitedTokenizer(requestData); BeanInvokerFormatter formatter = getFormatter(); String s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("TID", s); //** Get WKSContext value s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("WKSContext", s); //** Get WKSParentContext value s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("WKSParentContext", s); //** permanentConnectionForEvents s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("permanentConnectionForEvents", s); //** Get ipAddress value s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("ipAddress", s); //** Get eventsPort value s = formatter.unformatString((String)tokens.nextToken("#"), null); getEjbParameters().put("eventsPort", s); //** Code Generated end here } catch (Exception e) { e.printStackTrace(); throw new DSEInvalidRequestException(CSConstants.COMPID, "", e.getMessage()); } } /** * @see com.ibm.dse.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Hashtable haResult = (Hashtable)ejbResult; BeanInvokerFormatter formatter = getFormatter(); String responseString = ""; try { responseString = formatter.formatString((String)haResult.get("TID"), null); responseString += formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("WKSContext"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("WKSParentContext"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("permanentConnectionForEvents"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("ipAddress"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("eventsPort"), null); responseString = formatter.addDelimiter(responseString, "#"); } catch (Exception e) { e.printStackTrace(); } return responseString; } /** * @see com.ibm.btt.cs.invoker.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException { //** 1: Get EJBHome Object StartupJavaSessionActionHome home = (StartupJavaSessionActionHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually StartupJavaSessionAction bean = null; try{ bean = (StartupJavaSessionAction)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } /* (non-Javadoc) * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { this.sessionObject = sessionObject; } }
To:
import java.io.Serializable; import javax.servlet.http.HttpSession; import com.ibm.btt.base.Constants; import com.ibm.btt.base.Context; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.cs.servlet.CSConstants; import com.ibm.btt.formatter.client.FormatElement; import com.ibm.btt.samples.appl.business.StartupJavaSessionAction; import com.ibm.btt.samples.appl.business.StartupJavaSessionActionHome; import com.ibm.btt.sm.CSSessionHandler; import com.ibm.btt.sm.SessionEntry; public class JavaStartupSessionInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ private Object sessionObject = null; /** * Customer should add thier code here to access the Single Action EJB */ public Object executeEJB() throws Exception{ //** 1: Call back-end server to logon first StartupJavaSessionAction bean = (StartupJavaSessionAction) getBeanInvokerProxy(); Context ctx = bean.execute((Context) getEjbParameters().get("context")); //** 2: If logon success, Create Session Entry, and then put into SessionManagement SessionEntry se = new SessionEntry(); se.setCurrentContext((Serializable) ctx.getValueAt("instanceId")); se.setIpAddress((String)ctx.getValueAt("ipAddress")); se.setTID((String)ctx.getValueAt("TID")); CSSessionHandler.addSession((HttpSession)sessionObject,se); return ctx; } /** * @see com.ibm.dse.cs.BeanInvoker#parseRequestData(Object) */ public void parseRequestData(String request) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //create logon local context Context ctx = new Context("startupServerCtx",false); //extract data into local context FormatElement fmt = new FormatElement(); fmt.setName("startupReqFmt"); fmt.unformat(request,ctx); getEjbParameters().put("context",ctx); } catch (Exception e) { throw new DSEInvalidRequestException(CSConstants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.dse.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { String responseString = ""; try { FormatElement fmt = new FormatElement(); fmt.setName("startupReqFmt"); responseString = fmt.format((Context) ejbResult); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } return responseString; } /** * @see com.ibm.btt.cs.invoker.BeanInvoker#createBeanInvokerProxy() */ public Object createBeanInvokerProxy() throws DSEInvalidRequestException { try{ //** 1: Get EJBHome Object StartupJavaSessionActionHome home = (StartupJavaSessionActionHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually StartupJavaSessionAction bean = null; bean = (StartupJavaSessionAction)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /* (non-Javadoc) * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { this.sessionObject = sessionObject; } }
In JavaWithdrawalInvoker.java, modify:
import java.util.Map; import java.util.Hashtable; import javax.ejb.EJBHome; import com.ibm.btt.base.BTTSystemData; import com.ibm.btt.base.Context; import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidArgumentException; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.*; import com.ibm.btt.cs.servlet.CSConstants; import com.ibm.btt.samples.appl.business.*; /** * This class implements a business processor invoker. * @copyright(c) Copyright IBM Corporation 2004,2005 */ public class JavaWithdrawalInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ public Object executeEJB() throws Exception{ //** Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = (Withdrawal) getBeanInvokerProxy();; BTTSystemData sys = getSystemData(); Map result = bean.execute( getSystemData(), (String) getEjbParameter("AccountNumber"), (String)getEjbParameter("Date"), (String) getEjbParameter("Amount")); return result; } public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { //** Prepare session data in ejb parameters getEjbParameters().put(Constants.SESSION_ID, getSystemData().getSessionId()); getEjbParameters().put(CSConstants.DATAAPPLICATIONIDKEY, getSystemData().getSubsessionId()); //** Get AccountNumber value Tokenizer tokens = getDelimitedTokenizer(requestData); BeanInvokerFormatter formatter = getFormatter(); String s = formatter.unformatString((String)tokens.nextToken("#"),null); getEjbParameters().put("AccountNumber", s); //** Get Date value java.util.Date aDate = formatter.unformatDate((String)tokens.nextToken("#"),true,"ymd",true,"/"); getEjbParameters().put("Date", aDate.toString()); //** Get Amount value //Double amt = (Double) formatter.unformatFloat((String)tokens.nextToken("#"),4,null); Float amt = (Float) formatter.unformatFloat((String)tokens.nextToken("#")); getEjbParameters().put("Amount", amt.toString()); //** Get BranchId value // s = formatter.unformatString((String)tokens.nextToken("#"),null); // getEjbParameters().put("BranchId", s); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { Map haResult = (Map)ejbResult; BeanInvokerFormatter formatter = getFormatter(); String responseString = ""; try { responseString = formatter.formatString((String)haResult.get("TrxReplyCode"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("AccountBalance"), null); responseString = formatter.addDelimiter(responseString, "#"); responseString += formatter.formatString((String)haResult.get("TrxErrorMessage"), null); responseString = formatter.addDelimiter(responseString, "#"); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return responseString; } public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ //** 1: Get EJBHome Object WithdrawalHome home = (WithdrawalHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = null; try{ bean = (Withdrawal)home.create(); } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage()); } return bean; } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }
To:
import com.ibm.btt.base.Constants; import com.ibm.btt.base.DSEInvalidRequestException; import com.ibm.btt.base.DSEObjectNotFoundException; import com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest; import com.ibm.btt.cs.invoker.base.BeanInvokerImpl; import com.ibm.btt.samples.appl.business.Withdrawal; import com.ibm.btt.samples.appl.business.WithdrawalHome; public class JavaWithdrawalInvoker extends BeanInvokerImpl implements BeanInvokerForJavaRequest{ public Object executeEJB() throws Exception{ //** Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = (Withdrawal) getBeanInvokerProxy();; String result = bean.execute((String) getEjbParameter("request")); return result; } public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException { try { getEjbParameters().put("request",requestData); } catch (Exception e) { throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /** * @see com.ibm.btt.cs.BeanInvoker#processRespondData() */ public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException { return ejbResult; } public Object createBeanInvokerProxy() throws DSEInvalidRequestException{ try{ //** 1: Get EJBHome Object WithdrawalHome home = (WithdrawalHome)getHomeObject(); //** 2: Create Bean Proxy. If this bean is not existed in pool, then create new one manually Withdrawal bean = null; bean = (Withdrawal)home.create(); return bean; } catch(Exception e){ throw new DSEInvalidRequestException(Constants.COMPID, "", e.getMessage(), e); } } /* * @see com.ibm.btt.cs.invoker.base.BeanInvokerForJavaRequest#setSessionObject(java.lang.Object) */ public void setSessionObject(Object sessionObject) throws DSEInvalidRequestException, DSEObjectNotFoundException { } }