Add the Extension Class and Methods

You must add an Extension class containing a method which implements each REST service.

About this task

The REST service definition has a callout_statement section which imports a bean and invokes a method on that bean.

Procedure

  1. Go to the projects/project_name/src/main/com/matrixx/rsgateway/configuration directory.
  2. Create a java file. Its name must match the file that is invoked in the callout_statement field of the REST definition.
  3. Declare the class.
    Extend JsonStubs and annotate it with an @Service tag. Pass to the @Service tag the unqualified name of the class as the value argument:
    import com.matrixx.datacontainer.rest.JsonStubs;
    import org.springframework.stereotype.Service;
     
    @Service(value = "DemoServices ")
    public class DemoServices extends JsonStubs {
        ...
    }
  4. Declare the package as com.matrixx.rsgateway.configuration. Import the classes representing the request and response MDCs.
    If you defined a SearchTerm in the REST definition, import the class of that SearchTerm as well:
    import com.matrixx.datacontainer.mdc.DemoRequestSubscriberQuery;
    import com.matrixx.datacontainer.mdc.DemoResponseSubscriberQuery;
    import com.matrixx.datacontainer.rest.RestQueryTerm;
  5. Declare a static logger member variable and include the relevant libraries:
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
     
    import static com.matrixx.platform.LogUtils.ENTER;
    import static com.matrixx.platform.LogUtils.ERROR;
    import static com.matrixx.platform.LogUtils.LEAVE;
     
    @Service(value = "DemoServices ")
    public class DemoServices extends JsonStubs {
        private final Logger m_logger = LoggerFactory.getLogger(getClass());
        ...
     
    }
  6. For each REST definition, define a method whose header matches that invoked in the callout_statement field:
    @Service(value = "DemoServices ")
    public class DemoServices extends JsonStubs {
     
        public int demoQuerySubscriber(RestQueryTerm searchTerm,
            DemoRequestSubscriberQuery input,
            DemoResponseSubscriberQuery output)
        {
            ...
        }
        ...
     
    }
  7. Implement the behavior of the REST definition by using the generated Java classes.
    The following example wraps a call of the existing service_subscriber_query without implementing any additional logic:
    package com.matrixx.rsgateway.configuration;
     
    import com.matrixx.datacontainer.mdc.DemoRequestSubscriberQuery;
    import com.matrixx.datacontainer.mdc.DemoResponseSubscriberQuery;
    import com.matrixx.datacontainer.mdc.SubscriberQuery;
    import com.matrixx.datacontainer.mdc.SubscriberResponse;
    import com.matrixx.datacontainer.rest.JsonStubs;
    import com.matrixx.datacontainer.rest.RestQueryTerm;
    import com.matrixx.platform.MatrixxContext;
     
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
     
    import static com.matrixx.platform.LogUtils.ENTER;
    import static com.matrixx.platform.LogUtils.ERROR;
    import static com.matrixx.platform.LogUtils.LEAVE;
     
    import org.springframework.stereotype.Service;
     
    @Service(value = "DemoServices")
    public class DemoServices extends JsonStubs {
        private final Logger m_logger = LoggerFactory.getLogger(getClass());
        public int demoQuerySubscriber(RestQueryTerm searchTerm,
                DemoRequestSubscriberQuery input,
                DemoResponseSubscriberQuery output)
        {
            int rc = 0;
            ENTER(m_logger, "demoQuerySubscriber");
            try {
     
                String route = getRoute(MatrixxContext.getRequest());
                SubscriberQuery subQry = new SubscriberQuery();
                SubscriberResponse subResp = new SubscriberResponse();
                service_subscriber_query(route, null, searchTerm, subQry, subResp);
                copyOnto(output, subResp);
            }
            catch (Exception ex) {
                rc = -1;
                String m = ex.getMessage();
                output.setResult(-1L);
                output.setResultText(m);
                ERROR(m_logger, "demoQuerySubscriber: " + m, ex);
            }
            return LEAVE(rc, m_logger, "demoQuerySubscriber");
        }
     
        ...
     
    }