KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > transform > elements > HttpListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Element.java
26  *
27  * Created on August 4, 2003, 2:04 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.transform.elements;
31
32 /**
33  *
34  * @author prakash
35  */

36 import org.w3c.dom.Document JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38 import org.w3c.dom.NodeList JavaDoc;
39 import org.w3c.dom.Node JavaDoc;
40 import com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper;
41 import com.sun.enterprise.tools.upgrade.common.DomainsProcessor;
42 import com.sun.enterprise.tools.upgrade.common.UpgradeUtils;
43
44 public class HttpListener extends BaseElement {
45     
46     private static java.util.logging.Logger JavaDoc log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
47     private final String JavaDoc HTTP_LISTENER_PORT_PROPERTY_NAME="HTTP_LISTENER_PORT";
48
49     /** Creates a new instance of Element */
50     public HttpListener() {
51     }
52     /**
53      * element - http-listener
54      * parentSource - source http-service
55      * parentResult - parent http-service
56      */

57     public void transform(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult){
58         // In domain.xml http-service is /domain/configs/config/http-service/http-listener
59
// in server.xml http-service is /server/http-service/http-listener
60

61         // Obtain a list of http-listeners from the result. IF the passed in element is not the one in the list then add it.
62
// If its the one existing then modify it.
63
// There should be either one or zero http-service and zero or more http-listener
64
NodeList JavaDoc resultHttpListeners = parentResult.getElementsByTagName("http-listener");
65         Element JavaDoc resultHttpListener = null;
66         java.util.Vector JavaDoc notToTransferAttrList = new java.util.Vector JavaDoc();
67         for(int lh =0; lh < resultHttpListeners.getLength(); lh++){
68             // Compare id attribute of http-listener elements.
69
String JavaDoc resultElementID = ((Element JavaDoc)resultHttpListeners.item(lh)).getAttribute("id");
70             if((element.getAttribute("id")).equals(resultElementID)){
71                 resultHttpListener = (Element JavaDoc)resultHttpListeners.item(lh);
72                 // if you are upgrading dont upgrade the port directly... Rather set it in each server's system-property.
73
String JavaDoc propertyName = this.getHttpListenerPortProperty(resultElementID,resultHttpListener);
74                 if(this.commonInfoModel.getCurrentCluster() != null){
75                     notToTransferAttrList.add("port");
76                     if(propertyName != null){
77                         // For http-listener-1, upgradeUtils will get the port no. from clusteredInstance instance port
78
String JavaDoc propertyValue = null;
79                         if(!resultElementID.equals("http-listener-1")){
80                             propertyValue = element.getAttribute("port");
81                         }
82                         UpgradeUtils.getUpgradeUtils(this.commonInfoModel).updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(),
83                                                             propertyName, propertyValue, this);
84                     }
85                 }else{
86                     // This is for stand alone servers. Lets not change the port nos. directly in config. Rather set it in system property
87
if(!this.commonInfoModel.getTargetEdition().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.EDITION_PE)){
88                         String JavaDoc instanceName = commonInfoModel.getCurrentSourceInstance();
89                         if((instanceName != null) &&(!("".equals(instanceName.trim())))){
90                             notToTransferAttrList.add("port");
91                             String JavaDoc propertyValue = element.getAttribute("port");
92                             NodeList JavaDoc servers = parentResult.getOwnerDocument().getDocumentElement().getElementsByTagName("servers");
93                             NodeList JavaDoc serverList = ((Element JavaDoc)servers.item(0)).getElementsByTagName("server");
94                             UpgradeUtils.getUpgradeUtils(this.commonInfoModel).addOrUpdateSystemPropertyToServer(instanceName, serverList, propertyName, propertyValue, this);
95                         }
96                     }
97                 }
98                 this.transferAttributes(element, resultHttpListener,notToTransferAttrList);
99             }
100             if(resultElementID.equals("admin-listener")){
101                 String JavaDoc adminPort = DomainsProcessor.getSourceAdminPort();
102                 String JavaDoc adminSecurity = DomainsProcessor.getSourceAdminSecurity();
103                 ((Element JavaDoc)resultHttpListeners.item(lh)).setAttribute("port", adminPort);
104                 ((Element JavaDoc)resultHttpListeners.item(lh)).setAttribute("security-enabled", adminSecurity);
105             }
106         }
107         if(resultHttpListener == null){
108             // Add element - http-listener to result http-service.
109
resultHttpListener = parentResult.getOwnerDocument().createElement("http-listener");
110             // I noticed that for additional http-listeners there is no need to add property for each listener
111
if(this.commonInfoModel.getCurrentCluster() != null){
112                 notToTransferAttrList.add("port");
113                 String JavaDoc propertyName = element.getAttribute("id")+"_HTTP_LISTENER_PORT";
114                 UpgradeUtils.getUpgradeUtils(this.commonInfoModel).updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(),
115                                                                         propertyName, element.getAttribute("port"), this);
116                 resultHttpListener.setAttribute("port", "${"+propertyName+"}");
117             }
118             this.transferAttributes(element, resultHttpListener,notToTransferAttrList);
119             this.appendElementToParent(parentResult,resultHttpListener);
120         }
121         super.transform(element, parentSource, resultHttpListener);
122     }
123     public void transferAttributes(Element JavaDoc sourceEle, Element JavaDoc targetEle, java.util.List JavaDoc notToTransferAttrList){
124         // NOTE: server.xml of as7 has family & blocking-enabled attrs which does not exist in as8 domain.xml but exists in as81 domain.xml
125
// acceptor-threads should not be transferred. FIX for problem with LINUX
126
notToTransferAttrList.add("acceptor-threads");
127         
128         super.transferAttributes(sourceEle, targetEle, notToTransferAttrList);
129         if(this.commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_7X)){
130             String JavaDoc serverID = sourceEle.getOwnerDocument().getDocumentElement().getAttribute("name");
131             if(targetEle.getAttribute("default-virtual-server").equals(serverID)){
132                 targetEle.setAttribute("default-virtual-server","server");
133             }
134         }
135         
136         // This is already take care of above.
137
// If transferring from 8.0PE to 8.1 SE/EE, the listerner for __admin must have securtiy-enabled defaulted to true.
138
//if(this.commonInfoModel.getSourceVersionAndEdition().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_AS80_PE)){
139
//if(sourceEle.getAttribute("id").equals("admin-listener")){
140
//targetEle.setAttribute("security-enabled", "true");
141
//}
142
//}
143
//this.printAttrs(targetEle);
144
}
145     private void printAttrs(Element JavaDoc ele){
146         org.w3c.dom.NamedNodeMap JavaDoc sourceAttrNodeMap = ele.getAttributes();
147         for(int index=0; index < sourceAttrNodeMap.getLength(); index++){
148              Node JavaDoc sourceAttrNode = sourceAttrNodeMap.item(index);
149              log.info("******\n attr name="+sourceAttrNode.getNodeName()+" attrValue="+sourceAttrNode.getNodeValue());
150         }
151     }
152     private String JavaDoc getHttpListenerPortProperty(String JavaDoc id, Element JavaDoc resultHttpListener){
153         if(id.equals("http-listener-1")){
154             return this.HTTP_LISTENER_PORT_PROPERTY_NAME;
155         }
156         String JavaDoc portValue = resultHttpListener.getAttribute("port");
157         if((portValue != null) && portValue.trim().startsWith("${")){
158             return portValue.substring(2,portValue.length()-1);
159         }
160         return null;
161     }
162     
163 }
164
Popular Tags