com.liveperson.faas.dto.FaaSInvocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functions-client Show documentation
Show all versions of functions-client Show documentation
Functions client for invoking lambdas via the eventsource gateway (a.k.a Asgard)
package com.liveperson.faas.dto;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Data Transfer Object of the invocation
*
* @author arotaru
*/
public class FaaSInvocation {
private long timestamp;
private List headers;
private T payload;
public FaaSInvocation() {
this.timestamp = System.currentTimeMillis();
this.headers = new ArrayList();
}
public FaaSInvocation(Map headerMap, T payload) {
this.timestamp = System.currentTimeMillis();
this.headers = new ArrayList();
setHeaders(headerMap);
this.payload = payload;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public List getHeaders() {
return headers;
}
public void setHeaders(Map headerMap) {
if (headerMap == null)
return;
for (Map.Entry entry : headerMap.entrySet()) {
this.headers.add(new FaaSKeyValue(entry.getKey(), entry.getValue()));
}
}
public T getPayload() {
return payload;
}
public void setPayload(T payload) {
this.payload = payload;
}
@Override
public String toString(){
ObjectMapper objectMapper = new ObjectMapper();
try{
String json = objectMapper.writeValueAsString(this);
return json.replaceAll("\"payload\":null}$", "\"payload\":{}}");
} catch(Exception e){
return "";
}
}
}