Search in sources :

Example 21 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 {
    Element rootElement = document.getDocumentElement();
    File file = new File(Engine.CERTIFICATES_PATH + CertificateManager.STORES_PROPERTIES_FILE_NAME);
    synchronized (Engine.CERTIFICATES_PATH) {
        Properties storesProperties = PropertiesUtils.load(file);
        // Creation of the vector containing the certificates and the one containing the links
        java.util.List<String> linksVector = new ArrayList<String>();
        String tmp = "";
        Enumeration<?> storesKeysEnum = storesProperties.propertyNames();
        while (storesKeysEnum.hasMoreElements()) {
            tmp = (String) storesKeysEnum.nextElement();
            if (tmp.indexOf("projects.") != 0 && tmp.indexOf("tas.") != 0) {
            // if ( !tmp.endsWith(".type") && !tmp.endsWith(".group") ){
            // certifVector.add(tmp);
            // }
            } else
                linksVector.add(tmp);
        }
        Collections.sort(linksVector);
        File certifDirectory = new File(Engine.CERTIFICATES_PATH);
        File[] certifList = certifDirectory.listFiles();
        ArrayList<String> possibleCertificates = new ArrayList<String>();
        for (int i = 0; i < certifList.length; i++) {
            possibleCertificates.add(certifList[i].getName());
        }
        String certifName = "";
        String certifPwd = "";
        String group;
        // Properties newStoresProperties = new Properties();
        int i = 0;
        while (((certifName = (String) request.getParameter("name_" + i)) != null) && ((certifPwd = (String) request.getParameter("pwd_" + i)) != null)) {
            if (possibleCertificates.contains(certifName)) {
                storesProperties.setProperty(certifName, Crypto2.encodeToHexString(certifPwd));
                storesProperties.setProperty(certifName + ".type", (String) request.getParameter("type_" + i));
                group = (String) request.getParameter("group_" + i);
                if (group != null) {
                    storesProperties.setProperty(certifName + ".group", group);
                }
            } else {
                throw new ServiceException("You tried to configure an uninstalled certificate!");
            }
            i++;
        }
        storesKeysEnum = Collections.enumeration(linksVector);
        while (storesKeysEnum.hasMoreElements()) {
            certifName = (String) storesKeysEnum.nextElement();
            storesProperties.setProperty(certifName, storesProperties.getProperty(certifName));
        }
        PropertiesUtils.store(storesProperties, file);
    }
    ServiceUtils.addMessage(document, rootElement, "The certificates have successfully been updated.", "message");
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File)

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