setup-datasource-standard.jsp 16.5 KB
Newer Older
1 2 3 4 5 6 7
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%--
  -	$RCSfile$
  -	$Revision: 1772 $
  -	$Date: 2005-08-11 12:56:15 -0700 (Thu, 11 Aug 2005) $
--%>

8
<%@ page import="org.jivesoftware.database.DbConnectionManager,
9
                 org.jivesoftware.database.DefaultConnectionProvider,
10
                 org.jivesoftware.util.ClassUtils,
11
                 org.jivesoftware.util.JiveGlobals,
12
                 org.jivesoftware.util.Log,
13 14 15 16 17 18 19
                 org.jivesoftware.util.ParamUtils,
                 org.jivesoftware.wildfire.XMPPServer,
                 java.io.File,
                 java.lang.Double,
                 java.lang.Exception,
                 java.lang.Integer,
                 java.lang.String"
20
%>
21 22 23 24 25 26 27 28
<%@ page import="java.lang.Throwable"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
29 30

<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

<%
	// Redirect if we've already run setup:
	if (!XMPPServer.getInstance().isSetupMode()) {
        response.sendRedirect("setup-completed.jsp");
        return;
    }
%>

<%!
    boolean testConnection(Map<String,String> errors) {
        boolean success = true;
        Connection con = null;
        try {
            con = DbConnectionManager.getConnection();
            if (con == null) {
                success = false;
                errors.put("general","A connection to the database could not be "
                    + "made. View the error message by opening the "
                    + "\"" + File.separator + "logs" + File.separator + "error.log\" log "
                    + "file, then go back to fix the problem.");
            }
            else {
            	// See if the Jive db schema is installed.
            	try {
            		Statement stmt = con.createStatement();
            		// Pick an arbitrary table to see if it's there.
            		stmt.executeQuery("SELECT * FROM jiveID");
            		stmt.close();
            	}
            	catch (SQLException sqle) {
                    success = false;
                    sqle.printStackTrace();
64
                    errors.put("general","The Wildfire database schema does not "
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
                        + "appear to be installed. Follow the installation guide to "
                        + "fix this error.");
            	}
            }
        }
        catch (Exception ignored) {}
        finally {
            try {
        	    con.close();
            } catch (Exception ignored) {}
        }
        return success;
    }
%>


81 82 83 84 85 86 87 88 89 90 91 92
<%  // Get parameters
    String driver = ParamUtils.getParameter(request,"driver");
    String serverURL = ParamUtils.getParameter(request,"serverURL");
    String username = ParamUtils.getParameter(request,"username",true);
    String password = ParamUtils.getParameter(request,"password",true);
    int minConnections = ParamUtils.getIntParameter(request,"minConnections",-1);
    int maxConnections = ParamUtils.getIntParameter(request,"maxConnections",-1);
    double connectionTimeout = ParamUtils.getDoubleParameter(request,"connectionTimeout",0.0);

    boolean doContinue = request.getParameter("continue") != null;

    // handle a continue request
93
    Map<String,String> errors = new HashMap<String,String>();
