
org.kawanfw.sql.servlet.ServerSqlManagerDoGetTester Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aceql-http Show documentation
Show all versions of aceql-http Show documentation
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 four 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 SDK 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
/*
* Copyright (c)2022 KawanSoft S.A.S. All rights reserved.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2026-11-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
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.servlet.injection.properties.ConfPropertiesStore;
import org.kawanfw.sql.tomcat.TomcatSqlModeStore;
import org.kawanfw.sql.util.FrameworkDebug;
import org.kawanfw.sql.version.VersionWrapper;
/**
* @author Nicolas de Pomereu Test ServerSqlManager doGet method
*/
public class ServerSqlManagerDoGetTester {
private static boolean DEBUG = FrameworkDebug.isSet(ServerSqlManagerDoGetTester.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 servletCallName, 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(servletCallName, out, status);
} catch (Exception e) {
e.printStackTrace(out);
}
}
/**
* @param servletCallName
* @param out
* @param status
*/
private void printResult(String servletCallName, PrintWriter out, String status) {
Set databases = ConfPropertiesStore.get().getDatabaseNames();
out.println("");
out.println("
");
out.println("");
out.println("");
out.println("" + VersionWrapper.getServerVersion() + "");
out.println("
");
out.println("
");
out.println(servletCallName + " Servlet Configuration");
out.println("");
out.println("
");
out.println("");
out.println("");
out.println(" Database Name ");
out.println(" Configurator Parameter ");
out.println(" Configurator Value ");
out.println(" ");
printDatabaseConfigurators(out, databases);
out.println("
");
out.println("
");
out.println("");
out.println("");
out.println(" SQL Configuration Status ");
out.println(" ");
out.println("");
out.println(" " + status + " ");
out.println(" ");
out.println("
");
out.println("");
}
/**
* @param out
* @param databases
*/
private void printDatabaseConfigurators(PrintWriter out, Set databases) {
for (String database : databases) {
String databaseConfiguratorClassName = ConfPropertiesStore.get().getDatabaseConfiguratorClassName(database);
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 - 2025 Weber Informatics LLC | Privacy Policy