use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class GetBuildStatus method perform.
public static String perform(MobileApplication mobileApplication, String platformName, HttpServletRequest request) throws Exception {
String mobileBuilderPlatformURL = EnginePropertiesManager.getProperty(PropertyName.MOBILE_BUILDER_PLATFORM_URL);
URL url = new URL(mobileBuilderPlatformURL + "/getstatus");
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(url.getHost());
HttpState httpState = new HttpState();
Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url);
PostMethod method = new PostMethod(url.toString());
try {
HeaderName.ContentType.setRequestHeader(method, MimeType.WwwForm.value());
method.setRequestBody(new NameValuePair[] { new NameValuePair("application", mobileApplication.getComputedApplicationName()), new NameValuePair("platformName", platformName), new NameValuePair("auth_token", mobileApplication.getComputedAuthenticationToken()), new NameValuePair("endpoint", mobileApplication.getComputedEndpoint(request)) });
int methodStatusCode = Engine.theApp.httpClient.executeMethod(hostConfiguration, method, httpState);
InputStream methodBodyContentInputStream = method.getResponseBodyAsStream();
byte[] httpBytes = IOUtils.toByteArray(methodBodyContentInputStream);
String sResult = new String(httpBytes, "UTF-8");
if (methodStatusCode != HttpStatus.SC_OK) {
throw new ServiceException("Unable to get building status for application '" + mobileApplication.getProject() + "' (final app name: '" + mobileApplication.getComputedApplicationName() + "').\n" + sResult);
}
return sResult;
} finally {
method.releaseConnection();
}
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class GetPackage method perform.
public static HttpMethod perform(MobileApplication mobileApplication, String platformName, HttpServletRequest request) throws Exception {
String finalApplicationName = mobileApplication.getComputedApplicationName();
String mobileBuilderPlatformURL = EnginePropertiesManager.getProperty(PropertyName.MOBILE_BUILDER_PLATFORM_URL);
PostMethod method;
int methodStatusCode;
InputStream methodBodyContentInputStream;
URL url = new URL(mobileBuilderPlatformURL + "/getpackage");
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(new URI(url.toString(), true));
HttpState httpState = new HttpState();
Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url);
method = new PostMethod(url.toString());
HeaderName.ContentType.setRequestHeader(method, MimeType.WwwForm.value());
method.setRequestBody(new NameValuePair[] { new NameValuePair("application", finalApplicationName), new NameValuePair("platformName", platformName), new NameValuePair("auth_token", mobileApplication.getComputedAuthenticationToken()), new NameValuePair("endpoint", mobileApplication.getComputedEndpoint(request)) });
methodStatusCode = Engine.theApp.httpClient.executeMethod(hostConfiguration, method, httpState);
methodBodyContentInputStream = method.getResponseBodyAsStream();
if (methodStatusCode != HttpStatus.SC_OK) {
byte[] httpBytes = IOUtils.toByteArray(methodBodyContentInputStream);
String sResult = new String(httpBytes, "UTF-8");
throw new ServiceException("Unable to get package for project '" + mobileApplication.getProject() + "' (final app name: '" + finalApplicationName + "').\n" + sResult);
}
return method;
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class GetIcon method writeResponseResult.
@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws IOException, ServiceException {
String className = request.getParameter("className");
String large = request.getParameter("large");
if (className == null || !className.startsWith("com.twinsoft.convertigo.beans"))
throw new ServiceException("Must provide className parameter", null);
try {
BeanInfo bi = CachedIntrospector.getBeanInfo(GenericUtils.<Class<? extends DatabaseObject>>cast(Class.forName(className)));
int iconType = large != null && large.equals("true") ? BeanInfo.ICON_COLOR_32x32 : BeanInfo.ICON_COLOR_16x16;
IOUtils.copy(bi.getBeanDescriptor().getBeanClass().getResourceAsStream(MySimpleBeanInfo.getIconName(bi, iconType)), response.getOutputStream());
} catch (Exception e) {
throw new ServiceException("Icon unreachable", e);
}
Engine.logAdmin.info("The image has been exported");
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class Configure method restartCacheManager.
private void restartCacheManager() throws ServiceException {
try {
Engine.theApp.cacheManager.destroy();
String cacheManagerClassName = EnginePropertiesManager.getProperty(PropertyName.CACHE_MANAGER_CLASS);
Engine.logAdmin.debug("Cache manager class: " + cacheManagerClassName);
Engine.theApp.cacheManager = (CacheManager) Class.forName(cacheManagerClassName).getConstructor().newInstance();
Engine.theApp.cacheManager.init();
} catch (Exception e) {
String message = "Unable to restart the cache manager.";
Engine.logAdmin.error(message, e);
throw new ServiceException(message, e);
}
}
use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.
the class Configure method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
this.document = document;
root = document.getDocumentElement();
cacheType = request.getParameter("cacheType");
if (cacheType != null && cacheType.equals("database")) {
cacheType = cacheManagerDatabaseType;
} else {
cacheType = cacheManagerFileType;
}
dbCachePropFileName = Engine.CONFIGURATION_PATH + DatabaseCacheManager.DB_PROP_FILE_NAME;
PropertiesUtils.load(dbCacheProp, dbCachePropFileName);
try {
saveProps(request);
} catch (Exception e) {
throw new ServiceException("Unable to save the cache manager properties.", e.getCause());
}
String create = request.getParameter("create");
if (create != null && cacheType.equals(cacheManagerDatabaseType)) {
boolean dbCreationSupport = true;
String databaseDriver = dbCacheProp.getProperty("jdbc.driver.class_name");
String sqlCreateTableFileName = "/create_cache_table_";
String sqlTest = "select * from CacheTable limit 1";
String sqlRequest = "";
if (sqlServerDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "sqlserver.sql";
sqlTest = "select top 1 * FROM CacheTable";
} else if (mySQLDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "mysql.sql";
sqlTest = "select * from CacheTable limit 1";
} else if (oracleDriver.equals(databaseDriver)) {
sqlCreateTableFileName += "oracle.sql";
sqlTest = "select * from CacheTable where rownum <= 1";
dbCreationSupport = false;
}
if (dbCreationSupport) {
// Create Cache table into Database
String fileName = Engine.WEBAPP_PATH + "/WEB-INF/sql" + sqlCreateTableFileName;
BufferedReader br = new BufferedReader(new FileReader(fileName.toString()));
try {
SqlRequester sqlRequester = null;
java.sql.Statement statement = null;
while ((sqlRequest = br.readLine()) != null) {
try {
sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
sqlRequester.open();
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest = sqlRequest.substring(0, sqlRequest.length() - 1);
sqlRequest = sqlRequest.replaceAll("CacheTable", cacheTableName);
statement = sqlRequester.connection.createStatement();
statement.execute(sqlRequest);
ServiceUtils.addMessage(document, root, "Request: \"" + sqlRequest + "\" executed.", "message");
} finally {
if (statement != null) {
statement.close();
}
sqlRequester.close();
}
}
ServiceUtils.addMessage(document, root, "Cache table created.", "message");
} catch (Exception e) {
throw new ServiceException("Unable to create the cache table.", e);
} finally {
br.close();
}
}
// Test if Cache table exist
SqlRequester sqlRequester = null;
java.sql.Statement statement = null;
try {
sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
sqlRequester.open();
String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
sqlRequest = sqlTest.replaceAll("CacheTable", cacheTableName);
statement = sqlRequester.connection.createStatement();
statement.execute(sqlRequest);
ServiceUtils.addMessage(document, root, "Request: \"" + sqlRequest + "\" executed.", "message");
ServiceUtils.addMessage(document, root, "Cache table tested.", "message");
} catch (Exception e) {
throw new ServiceException("Unable to test the cache table.", e);
} finally {
if (statement != null) {
statement.close();
}
sqlRequester.close();
}
}
restartCacheManager();
}
Aggregations