Add the Extension Class and Methods
You must add an Extension class containing a method which implements each REST service.
About this task
callout_statement
section which
imports a bean and invokes a method on that bean.Procedure
- Go to the projects/project_name/src/main/com/matrixx/rsgateway/configuration directory.
- Create a java file. Its name must match the file that is invoked in the callout_statement field of the REST definition.
-
Declare the class.
Extend
JsonStubs
and annotate it with an@Service
tag. Pass to the@Service
tag the unqualified name of the class as thevalue
argument:import com.matrixx.datacontainer.rest.JsonStubs; import org.springframework.stereotype.Service; @Service(value = "DemoServices ") public class DemoServices extends JsonStubs { ... }
-
Declare the package as
com.matrixx.rsgateway.configuration
. Import the classes representing the request and response MDCs.If you defined aSearchTerm
in the REST definition, import the class of thatSearchTerm
as well:import com.matrixx.datacontainer.mdc.DemoRequestSubscriberQuery; import com.matrixx.datacontainer.mdc.DemoResponseSubscriberQuery; import com.matrixx.datacontainer.rest.RestQueryTerm;
-
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()); ... }
-
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) { ... } ... }
-
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"); } ... }