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

io.yawp.servlet.FixturesServlet Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.servlet;

import io.yawp.commons.http.ExceptionResponse;
import io.yawp.driver.api.Driver;
import io.yawp.driver.api.DriverFactory;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class FixturesServlet extends EndpointServlet {

    private static final long serialVersionUID = -7833278558858095857L;

    @Override
    public void init(ServletConfig config) throws ServletException {
        setWithHooks(false);
        super.init(config);
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (!enableFixtures()) {
            response(resp, new ExceptionResponse(403));
            return;
        }

        super.service(req, resp);
    }

    private boolean enableFixtures() {
        Driver driver = DriverFactory.getDriver();

        if (!driver.environment().isProduction()) {
            return true;
        }

        return driver.environment().isAdmin();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy