setup-datasource-standard.jsp 13.4 KB
Newer Older
1 2
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Matt Tucker's avatar
Matt Tucker committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<%--
  -	$RCSfile$
  -	$Revision$
  -	$Date$
--%>

<%@ page import="org.jivesoftware.util.ParamUtils,
                 java.util.*,
                 java.beans.BeanInfo,
                 java.beans.Introspector,
                 java.beans.PropertyDescriptor,
                 org.jivesoftware.messenger.JiveGlobals,

                 java.sql.Connection,
                 java.io.File,
                 java.sql.Statement,
                 java.sql.SQLException,

                 org.jivesoftware.database.DbConnectionManager,
                 org.jivesoftware.database.DefaultConnectionProvider,
                 org.jivesoftware.database.DefaultConnectionProvider"
%>

Bill Lynch's avatar
Bill Lynch committed
26
<%@ include file="setup-global.jspf" %>
27
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Matt Tucker's avatar
Matt Tucker committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<%  // 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,"minConnections",-1);
    double connectionTimeout = ParamUtils.getDoubleParameter(request,"connectionTimeout",0.0);

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

    // handle a continue request
    Map errors = new HashMap();
    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 {
50
                loadClass(driver);
Matt Tucker's avatar
Matt Tucker committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
            }
            catch (Throwable t) {
                errors.put("driver","Unable to load 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 < 0) {
            errors.put("minConnections","Please enter a valid minimum number of connections.");
        }
        if (maxConnections < 0) {
            errors.put("maxConnections","Please enter a valid maximum number of connections.");
        }
        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:
77
            JiveGlobals.setXMLProperty("connectionProvider.className",
Matt Tucker's avatar
Matt Tucker committed
78 79 80 81 82 83 84 85 86 87 88
                    "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);

Matt Tucker's avatar
Matt Tucker committed
89 90 91 92 93 94 95 96 97 98
                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",
Matt Tucker's avatar
Matt Tucker committed
99 100 101 102
                Double.toString(connectionTimeout));
            }
            catch (Exception e) {
                errors.put("general","Setting connection properties failed - please see the error "
Matt Tucker's avatar
Matt Tucker committed
103
                        + "log located in messengerHome/logs for more details.");
Matt Tucker's avatar
Matt Tucker committed
104 105 106 107 108
                Log.error(e);
            }
            // No errors setting the properties, so test the connection
            DbConnectionManager.setConnectionProvider(conProvider);
            if (testConnection(errors)) {
109
                // Update the sidebar status
110 111
                session.setAttribute("jive.setup.sidebar.3","done");
                session.setAttribute("jive.setup.sidebar.4","in_progress");
112
                // Success, move on
113 114
                response.sendRedirect("setup-admin-settings.jsp");
                return;
115
            }
Matt Tucker's avatar
Matt Tucker committed
116 117 118 119 120
        }
    }

    if (!doContinue) {
        // reset values of jdbc driver from props file
121 122 123 124
        driver = JiveGlobals.getXMLProperty("database.defaultProvider.driver");
        serverURL = JiveGlobals.getXMLProperty("database.defaultProvider.serverURL");
        username = JiveGlobals.getXMLProperty("database.defaultProvider.username");
        password = JiveGlobals.getXMLProperty("database.defaultProvider.password");
Matt Tucker's avatar
Matt Tucker committed
125 126
        try {
            minConnections = Integer.parseInt(
127
                    JiveGlobals.getXMLProperty("database.defaultProvider.minConnections"));
Matt Tucker's avatar
Matt Tucker committed
128 129 130 131 132 133
        }
        catch (Exception e) {
            minConnections = 5;
        }
        try {
            maxConnections = Integer.parseInt(
134
                    JiveGlobals.getXMLProperty("database.defaultProvider.maxConnections"));
Matt Tucker's avatar
Matt Tucker committed
135 136 137 138 139 140
        }
        catch (Exception e) {
            maxConnections = 15;
        }
        try {
            connectionTimeout = Double.parseDouble(
141
                    JiveGlobals.getXMLProperty("database.defaultProvider.connectionTimeout"));
Matt Tucker's avatar
Matt Tucker committed
142 143 144 145 146 147 148
        }
        catch (Exception e) {
            connectionTimeout = 1.0;
        }
    }