94 95 96 97 98 99 100 101 102
    if (doContinue) {
        // Error check
        if (driver == null || "sun.jdbc.odbc.JdbcOdbcDriver".equals(driver)
                || "com.internetcds.jdbc.tds.Driver".equals(driver))
        {
            errors.put("driver","Please enter a valid JDBC driver class.");
        }
        else {
            try {
103
                ClassUtils.forName(driver);
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
            }
            catch (Throwable t) {
                errors.put("driver","Unable to load the specified JDBC driver. Please verify the " +
                        "name of the driver is correct and that the driver is in the classpath " +
                        "of this server (usually the 'lib' directory). If you add a driver to " +
                        "your classpath you will neeed to restart the server.");
            }
        }
        if (serverURL == null) {
            errors.put("serverURL", "Please enter a valid JDBC URL.");
        }
        if (minConnections < 3) {
            errors.put("minConnections","The minimum connection pool size is three connections.");
        }
        if (maxConnections < minConnections) {
            errors.put("maxConnections","The maximum number of connections cannot be less than the minimum.");
        }
        if (connectionTimeout <= 0.0) {
            errors.put("connectionTimeout","Please enter a valid connection timeout value.");
        }

        // if there were no errors, continue
        if (errors.size() == 0) {
            // set properties, test connection, etc

            // Force the standard jive connection provider to be used by deleting the current setting:
            JiveGlobals.setXMLProperty("connectionProvider.className",
                    "org.jivesoftware.database.DefaultConnectionProvider");
            DefaultConnectionProvider conProvider = new DefaultConnectionProvider();
            try {
                conProvider.setDriver(driver);
                conProvider.setConnectionTimeout(connectionTimeout);
                conProvider.setMinConnections(minConnections);
                conProvider.setMaxConnections(maxConnections);
                conProvider.setServerURL(serverURL);
                conProvider.setUsername(username);
                conProvider.setPassword(password);

                JiveGlobals.setXMLProperty("database.defaultProvider.driver", driver);
                JiveGlobals.setXMLProperty("database.defaultProvider.serverURL", serverURL);
                JiveGlobals.setXMLProperty("database.defaultProvider.username", username);
                JiveGlobals.setXMLProperty("database.defaultProvider.password", password);

                JiveGlobals.setXMLProperty("database.defaultProvider.minConnections",
                        Integer.toString(minConnections));
                JiveGlobals.setXMLProperty("database.defaultProvider.maxConnections",
                        Integer.toString(maxConnections));
                JiveGlobals.setXMLProperty("database.defaultProvider.connectionTimeout",
                Double.toString(connectionTimeout));
            }
            catch (Exception e) {
                errors.put("general","Setting connection properties failed - please see the error "
                        + "log located in home/logs for more details.");
                Log.error(e);
            }
            // No errors setting the properties, so test the connection
            DbConnectionManager.setConnectionProvider(conProvider);
            if (testConnection(errors)) {
                // Success, move on
163
                response.sendRedirect("setup-profile-settings.jsp");
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
                return;
            }
        }
    }

    if (!doContinue) {
        // reset values of jdbc driver from props file
        driver = JiveGlobals.getXMLProperty("database.defaultProvider.driver");
        serverURL = JiveGlobals.getXMLProperty("database.defaultProvider.serverURL");
        username = JiveGlobals.getXMLProperty("database.defaultProvider.username");
        password = JiveGlobals.getXMLProperty("database.defaultProvider.password");
        try {
            minConnections = Integer.parseInt(
                    JiveGlobals.getXMLProperty("database.defaultProvider.minConnections"));
        }
        catch (Exception e) {
            minConnections = 5;
        }
        try {
            maxConnections = Integer.parseInt(
                    JiveGlobals.getXMLProperty("database.defaultProvider.maxConnections"));
        }
        catch (Exception e) {
            maxConnections = 15;
        }
        try {
            connectionTimeout = Double.parseDouble(
                    JiveGlobals.getXMLProperty("database.defaultProvider.connectionTimeout"));
        }
        catch (Exception e) {
            connectionTimeout = 1.0;
        }
    }
%>

199
<html>
200
<head>
201 202
    <title><fmt:message key="setup.datasource.standard.title" /></title>
    <meta name="currentStep" content="2"/>
203
</head>
204
<body>
205

206 207 208
	<h1>
	<fmt:message key="setup.datasource.standard.title" />
	</h1>
209

210 211 212
	<p>
	<fmt:message key="setup.datasource.standard.info" /> <fmt:message key="title" />.
	</p>
213

214 215 216
	<p>
	<b><fmt:message key="setup.datasource.standard.info2" /> </b><fmt:message key="setup.datasource.standard.info3" /> <tt>[Wildfire_HOME]/resources/database</tt>.
	</p>
217 218

<%  if (errors.size() > 0) { %>
219
    <div class="error">
220 221 222 223 224 225 226 227 228
    <%  if (errors.get("general") != null) { %>

        <%= errors.get("general") %>

    <%  } else { %>

        <fmt:message key="setup.datasource.standard.failed_connect" />

    <%  } %>
229
    </div>
230 231
<%  } %>

232 233 234 235 236 237


	<!-- BEGIN jive-contentBox -->
	<div class="jive-contentBox">


238
<%  // DB preset data
239
    List<String[]> presets = new ArrayList<String []>();
240 241
    presets.add(new String[]{"MySQL","com.mysql.jdbc.Driver","jdbc:mysql://[host-name]:3306/[database-name]"});
    presets.add(new String[]{"Oracle","oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@[host-name]:1521:[SID]"});
242
    presets.add(new String[]{"Microsoft SQLServer","net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://[host-name]/[database-name];appName=jive"});
243 244 245 246 247 248
    presets.add(new String[]{"PostgreSQL","org.postgresql.Driver","jdbc:postgresql://[host-name]:5432/[database-name]"});
    presets.add(new String[]{"IBM DB2","COM.ibm.db2.jdbc.app.DB2Driver","jdbc:db2:[database-name]"});
%>
<script language="JavaScript" type="text/javascript">
var data = new Array();
<%  for (int i=0; i<presets.size(); i++) {
249
        String[] data = presets.get(i);
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
%>
    data[<%= i %>] = new Array('<%= data[0] %>','<%= data[1] %>','<%= data[2] %>');
<%  } %>
function populate(i) {
    document.dbform.driver.value=data[i][1];
    document.dbform.serverURL.value=data[i][2];
}
var submitted = false;
function checkSubmit() {
    if (!submitted) {
        submitted = true;
        return true;
    }
    return false;
}
</script>

