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

io.dropwizard.jersey.sessions.Flash Maven / Gradle / Ivy

package io.dropwizard.jersey.sessions;

import jakarta.servlet.http.HttpSession;

import java.util.Optional;

public class Flash {
    private static final String ATTRIBUTE = "flash";
    private final HttpSession session;
    private final T value;

    @SuppressWarnings("unchecked")
    Flash(HttpSession session) {
        this.session = session;
        this.value = (T) session.getAttribute(ATTRIBUTE);
        if (this.value != null) {
            session.removeAttribute(ATTRIBUTE);
        }
    }

    public Optional get() {
        return Optional.ofNullable(value);
    }

    public void set(T value) {
        session.setAttribute(ATTRIBUTE, value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy