All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.main.java.org.kawanfw.sql.servlet.ServerSqlManagerDoGetTester Maven / Gradle / Ivy

Go to download

AceQL HTTP is a framework of REST like http APIs that allow to access to remote SQL databases over http from any device that supports http. AceQL HTTP is provided with three client SDK: - The AceQL C# Client SDK allows to wrap the HTTP APIs using Microsoft SQL Server like calls in their code, just like they would for a local database. - The AceQL Java Client JDBC Driver allows to wrap the HTTP APIs using JDBC calls in their code, just like they would for a local database. - The AceQL Python Client SDK allows SQL calls to be encoded with standard unmodified DB-API 2.0 syntax

There is a newer version: 12.2
Show newest version
/*
 * This file is part of AceQL HTTP.
 * AceQL HTTP: SQL Over HTTP
 * Copyright (C) 2020,  KawanSoft SAS
 * (http://www.kawansoft.com). All rights reserved.
 *
 * AceQL HTTP is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * AceQL HTTP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 *
 * Any modifications to this file must keep this entire header
 * intact.
 */
package org.kawanfw.sql.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Date;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.kawanfw.sql.api.server.DatabaseConfigurationException;
import org.kawanfw.sql.api.server.DefaultDatabaseConfigurator;
import org.kawanfw.sql.tomcat.ServletParametersStore;
import org.kawanfw.sql.tomcat.TomcatSqlModeStore;
import org.kawanfw.sql.util.FrameworkDebug;
import org.kawanfw.sql.version.Version;

/**
 * @author Nicolas de Pomereu Test ServerSqlManager doGet method
 */
public class ServerSqlManagerDoGetTester {

    private static boolean DEBUG = FrameworkDebug.isSet(ServerSqlManager.class);

    /** Color used by servlet display in all KawanSoft Frameworks */
    public static final String KAWANSOFT_COLOR = "E7403E";

    public static String CR_LF = System.getProperty("line.separator");
    public static final String DATABASE_CONFIGURATOR_CLASS_NAME = "databaseConfiguratorClassName";

    /** The init error message trapped */
    private String initErrrorMesage = "";

    public void doGetTest(HttpServletResponse response, String servletName, Exception exception

    ) throws IOException {

	response.setContentType("text/html");
	PrintWriter out = response.getWriter();

	debug("doGetTest begin");

	try {
	    // ok for servlet display
	    String status = "" + "OK & Running.";

	    // Test configurators, only if not already thrown Exception:

	    if (exception != null) {

		debug("exception != null");

		if (TomcatSqlModeStore.isTomcatEmbedded()) {
		    // status = initErrrorMesage + CR_LF + stackTrace;
		    status = exception.toString();
		    out.println(status);
		    debug("after out.println(status)");
		    return;

		} else {

		    String exceptionDisplay = null;

		    if (exception instanceof DatabaseConfigurationException) {
			exceptionDisplay = exception.getMessage();
		    } else {
			exceptionDisplay = ExceptionUtils.getStackTrace(exception);
		    }

		    BufferedReader bufferedReader = new BufferedReader(new StringReader(exceptionDisplay));
		    StringBuffer sb = new StringBuffer();

		    String line = null;
		    while ((line = bufferedReader.readLine()) != null) {
			// All subsequent lines contain the result
			sb.append(line);
			sb.append("
"); } status = "
" + initErrrorMesage + "
" + sb.toString(); } } printResult(servletName, out, status); } catch (Exception e) { e.printStackTrace(out); } } /** * @param servletName * @param out * @param status */ private void printResult(String servletName, PrintWriter out, String status) { Set databases = ServletParametersStore.getDatabaseNames(); out.println(""); out.println("
"); out.println(""); out.println(""); out.println("" + Version.getServerVersion() + ""); out.println("
"); out.println("
"); out.println(servletName + " Servlet Configuration"); out.println("
"); out.println("

"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); printDatabaseConfigurators(out, databases); out.println("
Database Name Configurator Parameter Configurator Value
"); out.println("

"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
SQL Configuration Status
" + status + "
"); out.println("
"); } /** * @param out * @param databases */ private void printDatabaseConfigurators(PrintWriter out, Set databases) { for (String database : databases) { String databaseConfiguratorClassName = ServletParametersStore.getInitParameter(database, DATABASE_CONFIGURATOR_CLASS_NAME); if (databaseConfiguratorClassName == null || databaseConfiguratorClassName.isEmpty()) { databaseConfiguratorClassName = DefaultDatabaseConfigurator.class.getName(); } out.println(""); out.println(" " + database + ""); out.println(" " + DATABASE_CONFIGURATOR_CLASS_NAME + ""); out.println(" " + databaseConfiguratorClassName + ""); out.println(""); } } /** * debug */ public static void debug(String s) { if (DEBUG) { System.out.println(new Date() + " " + s); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy