Make your own free website on Tripod.com

Example of Java Service

public static Map createContactMech(DispatchContext ctx, Map context) {
    Map result = new HashMap();
    GenericDelegator delegator = ctx.getDelegator();
    Security security = ctx.getSecurity();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Timestamp now = UtilDateTime.nowTimestamp();
    . . .
    String contactMechTypeId = (String) context.get("contactMechTypeId");
    . . .
    result.put("contactMechId", newCmId.toString());
    result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
    return result;
}

A Java service is much like an event where it is a static method, with 2 arguments:

  • DispatchContext ctx

    the runtime dispatcher context containing the necessary information to process services (reference to a delegator object, a dispatcher object and others attributes)

  • Map context

    Map containing the Input parameters for the service

Results are returned in a Map as well.