use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class Save method getServiceResult.
@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
String qname = request.getParameter("qname");
DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
Element response = document.createElement("response");
if (dbo != null) {
try {
Engine.theApp.databaseObjectsManager.exportProject(dbo.getProject());
response.setAttribute("status", "success");
response.setAttribute("message", "Successfully saved project.");
} catch (EngineException e) {
throw e;
}
} else {
throw new EngineException("The project does not exist.");
}
document.getDocumentElement().appendChild(response);
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class GoogleAnalyticsTicketManager method prepareHttpClient.
private HttpClient prepareHttpClient(String[] url) throws EngineException, MalformedURLException {
final Pattern scheme_host_pattern = Pattern.compile("https://(.*?)(?::([\\d]*))?(/.*|$)");
HttpClient client = new HttpClient();
HostConfiguration hostConfiguration = client.getHostConfiguration();
HttpState httpState = new HttpState();
client.setState(httpState);
if (proxyManager != null) {
proxyManager.getEngineProperties();
proxyManager.setProxy(hostConfiguration, httpState, new URL(url[0]));
}
Matcher matcher = scheme_host_pattern.matcher(url[0]);
if (matcher.matches()) {
String host = matcher.group(1);
String sPort = matcher.group(2);
int port = 443;
try {
port = Integer.parseInt(sPort);
} catch (Exception e) {
}
try {
Protocol myhttps = new Protocol("https", MySSLSocketFactory.getSSLSocketFactory(null, null, null, null, true), port);
hostConfiguration.setHost(host, port, myhttps);
url[0] = matcher.group(3);
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
return client;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class DatabaseCacheManager method storeResponse.
protected CacheEntry storeResponse(Document response, String requestString, long expiryDate) throws EngineException {
try {
storeWeakResponse(response, requestString);
Engine.logCacheManager.debug("Trying to store the response in the cache Database");
sqlRequester.checkConnection();
StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_STORE_RESPONSE));
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest.replace("CacheTable", cacheTableName);
String jdbcURL = sqlRequester.getProperty(SqlRequester.PROPERTIES_JDBC_URL);
boolean isSqlServerDatabase = jdbcURL.indexOf(":sqlserver:") != -1;
boolean isOracleServerDatabase = jdbcURL.indexOf(":oracle:") != -1;
if (!isSqlServerDatabase) {
sqlRequest.replace("[Transaction]", "Transaction");
}
String xml = XMLUtils.prettyPrintDOM(response);
sqlRequest.replace("{Xml}", escapeString(xml));
sqlRequest.replace("{RequestString}", escapeString(requestString));
sqlRequest.replace("{ExpiryDate}", Long.toString(expiryDate));
Element documentElement = response.getDocumentElement();
String project = documentElement.getAttribute("project");
sqlRequest.replace("{Project}", project);
String transaction = documentElement.getAttribute("transaction");
sqlRequest.replace("{Transaction}", transaction);
String sSqlRequest = sqlRequest.toString();
Engine.logCacheManager.debug("SQL: " + sSqlRequest);
// INSERT INTO CacheTable (Xml, ExpiryDate, RequestString, Project, [Transaction]) VALUES (XMLTYPE(?), {ExpiryDate}, '{RequestString}', '{Project}', '{Transaction}')
if (isOracleServerDatabase && sSqlRequest.toUpperCase().indexOf("XMLTYPE(?)") != -1) {
PreparedStatement statement = null;
java.sql.Clob clb = null;
try {
xml = escapeString(xml);
clb = sqlRequester.connection.createClob();
clb.setString(1, xml);
statement = sqlRequester.connection.prepareStatement(sSqlRequest);
statement.setClob(1, clb);
int nResult = statement.executeUpdate();
Engine.logCacheManager.debug(nResult + " row(s) inserted (Xml length=" + xml.length() + ").");
} finally {
if (clb != null) {
clb.free();
}
if (statement != null) {
statement.close();
}
}
} else // Other cases
// INSERT INTO CacheTable (Xml, ExpiryDate, RequestString, Project, [Transaction]) VALUES ('{Xml}', {ExpiryDate}, '{RequestString}', '{Project}', '{Transaction}')
{
Statement statement = null;
try {
statement = sqlRequester.connection.createStatement();
int nResult = statement.executeUpdate(sSqlRequest);
Engine.logCacheManager.debug(nResult + " row(s) inserted.");
} finally {
if (statement != null) {
statement.close();
}
}
}
DatabaseCacheEntry cacheEntry = new DatabaseCacheEntry();
cacheEntry.requestString = requestString;
cacheEntry.id = getId(requestString);
cacheEntry.expiryDate = expiryDate;
Engine.logCacheManager.debug("The response has been stored: [" + cacheEntry + "]");
storeWeakEntry(cacheEntry);
return cacheEntry;
} catch (Exception e) {
throw new EngineException("Unable to store the response! (requestString: " + requestString + ")", e);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class DatabaseCacheManager method init.
public void init() throws EngineException {
super.init();
try {
sqlRequester = new SqlRequester(DB_PROP_FILE_NAME);
sqlRequester.open();
} catch (IOException e) {
throw new EngineException("[DatabaseCacheManager] Unable to load the SQLRequester properties file: " + DB_PROP_FILE_NAME, e);
} catch (SQLException e) {
throw new EngineException("[DatabaseCacheManager] Unable to establish connection with the dataBase.", e);
} catch (ClassNotFoundException e) {
throw new EngineException("[DatabaseCacheManager] Unable to load JDBC Driver.", e);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class FileCacheManager method removeStoredResponseImpl.
protected synchronized void removeStoredResponseImpl(CacheEntry cacheEntry) throws EngineException {
FileCacheEntry fileCacheEntry = (FileCacheEntry) cacheEntry;
// Cache entry for index? Then ignore
if (cacheEntry.requestString == null)
return;
File file = new File(fileCacheEntry.fileName);
if ((file.exists()) && (!file.delete())) {
throw new EngineException("Unable to remove the cache entry [" + cacheEntry.toString() + "] from the cache!");
}
Engine.logCacheManager.debug("The cache entry [" + cacheEntry.toString() + "] has been successfully removed.");
}
Aggregations