-
Notifications
You must be signed in to change notification settings - Fork 11
Writing a Payload Modifier
Pradeeban Kathiravelu edited this page Aug 24, 2018
·
1 revision
Follow the documentation for creating a Data Provider and create a new plugin project.
After creating a brand new project, $PROJECT_HOME/META-INF/MANIFEST.MF
must be modified to import packages that are
required by this project to develop a SPM. These packages are as follows
:
Import-Package: com.google.gson;version="2.1.0",
com.google.gson.annotations;version="2.1.0",
com.google.gson.internal;version="2.1.0",
com.google.gson.internal.bind;version="2.1.0",
com.google.gson.reflect;version="2.1.0",
com.google.gson.stream;version="2.1.0",
edu.emory.cci.bindaas.framework.api,
edu.emory.cci.bindaas.framework.event,
edu.emory.cci.bindaas.framework.event.listeners,
edu.emory.cci.bindaas.framework.model,
edu.emory.cci.bindaas.framework.provider.exception,
edu.emory.cci.bindaas.framework.util,
org.apache.commons.logging;version="1.1.1",
org.osgi.framework;version="1.3.0"
One more entry needs to be added in order to tell Bindaas where to pick-up spring configuration files :
Spring-Context: META-INF/spring/*.xml
public class LoggingQRM implements ISubmitPayloadModifier{
private Log log = LogFactory.getLog(getClass());
@Override
public JsonObject getDocumentation() {
return new JsonObject();
}
@Override
public void validate() throws ModifierException {
// not implemented
}
@Override
public String getDescriptiveName() {
return "Plugin for logging submit payload";
}
@Override
public InputStream transformPayload(InputStream data, SubmitEndpoint submitEndpoint, JsonObject modifierProperties, RequestContext requestContext) throws AbstractHttpCodeException {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyAndCloseInput(data, bos);
bos.close();
byte[] rawBytes = bos.toByteArray();
log.info("Payload of [" + rawBytes.length + "] intercepted");
return new ByteArrayInputStream(rawBytes);
} catch (IOException e) {
log.error("Error in handling payload",e);
throw new SubmitExecutionFailedException(getClass().getName(), 1);
}
}
@Override
public String transformPayload(String data, SubmitEndpoint submitEndpoint, JsonObject modifierProperties, RequestContext requestContext) throws AbstractHttpCodeException {
log.info("Data received from HTTP POST [" + data + "]");
return data;
}
}