Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
package psiprobe.controllers.sql;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.catalina.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import psiprobe.controllers.AbstractContextHandlerController;
/**
* Verifies if a database connection can be established through a given datasource. Displays basic
* information about the database.
*/
@Controller
public class ConnectionTestController extends AbstractContextHandlerController {
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(ConnectionTestController.class);
@RequestMapping(path = "/sql/connection.ajax")
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws Exception {
return super.handleRequest(request, response);
}
@Override
protected ModelAndView handleContext(String contextName, Context context,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String resourceName = ServletRequestUtils.getStringParameter(request, "resource");
DataSource dataSource = null;
try {
dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context,
resourceName, getContainerWrapper());
} catch (NamingException e) {
request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage(
"probe.src.dataSourceTest.resource.lookup.failure", new Object[] {resourceName}));
logger.trace("", e);
}
if (dataSource == null) {
request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage(
"probe.src.dataSourceTest.resource.lookup.failure", new Object[] {resourceName}));
} else {
try {
// TODO: use Spring's jdbc template?
try (Connection conn = dataSource.getConnection()) {
DatabaseMetaData md = conn.getMetaData();
List