001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Jetty.java 7939 2006-01-25 17:35:15Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.ant.jonasbase.web;
025:
026: import org.objectweb.jonas.ant.JOnASBaseTask;
027: import org.objectweb.jonas.ant.jonasbase.JReplace;
028: import org.objectweb.jonas.ant.jonasbase.Tasks;
029:
030: /**
031: * Support Jetty Connector Configuration.
032: *
033: * @author Guillaume Sauthier
034: */
035: public class Jetty extends Tasks {
036:
037: /**
038: * Info for the logger
039: */
040: private static final String INFO = "[Jetty] ";
041:
042: /**
043: * HTTPS TOKEN
044: */
045: private static final String HTTPS_TOKEN = "<!-- Add a HTTPS SSL listener on port 9043";
046:
047: /**
048: * AJP TOKEN
049: */
050: private static final String AJP_TOKEN = "<!-- Add a AJP13 listener on port 8009";
051:
052: /**
053: * Default Constructor.
054: */
055: public Jetty() {
056: super ();
057: }
058:
059: /**
060: * Configure a HTTP Connector.
061: * @param http HTTP Configuration.
062: */
063: public void addConfiguredHttp(Http http) {
064: JReplace propertyReplace = new JReplace();
065: propertyReplace
066: .setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE);
067: propertyReplace.setToken(Http.DEFAULT_PORT);
068: propertyReplace.setValue(http.getPort());
069: propertyReplace.setLogInfo(INFO
070: + "Setting HTTP port number to : " + http.getPort());
071: addTask(propertyReplace);
072: }
073:
074: /**
075: * Configure a HTTPS Connector.
076: * @param https HTTPS Configuration.
077: */
078: public void addConfiguredHttps(Https https) {
079: JReplace propertyReplace = new JReplace();
080: propertyReplace
081: .setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE);
082: propertyReplace.setToken(HTTPS_TOKEN);
083: StringBuffer value = new StringBuffer();
084: value.append("<!-- Add a HTTPS SSL listener on port "
085: + https.getPort() + " -->\n");
086: value
087: .append(" <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->\n");
088: value.append(" <Call name=\"addListener\">\n");
089: value.append(" <Arg>\n");
090: if (Https.IBM_VM.equalsIgnoreCase(https.getVm())) {
091: value
092: .append(" <New class=\"org.mortbay.http.IbmJsseListener\">\n");
093: } else {
094: // default to Sun
095: value
096: .append(" <New class=\"org.mortbay.http.SunJsseListener\">\n");
097: }
098: value.append(" <Set name=\"Port\">" + https.getPort()
099: + "</Set>\n");
100: value.append(" <Set name=\"MinThreads\">5</Set>\n");
101: value.append(" <Set name=\"MaxThreads\">100</Set>\n");
102: value
103: .append(" <Set name=\"MaxIdleTimeMs\">30000</Set>\n");
104: value
105: .append(" <Set name=\"LowResourcePersistTimeMs\">2000</Set>\n");
106: if (https.getKeystoreFile() != null) {
107: value.append(" <Set name=\"Keystore\">"
108: + https.getKeystoreFile() + "</Set>\n");
109: }
110: if (https.getKeystorePass() != null) {
111: value.append(" <Set name=\"Password\">"
112: + https.getKeystorePass() + "</Set>\n");
113: }
114: if (https.getKeyPassword() != null) {
115: value.append(" <Set name=\"KeyPassword\">"
116: + https.getKeyPassword() + "</Set>\n");
117: }
118: value.append(" </New>\n");
119: value.append(" </Arg>\n");
120: value.append(" </Call>\n\n");
121: value
122: .append(" <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->\n");
123: value.append(" " + HTTPS_TOKEN);
124: propertyReplace.setValue(value.toString());
125: propertyReplace.setLogInfo(INFO
126: + "Setting HTTPS port number to : " + https.getPort());
127: addTask(propertyReplace);
128:
129: propertyReplace = new JReplace();
130: propertyReplace
131: .setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE);
132: propertyReplace.setToken(Https.DEFAULT_PORT);
133: propertyReplace.setValue(https.getPort());
134: propertyReplace.setLogInfo(INFO
135: + "Fix HTTP redirect port number to : "
136: + https.getPort());
137: addTask(propertyReplace);
138:
139: }
140:
141: /**
142: * Configure an AJP Connector.
143: * @param ajp AJP Configuration.
144: */
145: public void addConfiguredAjp(Ajp ajp) {
146: JReplace propertyReplace = new JReplace();
147: propertyReplace
148: .setConfigurationFile(JOnASBaseTask.JETTY_CONF_FILE);
149: propertyReplace.setToken(AJP_TOKEN);
150: StringBuffer value = new StringBuffer();
151: value.append("<!-- Add a AJP13 listener on port "
152: + ajp.getPort()
153: + " -->\n");
154: value
155: .append(" <!-- This protocol can be used with mod_jk in apache, IIS etc. -->\n");
156: value
157: .append(" <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->\n");
158: value.append(" <Call name=\"addListener\">\n");
159: value.append(" <Arg>\n");
160: value
161: .append(" <New class=\"org.mortbay.http.ajp.AJP13Listener\">\n");
162: value.append(" <Set name=\"Port\">" + ajp.getPort()
163: + "</Set>\n");
164: value.append(" <Set name=\"MinThreads\">5</Set>\n");
165: value.append(" <Set name=\"MaxThreads\">20</Set>\n");
166: value.append(" <Set name=\"MaxIdleTimeMs\">0</Set>\n");
167: value
168: .append(" <Set name=\"confidentialPort\">9043</Set>\n");
169: value.append(" </New>\n");
170: value.append(" </Arg>\n");
171: value.append(" </Call>\n\n");
172: value
173: .append(" <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->\n");
174: value.append(" " + AJP_TOKEN);
175: propertyReplace.setValue(value.toString());
176: propertyReplace.setLogInfo(INFO + "Setting AJP Connector to : "
177: + ajp.getPort());
178: addTask(propertyReplace);
179: }
180:
181: }
|