%>

149
<%@ include file="setup-header.jspf" %>
Matt Tucker's avatar
Matt Tucker committed
150 151

<p class="jive-setup-page-header">
152
<fmt:message key="setup.datasource.standard.title" />
Matt Tucker's avatar
Matt Tucker committed
153 154 155
</p>

<p>
Gaston Dombiak's avatar
Gaston Dombiak committed
156
<fmt:message key="setup.datasource.standard.info" /> <fmt:message key="title" />.
Matt Tucker's avatar
Matt Tucker committed
157 158
</p>

159
<p>
Gaston Dombiak's avatar
Gaston Dombiak committed
160
<b><fmt:message key="setup.datasource.standard.info2" /> </b><fmt:message key="setup.datasource.standard.info3" /><tt>[MESSENGER_HOME]/resources/database</tt>.
161 162
</p>

Matt Tucker's avatar
Matt Tucker committed
163 164 165 166 167 168 169 170 171
<%  if (errors.size() > 0) { %>

    <span class="jive-error-text">
    <%  if (errors.get("general") != null) { %>

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

    <%  } else { %>

172
        <fmt:message key="setup.datasource.standard.failed_connect" />
Matt Tucker's avatar
Matt Tucker committed
173 174 175 176 177 178 179 180

    <%  } %>
    </span>

<%  } %>

<%  // DB preset data
    List presets = new ArrayList();
Matt Tucker's avatar
Matt Tucker committed
181
    presets.add(new String[]{"MySQL","com.mysql.jdbc.Driver","jdbc:mysql://[host-name]:3306/[database-name]"});
Matt Tucker's avatar
Matt Tucker committed
182
    presets.add(new String[]{"Oracle","oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@[host-name]:1521:[SID]"});
183
    presets.add(new String[]{"MSSQL","com.microsoft.jdbc.sqlserver.SQLServerDriver","jdbc:microsoft:sqlserver://[host-name]:1433;databasename=[database-name]"});