267
<form action="setup-datasource-standard.jsp" method="post" name="dbform" onsubmit="return checkSubmit();">
268 269 270

<table cellpadding="3" cellspacing="2" border="0">
<tr>
271 272
	<td nowrap align="right"><fmt:message key="setup.datasource.standard.label" />:</td>
    <td>
273 274 275
        <select size="1" name="presets" onchange="populate(this.options[this.selectedIndex].value)">
            <option value=""><fmt:message key="setup.datasource.standard.pick_database" />
            <%  for (int i=0; i<presets.size(); i++) {
276
                    String[] data = presets.get(i);
277 278 279 280 281 282 283
            %>
                <option value="<%= i %>"> &#149; <%= data[0] %>
            <%  } %>
        </select>
    </td>
</tr>
<tr valign="top">
284
    <td nowrap align="right">
285 286 287 288 289
        <fmt:message key="setup.datasource.standard.jdbc" />
    </td>
    <td>
        <input type="text" name="driver" size="50" maxlength="150"
         value="<%= ((driver != null) ? driver : "") %>">
290
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.jdbc_info" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
291 292 293 294 295 296 297 298
        <%  if (errors.get("driver") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("driver") %>
            </span>
        <%  } %>
    </td>
</tr>
<tr valign="top">
299
    <td nowrap align="right">
300 301 302 303 304
        <fmt:message key="setup.datasource.standard.url" />
    </td>
    <td>
        <input type="text" name="serverURL" size="50" maxlength="250"
         value="<%= ((serverURL != null) ? serverURL : "") %>">
305
	    <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.valid_url" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
306 307 308 309 310 311 312 313 314
        <%  if (errors.get("serverURL") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("serverURL") %>
            </span>
        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
315
    <td nowrap align="right">
316 317 318 319 320
        <fmt:message key="setup.datasource.standard.username" />
    </td>
    <td>
        <input type="text" name="username" size="20" maxlength="50"
         value="<%= ((username != null) ? username : "") %>">
321
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.username_info" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
322 323 324 325 326 327 328 329
        <%  if (errors.get("username") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("username") %>
            </span>
        <%  } %>
    </td>
</tr>
<tr valign="top">
330
    <td nowrap align="right">
331 332 333 334 335
        <fmt:message key="setup.datasource.standard.password" />
    </td>
    <td>
        <input type="password" name="password" size="20" maxlength="50"
         value="<%= ((password != null) ? password : "") %>">
336
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.password_info" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
337 338 339 340 341 342 343 344 345
        <%  if (errors.get("password") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("password") %>
            </span>
        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
346
    <td nowrap align="right">
347 348
        <%--<fmt:message key="setup.datasource.standard.connect" />--%>
        Minimum Connections:
349 350
    </td>
    <td>
351
	    <input type="text" name="minConnections" size="5" maxlength="5" value="<%= ((minConnections != -1) ? ""+minConnections : "") %>">
352
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.pool" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
353 354 355 356 357
        <%  if (errors.get("minConnections") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("minConnections") %>
            </span>
        <%  } %>
358 359 360 361 362 363 364 365 366 367
    </td>
</tr>
<tr valign="top">
    <td nowrap align="right">
        <%--<fmt:message key="setup.datasource.standard.connect" />--%>
        Maximum Connections:
    </td>
    <td>
	    <input type="text" name="maxConnections" size="5" maxlength="5" value="<%= ((maxConnections != -1) ? ""+maxConnections : "") %>">
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.pool" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
368 369 370 371 372 373 374 375
        <%  if (errors.get("maxConnections") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("maxConnections") %>
            </span>
        <%  } %>
    </td>
</tr>
<tr valign="top">
376
    <td nowrap align="right">
377 378 379 380
        <fmt:message key="setup.datasource.standard.timeout" />
    </td>
    <td>
        <input type="text" name="connectionTimeout" size="5" maxlength="5"
381
         value="<%= connectionTimeout %>"> <span style="display: block; float: left; padding: 2px 5px 0px 2px;">Days</span>
382
        <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.datasource.standard.timeout_info" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
383 384 385 386 387 388 389 390 391
        <%  if (errors.get("connectionTimeout") != null) { %>
            <span class="jive-error-text">
            <%= errors.get("connectionTimeout") %>
            </span>
        <%  } %>
    </td>
</tr>
</table>

392
<br>
393

394 395
		<div align="right"><div class="jive-description" style="padding-bottom:10px;">
			<fmt:message key="setup.datasource.standard.note" /></div>
396 397 398
			<input type="Submit" name="continue" value="<fmt:message key="global.continue" />" id="jive-setup-save" border="0">
		</div>
	</form>
399

400 401
	</div>
	<!-- END jive-contentBox -->
402 403


404 405
</body>
</html>