Search in sources :

Example 6 with Handler

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

the class PayaraRestApiHandlers method getVirtualServersAttributes.

/**
 * Gets the context roots of all deployed applications on the domain.
 * This is outputted as List<Map<String, String>> for usage within the Virtual-Servers page.
 * @param handlerCtx
 */
@Handler(id = "py.getVirtualServersAttributes", input = { @HandlerInput(name = "configName", type = String.class, required = true), @HandlerInput(name = "sessionScopeRestURL", type = String.class, required = true), @HandlerInput(name = "parentEndpoint", type = String.class, required = true), @HandlerInput(name = "childType", type = String.class, required = true), @HandlerInput(name = "skipList", type = List.class, required = false), @HandlerInput(name = "includeList", type = List.class, required = false), @HandlerInput(name = "id", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getVirtualServersAttributes(HandlerContext handlerCtx) {
    String parentEndpoint = (String) handlerCtx.getInputValue("parentEndpoint");
    String childType = (String) handlerCtx.getInputValue("childType");
    String configName = (String) handlerCtx.getInputValue("configName");
    String sessionScopeRestURL = (String) handlerCtx.getInputValue("sessionScopeRestURL");
    sessionScopeRestURL = sessionScopeRestURL.endsWith("/") ? sessionScopeRestURL : sessionScopeRestURL + "/";
    String serverName = "";
    try {
        List<Map> table = RestUtil.buildChildEntityList((String) handlerCtx.getInputValue("parentEndpoint"), (String) handlerCtx.getInputValue("childType"), (List) handlerCtx.getInputValue("skipList"), (List) handlerCtx.getInputValue("includeList"), (String) handlerCtx.getInputValue("id"));
        if (configName.equals("default-config")) {
            for (Map row : table) {
                row.put("contextRoot", "");
            }
        } else {
            List<String> instances = RestUtil.getChildList(sessionScopeRestURL + "servers/server");
            for (String instance : instances) {
                String configRef = (String) RestUtil.getAttributesMap(instance).get("configRef");
                if (configRef.equals(configName)) {
                    serverName = instance.substring(instance.lastIndexOf("/") + 1);
                }
            }
            String deployedApplicationsEndpoint = sessionScopeRestURL + "servers/server/" + serverName + "/application-ref";
            List<String> deployedApplications = RestUtil.getChildList(deployedApplicationsEndpoint);
            List<String> virtualServers = RestUtil.getChildList(parentEndpoint + "/" + childType);
            List<String> applications = RestUtil.getChildList(sessionScopeRestURL + "applications/application");
            for (String virtualServer : virtualServers) {
                String virtualServerName = virtualServer.substring(virtualServer.lastIndexOf("/") + 1);
                for (int i = 0; i < deployedApplications.size(); i++) {
                    deployedApplications.set(i, deployedApplications.get(i).substring(deployedApplications.get(i).lastIndexOf("/") + 1));
                }
                String contextRoots = "";
                for (String application : applications) {
                    String applicationName = application.substring(application.lastIndexOf("/") + 1);
                    String[] deployedVirtualServers;
                    if (RestUtil.get(deployedApplicationsEndpoint + "/" + applicationName).isSuccess()) {
                        String deployedVirtualServersString = ((String) RestUtil.getAttributesMap(deployedApplicationsEndpoint + "/" + applicationName).get("virtualServers"));
                        if (deployedVirtualServersString != null) {
                            deployedVirtualServers = deployedVirtualServersString.split(",");
                            for (String deployedVirtualServer : deployedVirtualServers) {
                                if (!deployedVirtualServer.equals("") && deployedApplications.contains(applicationName) && virtualServerName.equals(deployedVirtualServer)) {
                                    if (!contextRoots.equals("")) {
                                        contextRoots += "<br>" + RestUtil.getAttributesMap(application).get("contextRoot");
                                    } else {
                                        contextRoots += RestUtil.getAttributesMap(application).get("contextRoot");
                                    }
                                }
                            }
                        }
                    }
                }
                for (Map row : table) {
                    if (row.get("name").equals(virtualServerName)) {
                        row.put("contextRoot", contextRoots);
                    }
                }
            }
        }
        handlerCtx.setOutputValue("result", table);
    } catch (Exception ex) {
        GuiUtil.handleException(handlerCtx, ex);
    }
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 7 with Handler

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

the class UpdateCenterHandlers method getUcList.

@Handler(id = "getUcList", input = { @HandlerInput(name = "state", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getUcList(HandlerContext handlerCtx) {
    List result = new ArrayList();
    if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))) {
        handlerCtx.setOutputValue("result", result);
        return;
    }
    try {
        Image img = getUpdateCenterImage();
        if (img == null) {
            handlerCtx.setOutputValue("result", result);
            return;
        }
        String state = (String) handlerCtx.getInputValue("state");
        if (state.equals("update")) {
            handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false));
            return;
        }
        List<Fmri> displayList = null;
        if (state.equals("installed"))
            displayList = getInstalledList(img);
        else if (state.equals("addOn"))
            displayList = getAddOnList(img);
        if (displayList != null) {
            for (Fmri fmri : displayList) {
                Map oneRow = new HashMap();
                try {
                    Manifest manifest = img.getManifest(fmri);
                    oneRow.put("selected", false);
                    oneRow.put("fmri", fmri);
                    oneRow.put("fmriStr", fmri.toString());
                    putInfo(oneRow, "pkgName", fmri.getName());
                    putInfo(oneRow, "version", getPkgVersion(fmri.getVersion()));
                    putInfo(oneRow, "newVersion", "");
                    putInfo(oneRow, "category", getCategory(manifest));
                    putInfo(oneRow, "pkgSize", getPkgSize(manifest));
                    oneRow.put("size", Integer.valueOf(manifest.getPackageSize()));
                    putInfo(oneRow, "auth", fmri.getAuthority());
                    String tooltip = manifest.getAttribute(PKG_SUMMARY);
                    if (GuiUtil.isEmpty(tooltip))
                        tooltip = manifest.getAttribute(DESC);
                    putInfo(oneRow, "tooltip", tooltip);
                    result.add(oneRow);
                } catch (Exception ex) {
                    GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage());
                    if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception ex1) {
        GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage());
        if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
            ex1.printStackTrace();
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 8 with Handler

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

the class UpdateCenterHandlers method getProxyInfo.

@Handler(id = "getProxyInfo", output = { @HandlerOutput(name = "connection", type = String.class), @HandlerOutput(name = "host", type = String.class), @HandlerOutput(name = "port", type = String.class) })
public static void getProxyInfo(HandlerContext handlerCtx) {
    Proxy proxy = SystemInfo.getProxy();
    if (proxy != null) {
        InetSocketAddress address = (InetSocketAddress) proxy.address();
        if (address != null) {
            handlerCtx.setOutputValue("connection", "useProxy");
            handlerCtx.setOutputValue("host", address.getHostName());
            handlerCtx.setOutputValue("port", address.getPort());
            return;
        }
    }
    handlerCtx.setOutputValue("connection", "direct");
    handlerCtx.setOutputValue("host", "");
    handlerCtx.setOutputValue("port", "");
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) Handler(com.sun.jsftemplating.annotation.Handler)

Example 9 with Handler

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

the class RestUtil2 method sendGetRequestToItemResource.

@Handler(id = "rest.get", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false) }, output = { @HandlerOutput(name = "result", type = Map.class) })
public static void sendGetRequestToItemResource(HandlerContext handlerCtx) {
    Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
    String endpoint = fixEndpoint((String) handlerCtx.getInputValue("endpoint"));
    Response resp = RestUtil.targetWithQueryParams(RestUtil.getJerseyClient().target(endpoint), RestUtil.buildMultivalueMap(attrs)).request(RestUtil.RESPONSE_TYPE).cookie(new Cookie(RestUtil.REST_TOKEN_COOKIE, RestUtil.getRestToken())).get(Response.class);
    // Response resp = makeRequest(endpoint, attrs).get(Response.class);
    Map map = resp.readEntity(Map.class);
    handlerCtx.setOutputValue("result", map);
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 10 with Handler

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

the class RestUtil2 method sendPostRequest.

@Handler(id = "rest.post", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false) }, output = { @HandlerOutput(name = "result", type = String.class) })
public static void sendPostRequest(HandlerContext handlerCtx) {
    Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
    String endpoint = fixEndpoint((String) handlerCtx.getInputValue("endpoint"));
    // Response resp = makeRequest(endpoint, null).post(Response.class, attrs);
    Response resp = RestUtil.getJerseyClient().target(endpoint).request(RestUtil.RESPONSE_TYPE).cookie(new Cookie(RestUtil.REST_TOKEN_COOKIE, RestUtil.getRestToken())).post(Entity.entity(attrs, MediaType.APPLICATION_JSON_TYPE), Response.class);
    if (!isSuccess(resp.getStatus())) {
        GuiUtil.getLogger().log(Level.SEVERE, GuiUtil.getCommonMessage("LOG_UPDATE_ENTITY_FAILED", new Object[] { endpoint, attrs }));
        GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
        return;
    }
    handlerCtx.setOutputValue("result", endpoint);
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) 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