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

web.throttling.index.jsp Maven / Gradle / Ivy

There is a newer version: 4.7.219
Show newest version


<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.mediators.throttle.admin.stub.types.ThrottlePolicy" %>
<%@ page import="org.wso2.carbon.mediators.throttle.admin.stub.types.InternalData" %>
<%@ page import="org.wso2.carbon.mediator.throttle.client.ThrottleClient" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.text.MessageFormat" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>



<%
    String service = request.getParameter("serviceName");
    String operation = request.getParameter("opName");
    String param = "", header;

    if (request.getParameter("backURL") != null) {
        session.setAttribute("backURL", request.getParameter("backURL"));
    }

    String BUNDLE = "org.wso2.carbon.mediator.throttle.ui.i18n.Resources";
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());

    boolean global = false;
    boolean operationLevel = false;
    if (service == null) {
        global = true;
        header = bundle.getString("throttling.headertext");
    } else {
        if (operation == null) {
            param = "serviceName=" + service;
            header = MessageFormat.format(bundle.getString("throttling.configuration.global"), service);
        } else {
            operationLevel = true;
            param = "serviceName=" + service + "&opName=" + operation;
            header = MessageFormat.format(bundle.getString("throttling.configuration.operation"), service, operation);
        }
    }
    /**
     * Get the current policy configuration from the admin service to
     * show when index.jsp loads.
     */

    //Obtaining the client-side ConfigurationContext instance.
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    //Server URL which is defined in the server.xml
    String serverBackendURL = CarbonUIUtil.getServerURL(config.getServletContext(),
            session);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ThrottlePolicy policy;

    try {
        ThrottleClient client = new ThrottleClient(cookie,
                serverBackendURL, configContext, request.getLocale());
        policy = client.getExistingConfigs(request, global, operationLevel);

    } catch (Exception e) {
        CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, e);
%>

<%
        return;
    }

    String maxAccesses = "";
    if (policy.getMaxConcurrentAccesses() != 0) {
        maxAccesses = String.valueOf(policy.getMaxConcurrentAccesses());
    }

    String firstOpt = bundle.getString("throttling.no"), secondOpt = bundle.getString("throttling.yes"), htmlString = "", style = "display: none;", disableFields;
    int newRows = 0;

    //If the module is engaged, show the option as "Yes"
    if (policy.getEngaged()) {
        firstOpt = bundle.getString("throttling.yes");
        secondOpt = bundle.getString("throttling.no");
        style = "display: inline;";
    }

    //If the incoming internal configs are not empty, load them
    if (policy.getMaxConcurrentAccesses() != 0 ||
            policy.getInternalConfigs() != null && policy.getInternalConfigs()[0] != null) {

        InternalData[] data = policy.getInternalConfigs();
        if (data != null) {
            newRows = data.length;

            String opt1, opt2, opt3, opt4, opt5;
            int f2, f3, f4;
            for (int i = 0; i < data.length; i++) {
                opt1 = "IP";
                opt2 = "DOMAIN";
                opt3 = "Control";
                opt4 = "Deny";
                opt5 = "Allow";
                disableFields = "";
                if (data[i] != null) {
                    if (data[i].getAccessLevel() == 1) {
                        opt3 = "Deny";
                        opt4 = "Control";
                        disableFields = "disabled=\'true\'";
                    } else if (data[i].getAccessLevel() == 2) {
                        opt3 = "Allow";
                        opt5 = "Control";
                        disableFields = "disabled=\'true\'";
                    }
                    if (data[i].getRangeType().equals("DOMAIN")) {
                        opt1 = "DOMAIN";
                        opt2 = "IP";
                    }
                    f2 = data[i].getMaxRequestCount();
                    f3 = data[i].getUnitTime();
                    f4 = data[i].getProhibitTimePeriod();
                    htmlString += "\n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            " + bundle.getString("throttling.delete") + "\n" +
                            "        \n";
                } else {
                    newRows--;
                }
            }
        }
    }
%>







<%= header%>

 

    

<%= htmlString%>
" onclick="submitForm();" class="button"/> " onclick="resetForm();" class="button"/> " onclick="loadDefault();" class="button"/> " onclick="clearAll();" class="button"/> " class="button"/>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy