Using the Adapter SDK in Mashery Local with Single Processor
Procedure
-
Create a new Maven Project in Eclipse. Go to
File > New > Maven Project.
-
Add dependencies to the project. In Eclipse, go to
Project Explorer > pom.xml > Dependencies.
-
Create new Java Class. In Eclipse, go to
Project > New > Class.
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"); } } }
-
Build the project in the folder, for example,
/home/beta/work_diysdk/CustomAdapter/:
mvn package
-
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
- Unload the zipped package using a Jenkins build job.
- Apply the Custom Processor on the Endpoint using the TIBCO Cloud Mashery dashboard.
Copyright © Cloud Software Group, Inc. All rights reserved.