Search in sources :

Example 16 with ServiceException

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();
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) InputStream(java.io.InputStream) HttpState(org.apache.commons.httpclient.HttpState) URL(java.net.URL)

Example 17 with ServiceException

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;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) InputStream(java.io.InputStream) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpState(org.apache.commons.httpclient.HttpState) URI(org.apache.commons.httpclient.URI) URL(java.net.URL)

Example 18 with ServiceException

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");
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) BeanInfo(java.beans.BeanInfo) MySimpleBeanInfo(com.twinsoft.convertigo.beans.core.MySimpleBeanInfo) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) IOException(java.io.IOException)

Example 19 with ServiceException

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);
    }
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException)

Example 20 with ServiceException

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();
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) SqlRequester(com.twinsoft.convertigo.engine.util.SqlRequester) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException)

Aggregations

ServiceException (com.twinsoft.convertigo.engine.admin.services.ServiceException)21 File (java.io.File)8 Element (org.w3c.dom.Element)7 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)6 IOException (java.io.IOException)6 AuthenticationException (com.twinsoft.convertigo.engine.AuthenticationException)5 EngineException (com.twinsoft.convertigo.engine.EngineException)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 JSONException (org.codehaus.jettison.json.JSONException)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 BufferedReader (java.io.BufferedReader)2 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2 HashMap (java.util.HashMap)2 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)2 HttpState (org.apache.commons.httpclient.HttpState)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2