Show TOC

Example of an EJB Function, Exposed as a Mapping FunctionLocate this document in the navigation structure

Use

Here is an example showing how to create an EJB function that will concatenate two string and then use it within a mapping.

Use the defined procedure for creating and using an external EJB function within a mapping. For more information about this, see Creating an External Function, Exposing It as an EJB and Using It as a Mapping Function .

Process

You can create an example function that joins two strings following the details below:

  1. Create the EJB DC and name it. In this example, the name is concatejb .

  2. Create the EAR DC and name it. In this example, the name is concatear .

  3. Set the necessary dependencies as described in the procedure.

  4. Name the new stateless session bean ConcatFunction in the Java package com.sap.test

  5. Open the local business interface ( ConcatFunctionLocal ) of your EJB and let it extend the interfaces Function and SdoInvoker .

                      @Local
    public interface ConcatFunctionLocal extends Function, SdoInvoker{
    }
    
                   
  6. Write the implementation of the ConcatFunction bean, for example, use the following source code:

                      package com.sap.test;
    
    import javax.ejb.Stateless;
    import javax.xml.namespace.QName;
    
    import com.sap.glx.sdo.api.SdoRenamingHelper;
    import commonj.sdo.DataObject;
    import commonj.sdo.Type;
    
    @Stateless
    public class ConcatFunction implements ConcatFunctionLocal {
    
            private static final String PARAMETER1 = "parameter1";
            private static final String PARAMETER2 = "parameter2";
            private static final String RESULT = "result";
    
            private static final String NAME_PROPERTY_INPUT_PARAMETER1 = SdoRenamingHelper
                            .renameXsdElementToSdoProperty(new QName(PARAMETER1), false);
    
            private static final String NAME_PROPERTY_INPUT_PARAMETER2 = SdoRenamingHelper
                            .renameXsdElementToSdoProperty(new QName(PARAMETER2), false);
    
            private static final String NAME_PROPERTY_OUTPUT_RESULT = SdoRenamingHelper
                            .renameXsdElementToSdoProperty(new QName(RESULT), false);
    
    @Override
            public DataObject invokeSdo(DataObject inputDO,
                            InvocationContext invocationContext) {
    
                    // input
                    Type typeInput = inputDO.getType();
                    String parameter1 = inputDO.getString(typeInput
                                    .getProperty(NAME_PROPERTY_INPUT_PARAMETER1));
                    String parameter2 = inputDO.getString(typeInput
                                    .getProperty(NAME_PROPERTY_INPUT_PARAMETER2));
    
                    // function code
                    String result = parameter1.concat(parameter2);
    
                    // output
                    DataObject outputDO = invocationContext.createOutputDataObject();
                    outputDO.setString(outputDO.getType().getProperty(
                                    NAME_PROPERTY_OUTPUT_RESULT), result);
    
                    return outputDO;
            }
    }
    
                   
  7. Build the created EJB DC concatejb , and the EAR DC concatear .

  8. Deploy the EAR DC, concatear .

  9. Create a new EJB function that matches the names and types of function parameters in the Java implementation of the EJB. Enter the JNDI lookup name in the JNDI name field of the EJB function.

You can use this function for concatenating two strings within a mapping in the expression editor.