Creating an invoker

To create an invoker, you create a resource bundle file to hold the information about the invoker, and then create the invoker itself.

The toolkit provides some invoker interfaces for you to implement when creating your own invokers. To create an invoker:

  1. Create a new class extending BeanInvokerImpl and implementing the one of the following interfaces:
    • BeanInvokerForJavaRequest, if you are creating an invoker for the Java(TM) request handler
    • BeanInvokerForStrutsAction, if you are creating an invoker for Struts actions
  2. Write the public Object createBeanInvokerProxy() throws DSEInvalidRequestException method to create the bean proxy. The following is an example of the method:
    public Object createBeanInvokerProxy () throw DSEInvalidRequestException {
    
        //** 1: Get EJBHome Object
        CustomerSampleHome home = (CustomerSampleHome)getHomeObject();
            
        //** 2: Create Bean Proxy.
        CustomerSampleBean bean = null;
        bean = (StartupServerAction)home.create(getSystemData());
        return bean;
    }
  3. Override the method public void parseRequestData(String requestData) throws DSEInvalidRequestException, DSEObjectNotFoundException. This method prepares the EJB invocation parameters. The following is an example of this method for Client/Server Messaging API:
    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());
            
            //***** 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);
              
        } catch (Exception e) {
            e.printStackTrace();
            throw new DSEInvalidRequestException(CSConstants.COMPID, "", e.getMessage());
        }
    }
  4. Override the method public Object executeEJB() throws Exception and write you code to access the Single Action EJB. The following is a sample of this method:
    public Object executeEJB() throws Exception{
        
        HelloWorld bean = (HelloWorld)getBeanInvokerProxy();
        
        //** call remote EJB method. The parameters can be retrieved from parameters hashtable
        String balance = bean.getBalance((String)getEjbParameter("accountID"),
    	  (String)getEjbParameter("userID"));
        
        return balance;
    }
  5. Write the method public Object processRespondData(Object ejbResult) throws DSEInvalidRequestException to process the response from the Single Action EJB. The parameterejbResult is what the public Object executeEJB() throws Exception method in the previous step returns. The following is a sample of this method:
    public Object processRespondData(Object ejbResult) throws
    DSEInvalidRequestException {
        Hashtable haResult = (Hashtable)ejbResult;
        BeanInvokerFormatter formatter = getFormatter();
        
    
        String responseString = "";
        responseString =
    formatter.formatString((String)haResult.get("TID"), null);
        responseString = formatter.addDelimiter(responseString, "#");
    
        return responseString;
    }