Package org.apache.geronimo.management.geronimo

Examples of org.apache.geronimo.management.geronimo.WebManager


            actionResponse.setRenderParameter(PARM_MODE, "new");
            String connectorType = actionRequest.getParameter(PARM_CONNECTOR_TYPE);
            actionResponse.setRenderParameter(PARM_CONNECTOR_TYPE, connectorType);
        } else if(mode.equals("add")) { // User just submitted the form to add a new connector
            // Create and configure the connector
            WebManager manager = PortletManager.getWebManager(actionRequest, new AbstractName(URI.create(managerURI)));
            ConnectorType connectorType = new ConnectorType(actionRequest.getParameter(PARM_CONNECTOR_TYPE));

            String uniqueName = actionRequest.getParameter(PARM_DISPLAY_NAME);
            actionResponse.setRenderParameter(PARM_DISPLAY_NAME, uniqueName);
            // set the connector attributes from the form post
            List<ConnectorAttribute> connectorAttributes = manager.getConnectorAttributes(connectorType);
            for (ConnectorAttribute attribute : connectorAttributes) {
                String name = attribute.getAttributeName();
                String value = actionRequest.getParameter(name);

                // handle booelan type special
                if (attribute.getAttributeClass().equals(Boolean.class)) {
                    // browser sends value of checked checkbox as "on" or "checked"
                    if ("on".equalsIgnoreCase(value) || "checked".equalsIgnoreCase(value)) {
                        value=Boolean.toString(true);
                    } else {
                        value=Boolean.toString(false);
                    }
                }
                // set the string form of the attribute's value as submitted by the browser
                if (value == null || value.trim().length()<1) {
                    // special case for KeystoreManager gbean
                    if ("trustStore".equals(attribute.getAttributeName())) {
                        attribute.setValue(null);
                    }
                } else {
                    attribute.setStringValue(value.trim());
                }
            }
            // create the connector gbean based on the configuration data
            AbstractName newConnectorName = manager.getConnectorConfiguration(connectorType, connectorAttributes, webContainer, uniqueName);

            // set the keystore properties if its a secure connector
            setKeystoreProperties(actionRequest, newConnectorName);

            // Start the connector
            try {
                GeronimoManagedBean managedBean = PortletManager.getManagedBean(actionRequest, newConnectorName);
                managedBean.startRecursive();
            } catch (Exception e) {
                log.error("Unable to start connector", e); //TODO: get into rendered page
            }

            try {
                manager.updateConnectorConfig(newConnectorName);
            } catch (Exception e) {
                log.error("Unable to update connector in server.xml", e); //TODO: get into rendered page
            }
            actionResponse.setRenderParameter(PARM_MODE, "list");
        } else if(mode.equals("save")) { // User just submitted the form to update a connector
            // Get submitted values
            //todo: lots of validation
            String connectorURI = actionRequest.getParameter(PARM_CONNECTOR_URI);
            // Identify and update the connector
            AbstractName connectorName = new AbstractName(URI.create(connectorURI));
            GBeanData connectorGBeanData=null;
            try {
                connectorGBeanData=PortletManager.getKernel().getGBeanData(connectorName);
            } catch (Exception e) {
                log.error("Unable to get connectorGBeanData by abstractName:"+connectorName.toURI(), e);
            }

            NetworkConnector connector = PortletManager.getNetworkConnector(actionRequest, connectorName);
            if(connector != null) {
                WebManager manager = PortletManager.getWebManager(actionRequest, new AbstractName(URI.create(managerURI)));
                ConnectorType connectorType = manager.getConnectorType(connectorName);

                // set the connector attributes from the form post
                for (ConnectorAttribute attribute : manager.getConnectorAttributes(connectorType)) {
                    String name = attribute.getAttributeName();
                    String value = actionRequest.getParameter(name);

                    // handle booelan type special
                    if (attribute.getAttributeClass().equals(Boolean.class)) {
                        // browser sends value of checked checkbox as "on" or "checked"
                        if ("on".equalsIgnoreCase(value) || "checked".equalsIgnoreCase(value)) {
                            value=Boolean.toString(true);
                        } else {
                            value=Boolean.toString(false);
                        }
                    }
                    // set the string form of the attribute's value as submitted by the browser
                    if (value == null || value.trim().length()<1) {
                        // special case for KeystoreManager gbean
                        if ("trustStore".equals(attribute.getAttributeName())) {

                            connectorGBeanData.setAttribute(name, null);
                        }
                    } else {
                        // set the string value on the ConnectorAttribute so
                        // it can handle type conversion via getValue()
                        try {
                            attribute.setStringValue(value);
                            connectorGBeanData.setAttribute(name, attribute.getValue());
                        } catch (Exception e) {
                            log.error("Unable to set property " + attribute.getAttributeName(), e);
                        }
                    }
                }

                // set the keystore properties if its a secure connector
                setKeystoreProperties(actionRequest, connectorName);

                try {
                    Kernel kernel = PortletManager.getKernel();
                    BundleContext bundleContext = kernel.getBundleFor(connectorName).getBundleContext();
                    kernel.stopGBean(connectorName);
                    kernel.unloadGBean(connectorName);
                    kernel.loadGBean(connectorGBeanData, bundleContext);
                    kernel.startGBean(connectorName);
                } catch (Exception e) {
                    log.error("Unable to reload updated connector:" + connectorName.toURI(), e);
                }


                try {
                    manager.updateConnectorConfig(connectorName);
                } catch (Exception e) {
                    log.error("Unable to update connector in server.xml", e); //TODO: get into rendered page
                }
            }
            actionResponse.setRenderParameter(PARM_MODE, "list");
View Full Code Here


            String server = getWebServerType(container.getClass());
            renderRequest.setAttribute(PARM_SERVER, server);

            if(mode.equals("new")) {
                String connectorType = renderRequest.getParameter(PARM_CONNECTOR_TYPE);
                WebManager webManager = PortletManager.getWebManager(renderRequest, new AbstractName(URI.create(managerURI)));
                ConnectorType type = new ConnectorType(connectorType);
                List<ConnectorAttribute> connectorAttributes = webManager.getConnectorAttributes(type);
                sortConnectorAttributes(connectorAttributes);
                renderRequest.setAttribute(PARM_CONNECTOR_ATTRIBUTES, connectorAttributes);
                renderRequest.setAttribute(PARM_CONNECTOR_TYPE, connectorType);
                renderRequest.setAttribute(PARM_MODE, "add");
                populateEnumAttributes(renderRequest);
                editConnectorView.include(renderRequest, renderResponse);
            } else if(mode.equals("edit")) {
                String connectorURI = renderRequest.getParameter(PARM_CONNECTOR_URI);
                NetworkConnector connector = PortletManager.getNetworkConnector(renderRequest, new AbstractName(URI.create(connectorURI)));
                if(connector == null) {
                    doList(renderRequest, renderResponse);
                } else {
                    AbstractName connectorName = new AbstractName(URI.create(connectorURI));
                    String uniqueName = connectorName.getName().get("name").toString();
                    renderRequest.setAttribute(PARM_DISPLAY_NAME, uniqueName);
                    WebManager webManager = PortletManager.getWebManager(renderRequest, new AbstractName(URI.create(managerURI)));
                    ConnectorType connectorType = webManager.getConnectorType(connectorName);
                    List<ConnectorAttribute> connectorAttributes = webManager.getConnectorAttributes(connectorType);
                    sortConnectorAttributes(connectorAttributes);

                    // populate the connector attributes from the connector
                    for (ConnectorAttribute attribute : connectorAttributes) {
                        try {
View Full Code Here

    private void doList(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
        WebManager[] managers = PortletManager.getWebManagers(renderRequest);
        List<ContainerInfo> all = new ArrayList<ContainerInfo>();
        for (int i = 0; i < managers.length; i++) {
            WebManager manager = managers[i];
            AbstractName webManagerName = PortletManager.getNameFor(renderRequest, manager);

            WebContainer[] containers = (WebContainer[]) manager.getContainers();
            for (int j = 0; j < containers.length; j++) {
                List<ConnectorInfo> beans = new ArrayList<ConnectorInfo>();
                WebContainer container = containers[j];
                AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                String id;
                if(containers.length == 1) {
                    id = manager.getProductName();
                } else {
                    id = manager.getProductName() + " (" + containerName.getName().get(NameFactory.J2EE_NAME) + ")";
                }
                ContainerInfo result = new ContainerInfo(id, webManagerName.toString(), containerName.toString());

                for (NetworkConnector connector : manager.getConnectorsForContainer(container)) {
                    ConnectorInfo info = new ConnectorInfo();
                    AbstractName connectorName = PortletManager.getNameFor(renderRequest, connector);
                    info.setConnectorURI(connectorName.toString());
                    info.setDescription(PortletManager.getGBeanDescription(renderRequest, connectorName));
                    info.setUniqueName((String)connectorName.getName().get(NameFactory.J2EE_NAME));
                    info.setState(((GeronimoManagedBean)connector).getState());
                    info.setPort(connector.getPort());
                    try {
                        info.setProtocol(connector.getProtocol());
                    } catch (IllegalStateException e) {
                        info.setProtocol("unknown");
                    }
                    beans.add(info);
                }
                result.setConnectors(beans);
                result.setConnectorTypes(manager.getConnectorTypes());
                all.add(result);
            }
        }
        if (0 == all.size()) {
            addWarningMessage(renderRequest, "warnMsg08");
View Full Code Here

            actionResponse.setRenderParameter(PARM_MODE, "new");
            String connectorType = actionRequest.getParameter(PARM_CONNECTOR_TYPE);
            actionResponse.setRenderParameter(PARM_CONNECTOR_TYPE, connectorType);
        } else if(mode.equals("add")) { // User just submitted the form to add a new connector
            // Create and configure the connector
            WebManager manager = PortletManager.getWebManager(actionRequest, new AbstractName(URI.create(managerURI)));
            ConnectorType connectorType = new ConnectorType(actionRequest.getParameter(PARM_CONNECTOR_TYPE));

            String uniqueName = actionRequest.getParameter(PARM_DISPLAY_NAME);
            actionResponse.setRenderParameter(PARM_DISPLAY_NAME, uniqueName);
            // set the connector attributes from the form post
            List<ConnectorAttribute> connectorAttributes = manager.getConnectorAttributes(connectorType);
            for (ConnectorAttribute attribute : connectorAttributes) {
                String name = attribute.getAttributeName();
                String value = actionRequest.getParameter(name);

                // handle booelan type special
                if (attribute.getAttributeClass().equals(Boolean.class)) {
                    // browser sends value of checked checkbox as "on" or "checked"
                    if ("on".equalsIgnoreCase(value) || "checked".equalsIgnoreCase(value)) {
                        value=Boolean.toString(true);
                    } else {
                        value=Boolean.toString(false);
                    }
                }
                // set the string form of the attribute's value as submitted by the browser
                if (value == null || value.trim().length()<1) {
                    // special case for KeystoreManager gbean
                    if ("trustStore".equals(attribute.getAttributeName())) {
                        attribute.setValue(null);
                    }
                } else {
                    attribute.setStringValue(value.trim());
                }
            }
            // create the connector gbean based on the configuration data
            AbstractName newConnectorName = manager.getConnectorConfiguration(connectorType, connectorAttributes, webContainer, uniqueName);

            // set the keystore properties if its a secure connector
            setKeystoreProperties(actionRequest, newConnectorName);

            // Start the connector
            try {
                GeronimoManagedBean managedBean = PortletManager.getManagedBean(actionRequest, newConnectorName);
                managedBean.startRecursive();
            } catch (Exception e) {
                log.error("Unable to start connector", e); //TODO: get into rendered page
            }

            try {
                manager.updateConnectorConfig(newConnectorName);
            } catch (Exception e) {
                log.error("Unable to update connector in server.xml", e); //TODO: get into rendered page
            }
            actionResponse.setRenderParameter(PARM_MODE, "list");
        } else if(mode.equals("save")) { // User just submitted the form to update a connector
            // Get submitted values
            //todo: lots of validation
            String connectorURI = actionRequest.getParameter(PARM_CONNECTOR_URI);
            // Identify and update the connector
            AbstractName connectorName = new AbstractName(URI.create(connectorURI));
            GBeanData connectorGBeanData=null;
            try {
                connectorGBeanData=PortletManager.getKernel().getGBeanData(connectorName);
            } catch (Exception e) {
                log.error("Unable to get connectorGBeanData by abstractName:"+connectorName.toURI(), e);
            }

            // Store the port info of the connector currently modified
            String toBeUpdatedConnectorName = (String) connectorGBeanData.getAttribute("name");
            Integer toBeUpdatedConnectorPort = (Integer) connectorGBeanData.getAttribute("port");
           
            NetworkConnector connector = PortletManager.getNetworkConnector(actionRequest, connectorName);
            if(connector != null) {
                WebManager manager = PortletManager.getWebManager(actionRequest, new AbstractName(URI.create(managerURI)));
                ConnectorType connectorType = manager.getConnectorType(connectorName);
               

                // set the connector attributes from the form post
                for (ConnectorAttribute attribute : manager.getConnectorAttributes(connectorType)) {
                    String name = attribute.getAttributeName();
                    String value = actionRequest.getParameter(name);

                    // handle booelan type special
                    if (attribute.getAttributeClass().equals(Boolean.class)) {
                        // browser sends value of checked checkbox as "on" or "checked"
                        if ("on".equalsIgnoreCase(value) || "checked".equalsIgnoreCase(value)) {
                            value=Boolean.toString(true);
                        } else {
                            value=Boolean.toString(false);
                        }
                    }
                    // set the string form of the attribute's value as submitted by the browser
                    if (value == null || value.trim().length()<1) {
                        // special case for KeystoreManager gbean
                        if ("trustStore".equals(attribute.getAttributeName())) {

                            connectorGBeanData.setAttribute(name, null);
                        }
                    } else {
                        // set the string value on the ConnectorAttribute so
                        // it can handle type conversion via getValue()
                        try {
                            attribute.setStringValue(value);
                            connectorGBeanData.setAttribute(name, attribute.getValue());
                        } catch (Exception e) {
                            log.error("Unable to set property " + attribute.getAttributeName(), e);
                        }
                    }
                }

                // set the keystore properties if its a secure connector
                setKeystoreProperties(actionRequest, connectorName);
               
                if (actionRequest.getServerPort() != toBeUpdatedConnectorPort.intValue()) {
                    try {
                        Kernel kernel = PortletManager.getKernel();
                        BundleContext bundleContext = kernel.getBundleFor(connectorName).getBundleContext();
                        kernel.stopGBean(connectorName);
                        kernel.unloadGBean(connectorName);
                        kernel.loadGBean(connectorGBeanData, bundleContext);
                        kernel.startGBean(connectorName);
                    } catch (Exception e) {
                        log.error("Unable to reload updated connector:" + connectorName.toURI(), e);
                        actionResponse.setRenderParameter("toBeUpdatedConnectorName", toBeUpdatedConnectorName);
                        addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg25", toBeUpdatedConnectorName));
                    }

                    try {
                        manager.updateConnectorConfig(connectorName);
                    } catch (Exception e) {
                        log.error("Unable to update connector in server.xml", e);
                        addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg26"));
                    }
                } else {
View Full Code Here

            String server = getWebServerType(container.getClass());
            renderRequest.setAttribute(PARM_SERVER, server);

            if(mode.equals("new")) {
                String connectorType = renderRequest.getParameter(PARM_CONNECTOR_TYPE);
                WebManager webManager = PortletManager.getWebManager(renderRequest, new AbstractName(URI.create(managerURI)));
                ConnectorType type = new ConnectorType(connectorType);
                List<ConnectorAttribute> connectorAttributes = webManager.getConnectorAttributes(type);
                sortConnectorAttributes(connectorAttributes);
                renderRequest.setAttribute(PARM_CONNECTOR_ATTRIBUTES, connectorAttributes);
                renderRequest.setAttribute(PARM_CONNECTOR_TYPE, connectorType);
                renderRequest.setAttribute(PARM_MODE, "add");
                populateEnumAttributes(renderRequest);
                editConnectorView.include(renderRequest, renderResponse);
            } else if(mode.equals("edit")) {
                String connectorURI = renderRequest.getParameter(PARM_CONNECTOR_URI);
                NetworkConnector connector = PortletManager.getNetworkConnector(renderRequest, new AbstractName(URI.create(connectorURI)));
                if(connector == null) {
                    doList(renderRequest, renderResponse);
                } else {
                    AbstractName connectorName = new AbstractName(URI.create(connectorURI));
                    String uniqueName = connectorName.getName().get("name").toString();
                    renderRequest.setAttribute(PARM_DISPLAY_NAME, uniqueName);
                    WebManager webManager = PortletManager.getWebManager(renderRequest, new AbstractName(URI.create(managerURI)));
                    ConnectorType connectorType = webManager.getConnectorType(connectorName);
                    List<ConnectorAttribute> connectorAttributes = webManager.getConnectorAttributes(connectorType);
                    sortConnectorAttributes(connectorAttributes);

                    // populate the connector attributes from the connector
                    for (ConnectorAttribute attribute : connectorAttributes) {
                        try {
View Full Code Here

    private void doList(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
        WebManager[] managers = PortletManager.getWebManagers(renderRequest);
        List<ContainerInfo> all = new ArrayList<ContainerInfo>();
        for (int i = 0; i < managers.length; i++) {
            WebManager manager = managers[i];
            AbstractName webManagerName = PortletManager.getNameFor(renderRequest, manager);

            WebContainer[] containers = (WebContainer[]) manager.getContainers();
            for (int j = 0; j < containers.length; j++) {
                List<ConnectorInfo> beans = new ArrayList<ConnectorInfo>();
                WebContainer container = containers[j];
                AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                String id;
                if(containers.length == 1) {
                    id = manager.getProductName();
                } else {
                    id = manager.getProductName() + " (" + containerName.getName().get(NameFactory.J2EE_NAME) + ")";
                }
                ContainerInfo result = new ContainerInfo(id, webManagerName.toString(), containerName.toString());

                for (NetworkConnector connector : manager.getConnectorsForContainer(container)) {
                    ConnectorInfo info = new ConnectorInfo();
                    AbstractName connectorName = PortletManager.getNameFor(renderRequest, connector);
                    info.setConnectorURI(connectorName.toString());
                    info.setDescription(PortletManager.getGBeanDescription(renderRequest, connectorName));
                    info.setUniqueName((String)connectorName.getName().get(NameFactory.J2EE_NAME));
                    info.setState(((GeronimoManagedBean)connector).getState());
                    info.setPort(connector.getPort());
                    try {
                        info.setProtocol(connector.getProtocol());
                    } catch (IllegalStateException e) {
                        info.setProtocol("unknown");
                    }
                    beans.add(info);
                }
                result.setConnectors(beans);
                result.setConnectorTypes(manager.getConnectorTypes());
                all.add(result);
            }
        }
        if (0 == all.size()) {
            addWarningMessage(renderRequest, "warnMsg08");
View Full Code Here

    public void processAction(ActionRequest actionRequest,
                              ActionResponse actionResponse) throws PortletException, IOException {
        try {
            WebManager[] managers = PortletManager.getCurrentServer(actionRequest).getWebManagers();
            if (managers != null) {
                WebManager manager = managers[0]//todo: handle multiple
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    WebContainer container = containers[0]//todo: handle multiple
                    String server = getWebServerType(container.getClass());
                    if (actionRequest.getParameter("stats") != null) {
                        Boolean stats = actionRequest.getParameter("stats").equals("true") ? Boolean.TRUE : Boolean.FALSE;
View Full Code Here

            return;
        }
        try {
            WebManager[] managers = PortletManager.getCurrentServer(renderRequest).getWebManagers();
            if (managers != null) {
                WebManager manager = managers[0]//todo: handle multiple
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    WebContainer container = containers[0]//todo: handle multiple
                    if(container.isStatisticsProvider()) {
                        WebContainerStats webStats = (WebContainerStats) ((StatisticsProvider)container).getStats();
                        if (webStats.isStatsOn()) {
View Full Code Here

//    }
//

    public static WebAccessLog getWebAccessLog(PortletRequest request, AbstractName managerName, AbstractName containerName) {
        ManagementHelper helper = getManagementHelper(request);
        WebManager manager = (WebManager) helper.getObject(managerName);
        return manager.getAccessLog((WebContainer) helper.getObject(containerName));
    }
View Full Code Here

        return (WebContainer) helper.getObject(containerName);
    }

    public static NetworkConnector[] getNetworkConnectors(PortletRequest request, AbstractName managerName) {
        ManagementHelper helper = getManagementHelper(request);
        WebManager manager = (WebManager) helper.getObject(managerName);
        return manager.getConnectors();
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.management.geronimo.WebManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.