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

io.femo.http.drivers.DefaultEnvironment Maven / Gradle / Ivy

Go to download

An easy to use HTTP API, that supports synchronous and asynchronous execution of HTTP request. On android only asynchronous driver is supported. This library has been backported to jdk 7 to retain compatibility with android!

The newest version!
package io.femo.http.drivers;

import io.femo.http.Constants;
import io.femo.http.Environment;
import io.femo.http.HttpRequest;
import io.femo.http.HttpResponse;
import io.femo.http.middleware.EnvironmentReplacerMiddleware;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by felix on 7/2/16.
 */
public class DefaultEnvironment extends Environment {

    private Map> variables;

    public DefaultEnvironment () {
        this.variables = new HashMap<>();
        set("iso_time", new EnvironmentReplacerMiddleware.HttpSupplier() {
            @Override
            public String get(HttpRequest req, HttpResponse res) {
                return DateFormat.getTimeInstance().format(new Date());
            }
        });
        set("iso_date", new EnvironmentReplacerMiddleware.HttpSupplier() {
            @Override
            public String get(HttpRequest req, HttpResponse res) {
                return DateFormat.getDateInstance().format(new Date());
            }
        });
        set("iso_datetime", new EnvironmentReplacerMiddleware.HttpSupplier() {
            @Override
            public String get(HttpRequest req, HttpResponse res) {
                return DateFormat.getDateTimeInstance().format(new Date());
            }
        });
        set("server", "FeMo.IO HTTP Server " + Constants.VERSION);
    }

    @Override
    public boolean has(String variable) {
        return variables.containsKey(variable);
    }

    @Override
    public EnvironmentReplacerMiddleware.HttpSupplier get(String key) {
        return variables.get(key);
    }

    @Override
    public Environment set(String name, EnvironmentReplacerMiddleware.HttpSupplier value) {
        variables.put(name, value);
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy