FileDocCategorySizeDatePackage
HttpListener.javaAPI DocGlassfish v2 API10435Wed Jul 11 10:00:58 BST 2007com.sun.enterprise.tools.upgrade.transform.elements

HttpListener

public class HttpListener extends BaseElement
author
prakash

Fields Summary
private static Logger
log
private final String
HTTP_LISTENER_PORT_PROPERTY_NAME
Constructors Summary
public HttpListener()
Creates a new instance of Element


           
      
    
Methods Summary
private java.lang.StringgetHttpListenerPortProperty(java.lang.String id, org.w3c.dom.Element resultHttpListener)

        if(id.equals("http-listener-1")){
            return this.HTTP_LISTENER_PORT_PROPERTY_NAME;
        }
        String portValue = resultHttpListener.getAttribute("port");
        if((portValue != null) && portValue.trim().startsWith("${")){
            return portValue.substring(2,portValue.length()-1);
        }
        return null;
    
private voidprintAttrs(org.w3c.dom.Element ele)

        org.w3c.dom.NamedNodeMap sourceAttrNodeMap = ele.getAttributes();
        for(int index=0; index < sourceAttrNodeMap.getLength(); index++){
             Node sourceAttrNode = sourceAttrNodeMap.item(index);
             log.info("******\n attr name="+sourceAttrNode.getNodeName() + 
                     " attrValue="+sourceAttrNode.getNodeValue());
        }
    
public voidtransferAttributes(org.w3c.dom.Element sourceEle, org.w3c.dom.Element targetEle, java.util.List notToTransferAttrList)

        // NOTE: server.xml of as7 has family & blocking-enabled attrs 
	// They do not exist in as8 domain.xml but exists in as81 domain.xml
        // acceptor-threads should not be transferred.  FIX for problem with LINUX
        notToTransferAttrList.add("acceptor-threads");
        logger.log(Level.FINE, this.getClass().getName() + ":: notToTransferAttrList ", 
                    notToTransferAttrList);
        super.transferAttributes(sourceEle, targetEle, notToTransferAttrList);
        if(UpgradeConstants.VERSION_7X.equals(commonInfoModel.getSourceVersion())){
            String serverID = sourceEle.getOwnerDocument().getDocumentElement().getAttribute("name");
            if(targetEle.getAttribute("default-virtual-server").equals(serverID)){
                targetEle.setAttribute("default-virtual-server","server");
            }
        }
    
public voidtransform(org.w3c.dom.Element element, org.w3c.dom.Element parentSource, org.w3c.dom.Element parentResult)
element - http-listener parentSource - source http-service parentResult - parent http-service

        // In domain.xml http-service is /domain/configs/config/http-service/http-listener
        // in server.xml http-service is /server/http-service/http-listener

        // Obtain a list of http-listeners from the result. IF the passed in element is not the one in the list then add it.
        // If its the one existing then modify it.
        // There should be either one or zero http-service and zero or more http-listener
        logger.log(Level.FINE, 
                stringManager.getString("upgrade.transform.transformingMSG", 
                this.getClass().getName(), 
                element));
        NodeList resultHttpListeners = parentResult.getElementsByTagName("http-listener");
        Element resultHttpListener = null;
        java.util.Vector notToTransferAttrList = new java.util.Vector();
        for(int lh =0; lh < resultHttpListeners.getLength(); lh++){
            // Compare id attribute of http-listener elements.
            String resultElementID = ((Element)resultHttpListeners.item(lh)).getAttribute("id");
            if((element.getAttribute("id")).equals(resultElementID)){
                resultHttpListener = (Element)resultHttpListeners.item(lh);
                // if you are upgrading dont upgrade the port directly... Rather set it in each server's system-property.
                String propertyName = this.getHttpListenerPortProperty(resultElementID,resultHttpListener);
                if(commonInfoModel.getCurrentCluster() != null){
                    notToTransferAttrList.add("port");
                    if(propertyName != null){
                        // For http-listener-1, upgradeUtils will get the port no. from clusteredInstance instance port
                        String propertyValue = null;
                        if(!resultElementID.equals("http-listener-1")){
                            propertyValue = element.getAttribute("port");
                        }
                        UpgradeUtils.getUpgradeUtils(commonInfoModel).
                            updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(), 
                                propertyName, propertyValue, this);
                    }
                }else{
                    // This is for stand alone servers.  
		    // Lets not change the port nos. directly in config.  Rather set it in system property
                    if(!UpgradeConstants.EDITION_PE.equals(commonInfoModel.getSourceEdition())){
                        String instanceName = commonInfoModel.getCurrentSourceInstance();
                        if((instanceName != null) &&(!("".equals(instanceName.trim())))){
                            notToTransferAttrList.add("port");
                            String propertyValue = element.getAttribute("port");
                            NodeList servers = parentResult.getOwnerDocument().getDocumentElement().
                                    getElementsByTagName("servers");
                            NodeList serverList = ((Element)servers.item(0)).getElementsByTagName("server");
                            UpgradeUtils.getUpgradeUtils(commonInfoModel).
                                    addOrUpdateSystemPropertyToServer(instanceName, 
                                        serverList, propertyName, propertyValue, this);
                        }
                    }
                }
                this.transferAttributes(element, resultHttpListener,notToTransferAttrList);
            }
            if(resultElementID.equals("admin-listener")){
                String domainPath = commonInfoModel.getSourceDomainPath();
                String adminPort = DomainsProcessor.getSourceAdminPort(domainPath);
                String adminSecurity = DomainsProcessor.getSourceAdminSecurity(domainPath);
                ((Element)resultHttpListeners.item(lh)).setAttribute("port", adminPort);
		//security-enabled should be set to true when target is of enterprise profile. start CR 6383799
		if(UpgradeConstants.EDITION_EE.equals(commonInfoModel.getSourceEdition()) &&
                        adminSecurity.equals("false")) {
                    ((Element)resultHttpListeners.item(lh)).setAttribute("security-enabled", "true");
		//end CR 6383799
		} else
                    ((Element)resultHttpListeners.item(lh)).setAttribute("security-enabled", adminSecurity);
            }
        }
        if(resultHttpListener == null){
            // Add element - http-listener to result http-service.
            resultHttpListener = parentResult.getOwnerDocument().createElement("http-listener");
            // I noticed that for additional http-listeners there is no need to add property for each listener
            if(commonInfoModel.getCurrentCluster() != null){
                notToTransferAttrList.add("port");
                String propertyName = element.getAttribute("id")+"_HTTP_LISTENER_PORT";
                UpgradeUtils.getUpgradeUtils(commonInfoModel).
                        updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(),
                            propertyName, element.getAttribute("port"), this);
                resultHttpListener.setAttribute("port", "${"+propertyName+"}");
            }
            this.transferAttributes(element, resultHttpListener,notToTransferAttrList);
            this.appendElementToParent(parentResult,resultHttpListener);
        }
        super.transform(element, parentSource, resultHttpListener);