1 26 27 package org.objectweb.jonas.ant.jonasbase; 28 29 import org.objectweb.jonas.ant.JOnASBaseTask; 30 31 35 public class WebContainer extends Tasks { 36 37 40 private static final String INFO = "[WebContainer] "; 41 42 45 private static final String JETTY_SERVICE = "org.objectweb.jonas.web.jetty50.JettyJWebContainerServiceImpl"; 46 47 50 private static final String TOMCAT_SERVICE = "org.objectweb.jonas.web.wrapper.catalina55.CatalinaJWebContainerServiceWrapper"; 51 52 55 private static final String DEFAULT_SERVICE = TOMCAT_SERVICE; 56 57 60 private static final String DEFAULT_PORT = "9000"; 61 62 65 private static final String TOMCAT_SERVICE_NAME = "<Service name=\"Tomcat-JOnAS\">"; 66 67 70 private boolean clusterIsEnabled = false; 71 72 75 private static final String DEFAULT_CLUSTER_LISTEN_PORT = "4001"; 76 77 80 private static final String DEFAULT_CLUSTER_MULTICAST_ADDR = "228.0.0.4"; 81 82 85 private static final String DEFAULT_CLUSTER_MULTICAST_PORT = "45564"; 86 87 90 public WebContainer() { 91 super(); 92 } 93 94 98 public void setPort(String portNumber) { 99 JReplace propertyReplace = new JReplace(); 101 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 102 propertyReplace.setToken(DEFAULT_PORT); 103 propertyReplace.setValue(portNumber); 104 propertyReplace.setLogInfo(INFO + "Setting Tomcat port number to : " + portNumber); 105 addTask(propertyReplace); 106 107 propertyReplace = new JReplace(); 109 propertyReplace.setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE); 110 propertyReplace.setToken(DEFAULT_PORT); 111 propertyReplace.setValue(portNumber); 112 propertyReplace.setLogInfo(INFO + "Setting Jetty port number to : " + portNumber); 113 addTask(propertyReplace); 114 } 115 116 117 121 public void setName(String containerName) { 122 123 String service = null; 124 125 if (containerName.equalsIgnoreCase("jetty")) { 126 service = JETTY_SERVICE; 127 } else { 128 service = TOMCAT_SERVICE; 129 } 130 131 JReplace propertyReplace = new JReplace(); 133 propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE); 134 propertyReplace.setToken(DEFAULT_SERVICE); 135 propertyReplace.setValue(service); 136 propertyReplace.setLogInfo(INFO + "Setting service to : " + service); 137 addTask(propertyReplace); 138 } 139 140 144 public void setAjpPort(String portNumber) { 145 JReplace propertyReplace = new JReplace(); 147 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 148 propertyReplace.setToken(TOMCAT_SERVICE_NAME); 149 String value = TOMCAT_SERVICE_NAME + "\n" 150 + 151 " <!-- Define an AJP 1.3 Connector on port " + portNumber + " -->" + "\n" 152 + 153 " <Connector port=\"" + portNumber + "\" enableLookups=\"false\" redirectPort=\"8443\" protocol=\"AJP/1.3\" />" + "\n"; 154 propertyReplace.setValue(value); 155 propertyReplace.setLogInfo(INFO + "Setting Tomcat AJP Connector to : " + portNumber); 156 addTask(propertyReplace); 157 } 158 159 163 public void setDirectorPort(String portNumber) { 164 JReplace propertyReplace = new JReplace(); 166 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 167 propertyReplace.setToken(TOMCAT_SERVICE_NAME); 168 String value = TOMCAT_SERVICE_NAME + "\n" 169 + 170 " <!-- Define a Director Connector on port " + portNumber + " -->" + "\n" 171 + 172 " <Connector protocol=\"org.enhydra.servlet.connectionMethods.EnhydraDirector.DirectorProtocol\"" + "\n" 173 + 174 " port=\"" + portNumber + "\"\n" 175 + 176 " threadTimeout = \"300\"" + "\n" 177 + 178 " clientTimeout = \"30\"" + "\n" 179 + 180 " sessionAffinity = \"false\"" + "\n" 181 + 182 " queueSize = \"400\"" + "\n" 183 + 184 " numThreads = \"200\"" + "\n" 185 + 186 " bindAddress = \"(All Interfaces)\"" + "\n" 187 + 188 " authKey = \"(Unauthenticated)\"" + "\n" 189 + 190 " />" + "\n"; 191 propertyReplace.setValue(value); 192 propertyReplace.setLogInfo(INFO + "Setting Tomcat AJP Connector to : " + portNumber); 193 addTask(propertyReplace); 194 } 195 196 199 private void setCluster() { 200 if (!clusterIsEnabled) { 201 JReplace propertyReplace = new JReplace(); 202 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 203 propertyReplace.setToken("</Host>"); 204 String value = "\n" 205 + 206 " <Cluster className=\"org.apache.catalina.cluster.tcp.SimpleTcpCluster\"" + "\n" 207 + 208 " managerClassName=\"org.apache.catalina.cluster.session.DeltaManager\"" + "\n" 209 + 210 " expireSessionsOnShutdown=\"false\"" + "\n" 211 + 212 " useDirtyFlag=\"true\"" + "\n" 213 + 214 " notifyListenersOnReplication=\"true\">" + "\n" 215 + 216 " <Membership" + "\n" 217 + 218 " className=\"org.apache.catalina.cluster.mcast.McastService\"" + "\n" 219 + 220 " mcastAddr=\"228.0.0.4\"" + "\n" 221 + 222 " mcastPort=\"45564\"" + "\n" 223 + 224 " mcastFrequency=\"500\"" + "\n" 225 + 226 " mcastDropTime=\"3000\"/>" + "\n" 227 + 228 229 " <Receiver" + "\n" 230 + 231 " className=\"org.apache.catalina.cluster.tcp.ReplicationListener\"" + "\n" 232 + 233 " tcpListenAddress=\"auto\"" + "\n" 234 + 235 " tcpListenPort=\"4001\"" + "\n" 236 + 237 " tcpSelectorTimeout=\"100\"" + "\n" 238 + 239 " tcpThreadCount=\"6\"/>" + "\n" 240 + 241 242 " <Sender" + "\n" 243 + 244 " className=\"org.apache.catalina.cluster.tcp.ReplicationTransmitter\"" + "\n" 245 + 246 " replicationMode=\"pooled\"" + "\n" 247 + 248 " ackTimeout=\"15000\"/>" + "\n" 249 + 250 251 " <Valve className=\"org.apache.catalina.cluster.tcp.ReplicationValve\"" + "\n" 252 + 253 " filter=\".*\\.gif;.*\\.js;.*\\.jpg;.*\\.png;.*\\.htm;.*\\.html;.*\\.css;.*\\.txt;\"/>" + "\n" 254 + 255 256 " </Cluster>" + "\n" 262 + 263 " </Host>"; 264 propertyReplace.setValue(value); 265 propertyReplace.setLogInfo(INFO + "Setting Cluster"); 266 addTask(propertyReplace); 267 clusterIsEnabled = true; 268 269 } 270 } 271 272 276 public void setClusterListenPort(String portNumber) { 277 setCluster(); 279 JReplace propertyReplace = new JReplace(); 280 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 281 propertyReplace.setToken(DEFAULT_CLUSTER_LISTEN_PORT); 282 propertyReplace.setValue(portNumber); 283 propertyReplace.setLogInfo(INFO + "Setting Cluster listen port : " + portNumber); 284 addTask(propertyReplace); 285 } 286 290 public void setClusterMcastAddr(String address) { 291 setCluster(); 293 JReplace propertyReplace = new JReplace(); 294 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 295 propertyReplace.setToken(DEFAULT_CLUSTER_MULTICAST_ADDR); 296 propertyReplace.setValue(address); 297 propertyReplace.setLogInfo(INFO + "Setting Cluster multicast addr : " + address); 298 addTask(propertyReplace); 299 } 300 304 public void setClusterMcastPort(String portNumber) { 305 setCluster(); 307 JReplace propertyReplace = new JReplace(); 308 propertyReplace.setConfigurationFile(JOnASBaseTask.TOMCAT_CONF_FILE); 309 propertyReplace.setToken(DEFAULT_CLUSTER_MULTICAST_PORT); 310 propertyReplace.setValue(portNumber); 311 propertyReplace.setLogInfo(INFO + "Setting Cluster multicast port : " + portNumber); 312 addTask(propertyReplace); 313 } 314 } | Popular Tags |