Using the Adapter SDK in Mashery Local with Single Processor

To use the Adapter SDK in Mashery Local with a single processor, follow the steps below:

Procedure

  1. Create a new Maven Project in Eclipse. Go to File > New > Maven Project.



  2. Add dependencies to the project. In Eclipse, go to Project Explorer > pom.xml > Dependencies.

    Here is the list of dependencies:

  3. Create new Java Class. In Eclipse, go to Project > New > Class.
    In the package com.example.masherylocal.CustomAdapter, create the following class CustomProcessor.

    This is the reference code:
    package com.example.masherylocal.CustomAdapter;
     
    import com.mashery.http.server.HTTPServerRequest;
    import com.mashery.http.server.HTTPServerResponse;
    import com.mashery.trafficmanager.event.listener.TrafficEventListener;
    import com.mashery.trafficmanager.event.model.TrafficEvent;
    import com.mashery.trafficmanager.event.model.TrafficEventCategory;
    import com.mashery.trafficmanager.event.model.TrafficEventType;
    import com.mashery.trafficmanager.event.processor.model.ProcessorEvent;
    import com.mashery.trafficmanager.model.core.APICall;
    import com.mashery.trafficmanager.model.core.ApplicationRequest;
    import com.mashery.trafficmanager.model.core.TrafficManagerResponse;
    import com.mashery.trafficmanager.processor.ProcessorBean;
     
    @ProcessorBean(enabled=true, name="com.example.masherylocal.CustomAdapter.CustomProcessor", immediate=true)
    public class CustomProcessor implements TrafficEventListener {
     
        public void handleEvent(TrafficEvent event) {
            TrafficEventType eventType = event.getType();
            if (eventType.getCategory() != TrafficEventCategory.PROCESSOR)
                return;
            ProcessorEvent processorEvent = (ProcessorEvent) event;
            APICall apiCall = processorEvent.getCallContext();
             
            if (eventType.getName().contentEquals("Pre-Process Event")) {
                ApplicationRequest appRequest = apiCall.getRequest();
                HTTPServerRequest httpRequest = appRequest.getHTTPRequest();
            } else if (eventType.getName().contentEquals("Post-Process Event")) {
                TrafficManagerResponse tmResp = apiCall.getResponse();
                HTTPServerResponse httpResp = tmResp.getHTTPResponse();
                httpResp.getHeaders().add("CustomAdapter.CustomProcessor::handleEvent", "Post-Process Event");
            }
        }
    }
  4. Build the project in the folder, for example, /home/beta/work_diysdk/CustomAdapter/:
    mvn package
  5. Use a simple zip command to package the project in the folder, for example, /home/beta/work_diysdk/CustomAdapter/target/:
    zip CustomAdapter-1.0.zip CustomAdapter-1.0.jar
  6. Unload the zipped package using Mashery Local Cluster Manager.
  7. Apply the Custom Processor on the Endpoint using Mashery SaaS Control Center.