Search in sources :

Example 76 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class ResourceHandlers method combineProperties.

/* This method goes through the table list,  if there is confidential properties, will ensure that the masked value1 and value2 is the same.
    * And will copy this to the property value column to continue processing.
    * This method is called just before saving the properties.
    */
@Handler(id = "gf.combineProperties", input = { @HandlerInput(name = "tableList", type = java.util.List.class) }, output = { @HandlerOutput(name = "combined", type = java.util.List.class) })
public static void combineProperties(HandlerContext handlerCtx) {
    List<Map> tableList = (List) handlerCtx.getInputValue("tableList");
    List<Map> combined = new ArrayList();
    for (Map oneRow : tableList) {
        Map newRow = new HashMap();
        boolean isC = (Boolean) oneRow.get("isConfidential");
        String name = (String) oneRow.get("name");
        newRow.put("name", name);
        if (GuiUtil.isEmpty(name)) {
            continue;
        }
        if (isC) {
            String v1 = (String) oneRow.get("confValue");
            String v2 = (String) oneRow.get("confValue2");
            if (v1 == null) {
                if (v2 != null) {
                    GuiUtil.handleError(handlerCtx, "Confidential property '" + name + "' does not match.");
                    return;
                }
                continue;
            }
            if (!v1.equals(v2)) {
                GuiUtil.handleError(handlerCtx, "Confidential property '" + name + "' does not match.");
                return;
            }
            newRow.put("value", v1);
        } else {
            newRow.put("value", oneRow.get("value"));
        }
        combined.add(newRow);
    }
    handlerCtx.setOutputValue("combined", combined);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 77 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class RestUtilHandlers method callRestAndExtractMsgProps.

@Handler(id = "gf.callRestAndExtractMsgProps", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false), @HandlerInput(name = "method", type = String.class, defaultValue = "post"), @HandlerInput(name = "index", type = Integer.class, defaultValue = "0") }, output = { @HandlerOutput(name = "keyList", type = List.class), @HandlerOutput(name = "propsMap", type = Map.class), @HandlerOutput(name = "listEmpty", type = Boolean.class) })
public static void callRestAndExtractMsgProps(HandlerContext handlerCtx) {
    Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    String method = ((String) handlerCtx.getInputValue("method")).toLowerCase(GuiUtil.guiLocale);
    int index = (Integer) handlerCtx.getInputValue("index");
    try {
        Map responseMap = RestUtil.restRequest(endpoint, attrs, method, handlerCtx, false);
        ArrayList messages = (ArrayList) responseMap.get("messages");
        if (messages != null) {
            Map message = (Map) messages.get(index);
            List<Map<String, String>> props = (List<Map<String, String>>) message.get("properties");
            processProps(props, handlerCtx);
        }
    } catch (Exception ex) {
        GuiUtil.getLogger().severe("Error in callRestAndExtratResponse ; \nendpoint = " + endpoint + "attrs=" + attrs + "method=" + method);
    // we don't need to call GuiUtil.handleError() because thats taken care of in restRequest() when we pass in the handler.
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Handler(com.sun.jsftemplating.annotation.Handler)

Example 78 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class WebAppHandlers method ensureDefaultWebModule.

// This is called when user change the default web module of a VS.
// Need to ensure this VS is in the application-ref virtual server list. If not add it and restart the app for
// change to take into effect.  refer to issue#8671
@Handler(id = "gf.ensureDefaultWebModule", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "vsName", type = String.class, required = true), @HandlerInput(name = "instanceList", type = List.class, required = true) })
public static void ensureDefaultWebModule(HandlerContext handlerCtx) throws Exception {
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    String vsName = (String) handlerCtx.getInputValue("vsName");
    String encodedName = URLEncoder.encode(vsName, "UTF-8");
    List<String> instanceList = (List) handlerCtx.getInputValue("instanceList");
    Map vsAttrs = RestUtil.getAttributesMap(endpoint + "/" + encodedName);
    String webModule = (String) vsAttrs.get("defaultWebModule");
    if (GuiUtil.isEmpty(webModule))
        return;
    String appName = webModule;
    int index = webModule.indexOf("#");
    if (index != -1) {
        appName = webModule.substring(0, index);
    }
    String serverEndPoint = GuiUtil.getSessionValue("REST_URL") + "/servers/server/";
    for (String serverName : instanceList) {
        String encodedAppName = URLEncoder.encode(appName, "UTF-8");
        String encodedServerName = URLEncoder.encode(serverName, "UTF-8");
        String apprefEndpoint = serverEndPoint + encodedServerName + "/application-ref/" + encodedAppName;
        Map apprefAttrs = RestUtil.getAttributesMap(apprefEndpoint);
        String vsStr = (String) apprefAttrs.get("virtualServers");
        // Add to the vs list of this application-ref, then restart the app.
        if (GuiUtil.isEmpty(vsStr)) {
            vsStr = vsName;
        } else {
            List vsList = GuiUtil.parseStringList(vsStr, ",");
            if (vsList.contains(vsName)) {
                // the default web module app is already deployed to this vs, no action needed
                continue;
            } else {
                vsStr = vsStr + "," + vsName;
            }
        }
        apprefAttrs.put("virtualServers", vsStr);
        RestResponse response = RestUtil.sendUpdateRequest(apprefEndpoint, apprefAttrs, null, null, null);
        if (!response.isSuccess()) {
            GuiUtil.getLogger().severe("Update virtual server failed.  parent=" + apprefEndpoint + "; attrsMap =" + apprefAttrs);
            GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
            return;
        }
        List targets = new ArrayList();
        targets.add("domain");
        DeployUtil.reloadApplication(appName, targets, handlerCtx);
    }
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 79 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class WebAppHandlers method getNetworkListeners.

@Handler(id = "gf.getNetworkListeners", input = { @HandlerInput(name = "configName", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getNetworkListeners(HandlerContext handlerCtx) {
    String configName = (String) handlerCtx.getInputValue("configName");
    String endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/network-config/network-listeners/network-listener";
    try {
        List<Map> childElements = (List<Map>) RestUtil.buildChildEntityList(endpoint, "", null, null, "name");
        for (Map m : childElements) {
            String name = (String) m.get("protocol");
            if (name.equals(ServerTags.PORT_UNIF_PROTOCOL_NAME)) {
                m.put("protocol", ServerTags.SEC_ADMIN_LISTENER_PROTOCOL_NAME);
            }
        }
        handlerCtx.setOutputValue("result", childElements);
    } catch (Exception ex) {
        GuiUtil.handleException(handlerCtx, ex);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 80 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class WebAppHandlers method checkVsOfAppRef.

// This handler is called after user deleted one more more VS from the VS table.
// We need to go through all the application-ref to see if the VS specified still exist.  If it doesn't, we need to
// remove that from the vs list.
@Handler(id = "checkVsOfAppRef")
public static void checkVsOfAppRef(HandlerContext handlerCtx) throws Exception {
    String configUrl = GuiUtil.getSessionValue("REST_URL") + "/configs/config/";
    List configs = new ArrayList(RestUtil.getChildMap(configUrl).keySet());
    ArrayList vsList = new ArrayList();
    for (Object cfgName : configs) {
        String vsUrl = configUrl + cfgName + "/http-service/virtual-server";
        List vsNames = new ArrayList(RestUtil.getChildMap(vsUrl).keySet());
        for (Object str : vsNames) {
            if (!vsList.contains(str))
                vsList.add(str);
        }
    }
    List servers = new ArrayList(RestUtil.getChildMap(GuiUtil.getSessionValue("REST_URL") + "/servers/server").keySet());
    for (Object svrName : servers) {
        String serverEndpoint = GuiUtil.getSessionValue("REST_URL") + "/servers/server/" + svrName;
        List appRefs = new ArrayList(RestUtil.getChildMap(serverEndpoint + "/application-ref").keySet());
        for (Object appRef : appRefs) {
            String apprefEndpoint = serverEndpoint + "/application-ref/" + appRef;
            Map apprefAttrs = RestUtil.getAttributesMap(apprefEndpoint);
            String vsStr = (String) apprefAttrs.get("VirtualServers");
            List<String> lvsList = GuiUtil.parseStringList(vsStr, ",");
            boolean changed = false;
            for (String oneVs : lvsList) {
                if (!vsList.contains(oneVs)) {
                    changed = true;
                    continue;
                }
            }
            if (changed) {
                apprefAttrs.put("VirtualServers", vsStr);
                RestResponse response = RestUtil.sendUpdateRequest(apprefEndpoint, apprefAttrs, null, null, null);
                if (!response.isSuccess()) {
                    GuiUtil.getLogger().severe("Update virtual server failed.  parent=" + apprefEndpoint + "; attrsMap =" + apprefAttrs);
                    GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
                    return;
                }
            }
        }
    }
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)167 ArrayList (java.util.ArrayList)85 Map (java.util.Map)85 List (java.util.List)82 HashMap (java.util.HashMap)81 TreeMap (java.util.TreeMap)14 IOException (java.io.IOException)12 Date (java.util.Date)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)8 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)8 Image (com.sun.pkg.client.Image)8 ListIterator (java.util.ListIterator)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FacesContext (javax.faces.context.FacesContext)7 AttributeList (javax.management.AttributeList)7 RestResponse (org.glassfish.admingui.common.util.RestResponse)7 URL (java.net.URL)6 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)6 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5