Matt Tucker's avatar
Matt Tucker committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    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++) {
        String[] data = (String[])presets.get(i);
%>
    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>

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

<table cellpadding="3" cellspacing="2" border="0">
<tr>
    <td colspan="2">
        Database Driver Presets:
        <select size="1" name="presets" onchange="populate(this.options[this.selectedIndex].value)">
216
            <option value=""><fmt:message key="setup.datasource.standard.pick_database" />
Matt Tucker's avatar
Matt Tucker committed
217 218 219 220 221 222 223 224 225 226 227
            <%  for (int i=0; i<presets.size(); i++) {
                    String[] data = (String[])presets.get(i);
            %>
                <option value="<%= i %>"> &#149; <%= data[0] %>
            <%  } %>
        </select>
        <br><br>
    </td>
</tr>
<tr valign="top">
    <td class="jive-label" nowrap>
228
        <fmt:message key="setup.datasource.standard.jdbc" />
Matt Tucker's avatar
Matt Tucker committed
229 230 231 232 233 234
    </td>
    <td>
        <input type="text" name="driver" size="50" maxlength="150"
         value="<%= ((driver != null) ? driver : "") %>">
        <span class="jive-description">
        <br>
235
        <fmt:message key="setup.datasource.standard.jdbc_info" />
Matt Tucker's avatar
Matt Tucker committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249
        </span>
        <%  if (errors.get("driver") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("driver") %>
            </span>

        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
    <td class="jive-label" nowrap>
250
        <fmt:message key="setup.datasource.standard.url" />
Matt Tucker's avatar
Matt Tucker committed
251 252 253 254 255 256
    </td>
    <td>
        <input type="text" name="serverURL" size="50" maxlength="250"
         value="<%= ((serverURL != null) ? serverURL : "") %>">
        <span class="jive-description">
        <br>
257
        <fmt:message key="setup.datasource.standard.valid_url" />
Matt Tucker's avatar
Matt Tucker committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271
        </span>
        <%  if (errors.get("serverURL") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("serverURL") %>
            </span>

        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
    <td class="jive-label" nowrap>
272
        <fmt:message key="setup.datasource.standard.username" />
Matt Tucker's avatar
Matt Tucker committed
273 274 275 276 277 278
    </td>
    <td>
        <input type="text" name="username" size="20" maxlength="50"
         value="<%= ((username != null) ? username : "") %>">
        <span class="jive-description">
        <br>
279
        <fmt:message key="setup.datasource.standard.username_info" />
Matt Tucker's avatar
Matt Tucker committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293
        </span>
        <%  if (errors.get("username") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("username") %>
            </span>

        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
    <td class="jive-label" nowrap>
294
        <fmt:message key="setup.datasource.standard.password" />
Matt Tucker's avatar
Matt Tucker committed
295 296 297 298 299 300
    </td>
    <td>
        <input type="password" name="password" size="20" maxlength="50"
         value="<%= ((password != null) ? password : "") %>">
        <span class="jive-description">
        <br>
301
        <fmt:message key="setup.datasource.standard.password_info" />
Matt Tucker's avatar
Matt Tucker committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315
        </span>
        <%  if (errors.get("password") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("password") %>
            </span>

        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
    <td class="jive-label" nowrap>
316
        <fmt:message key="setup.datasource.standard.connect" />
Matt Tucker's avatar
Matt Tucker committed
317 318
    </td>
    <td>
319
        <fmt:message key="setup.datasource.standard.min" /> <input type="text" name="minConnections" size="5" maxlength="5"
Matt Tucker's avatar
Matt Tucker committed
320 321
         value="<%= ((minConnections != -1) ? ""+minConnections : "") %>">
        &nbsp;
322
        <fmt:message key="setup.datasource.standard.max" /> <input type="text" name="maxConnections" size="5" maxlength="5"
Matt Tucker's avatar
Matt Tucker committed
323 324 325
         value="<%= ((maxConnections != -1) ? ""+maxConnections : "") %>">
        <span class="jive-description">
        <br>
326
        <fmt:message key="setup.datasource.standard.pool" />
Matt Tucker's avatar
Matt Tucker committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
        </span>
        <%  if (errors.get("minConnections") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("minConnections") %>
            </span>

        <%  } %>
        <%  if (errors.get("maxConnections") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("maxConnections") %>
            </span>

        <%  } %>
    </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr valign="top">
    <td class="jive-label" nowrap>
349
        <fmt:message key="setup.datasource.standard.timeout" />
Matt Tucker's avatar
Matt Tucker committed
350 351 352 353 354 355
    </td>
    <td>
        <input type="text" name="connectionTimeout" size="5" maxlength="5"
         value="<%= connectionTimeout %>">
        <span class="jive-description">
        <br>
356
        <fmt:message key="setup.datasource.standard.timeout_info" />
Matt Tucker's avatar
Matt Tucker committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
        </span>
        <%  if (errors.get("connectionTimeout") != null) { %>

            <br>
            <span class="jive-error-text">
            <%= errors.get("connectionTimeout") %>
            </span>

        <%  } %>
    </td>
</tr>
</table>

<br><br>

<hr size="0">

<div align="right">
    <input type="submit" name="continue" value=" Continue ">
    <br>
377
    <fmt:message key="setup.datasource.standard.note" />
Matt Tucker's avatar
Matt Tucker committed
378 379 380 381 382
</div>

</form>

<%@ include file="setup-footer.jsp" %>