All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liveperson.faas.dto.FaaSInvocation Maven / Gradle / Ivy

Go to download

Functions client for invoking lambdas via the eventsource gateway (a.k.a Asgard)

There is a newer version: 1.2.3
Show newest version
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 "";
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy