Search in sources :

Example 6 with ServiceException

use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.

the class GetBuildStatus method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String project = Keys.project.value(request);
    MobileApplication mobileApplication = getMobileApplication(project);
    if (mobileApplication == null) {
        throw new ServiceException("no such mobile application");
    } else {
        boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
        if (!bTpPrivateRole && mobileApplication.getAccessibility() == Accessibility.Private) {
            throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
        }
    }
    String platformName = Keys.platform.value(request);
    String sResult = perform(mobileApplication, platformName, request);
    JSONObject jsonResult = new JSONObject(sResult);
    Element statusElement = document.createElement("build");
    statusElement.setAttribute(Keys.project.name(), project);
    statusElement.setAttribute(Keys.platform.name(), platformName);
    if (jsonResult.has(platformName + "_status")) {
        statusElement.setAttribute("status", jsonResult.getString(platformName + "_status"));
    } else {
        statusElement.setAttribute("status", "none");
    }
    if (jsonResult.has(platformName + "_bn")) {
        statusElement.setAttribute("bn", jsonResult.getString(platformName + "_bn"));
        statusElement.setAttribute("bp_url", EnginePropertiesManager.getProperty(PropertyName.MOBILE_BUILDER_PLATFORM_URL).replaceFirst("(.*)/.*?$", "$1"));
    }
    if (jsonResult.has(platformName + "_error")) {
        statusElement.setAttribute("error", jsonResult.getString(platformName + "_error"));
    }
    statusElement.setAttribute("version", jsonResult.has("version") ? jsonResult.getString("version") : "n/a");
    statusElement.setAttribute("phonegap_version", jsonResult.has("phonegap_version") ? jsonResult.getString("phonegap_version") : "n/a");
    statusElement.setAttribute("revision", jsonResult.has("revision") ? jsonResult.getString("revision") : "n/a");
    statusElement.setAttribute("endpoint", jsonResult.has("endpoint") ? jsonResult.getString("endpoint") : "n/a");
    document.getDocumentElement().appendChild(statusElement);
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) JSONObject(org.codehaus.jettison.json.JSONObject) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) Element(org.w3c.dom.Element)

Example 7 with ServiceException

use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.

the class GetLocalRevision method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String project = Keys.project.value(request);
    MobileApplication mobileApplication = GetBuildStatus.getMobileApplication(project);
    if (mobileApplication == null) {
        throw new ServiceException("no such mobile application");
    } else {
        boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
        if (!bTpPrivateRole && mobileApplication.getAccessibility() == Accessibility.Private) {
            throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
        }
    }
    String platformName = Keys.platform.value(request);
    MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(request, "mobile/flashupdate", project, platformName);
    mobileResourceHelper.prepareFilesForFlashupdate();
    Element elt = document.createElement("revision");
    elt.setTextContent(mobileResourceHelper.getRevision());
    document.getDocumentElement().appendChild(elt);
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) Element(org.w3c.dom.Element)

Example 8 with ServiceException

use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.

the class GetPackage method writeResponseResult.

@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String project = Keys.project.value(request);
    MobileApplication mobileApplication = GetBuildStatus.getMobileApplication(project);
    if (mobileApplication == null) {
        throw new ServiceException("no such mobile application");
    } else {
        boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
        if (!bTpPrivateRole && mobileApplication.getAccessibility() == Accessibility.Private) {
            throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
        }
    }
    String platformName = Keys.platform.value(request);
    HttpMethod method = null;
    try {
        method = perform(mobileApplication, platformName, request);
        try {
            String contentDisposition = method.getResponseHeader(HeaderName.ContentDisposition.value()).getValue();
            HeaderName.ContentDisposition.setHeader(response, contentDisposition);
        } catch (Exception e) {
            HeaderName.ContentDisposition.setHeader(response, "attachment; filename=\"" + project + "\"");
        }
        try {
            response.setContentType(method.getResponseHeader(HeaderName.ContentType.value()).getValue());
        } catch (Exception e) {
            response.setContentType(MimeType.OctetStream.value());
        }
        OutputStream responseOutputStream = response.getOutputStream();
        IOUtils.copy(method.getResponseBodyAsStream(), responseOutputStream);
    } catch (IOException ioex) {
        // Fix for ticket #4698
        if (!ioex.getClass().getSimpleName().equalsIgnoreCase("ClientAbortException")) {
            // fix for #5042
            throw ioex;
        }
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) OutputStream(java.io.OutputStream) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) IOException(java.io.IOException)

Example 9 with ServiceException

use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.

the class Delete method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element rootElement = document.getDocumentElement();
    // String classToCreate = ServiceUtils.getRequiredParameter(request, "classToCreate");
    synchronized (Engine.CERTIFICATES_PATH) {
        FileAndProperties rep = ServiceUtils.startCertificate();
        File file = rep.getF();
        Properties storesProperties = rep.getP();
        String certificateName;
        int i = 1;
        ArrayList<String> mappingsToDelete = new ArrayList<String>();
        while ((certificateName = (String) request.getParameter("certificateName_" + i)) != null) {
            Iterator<Object> it = storesProperties.keySet().iterator();
            while (it.hasNext()) {
                String propertyName = (String) it.next();
                String propertyValue = storesProperties.getProperty(propertyName);
                if (propertyValue.equals(certificateName)) {
                    mappingsToDelete.add(propertyName);
                }
            }
            for (int j = 0; j < mappingsToDelete.size(); j++) {
                // delete found mappings
                ServiceUtils.deleteMapping(storesProperties, mappingsToDelete.get(j), document, rootElement);
            }
            if (storesProperties.remove(certificateName) != null) {
                ServiceUtils.addMessage(document, rootElement, "Certificate " + certificateName + " has successfully been deleted.", "message");
            } else
                throw new ServiceException("Certificate " + certificateName + " didn't exist");
            storesProperties.remove(certificateName + ".type");
            storesProperties.remove(certificateName + ".group");
            i++;
        }
        PropertiesUtils.store(storesProperties, file);
    }
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) FileAndProperties(com.twinsoft.convertigo.engine.admin.util.FileAndProperties) FileAndProperties(com.twinsoft.convertigo.engine.admin.util.FileAndProperties) Properties(java.util.Properties) File(java.io.File)

Example 10 with ServiceException

use of com.twinsoft.convertigo.engine.admin.services.ServiceException in project convertigo by convertigo.

the class List method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element rootElement = document.getDocumentElement();
    Element certificates = document.createElement("certificates");
    rootElement.appendChild(certificates);
    File file = new File(Engine.CERTIFICATES_PATH + CertificateManager.STORES_PROPERTIES_FILE_NAME);
    Properties storesProperties = new Properties();
    synchronized (Engine.CERTIFICATES_PATH) {
        try {
            PropertiesUtils.load(storesProperties, file);
        } catch (Exception e) {
            String message = "Unexpected exception";
            Engine.logAdmin.error(message, e);
            throw new ServiceException(message, e);
        }
    }
    java.util.List<String> certifVector = new ArrayList<String>();
    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);
    storesKeysEnum = Collections.enumeration(certifVector);
    Engine.logAdmin.debug("Analyzing certificates...");
    String certificateName, certificateType, certificatePwd, certificateGroup;
    java.util.List<String> installedCertificates = new ArrayList<>();
    java.util.List<Element> elts = new ArrayList<>();
    while (storesKeysEnum.hasMoreElements()) {
        certificateName = (String) storesKeysEnum.nextElement();
        certificateType = (String) storesProperties.getProperty(certificateName + ".type");
        certificatePwd = (String) storesProperties.getProperty(certificateName);
        certificateGroup = (String) storesProperties.getProperty(certificateName + ".group");
        Engine.logAdmin.debug("Found certificate:");
        Engine.logAdmin.debug("   name=" + certificateName);
        Engine.logAdmin.debug("   type=" + certificateType);
        Engine.logAdmin.debug("   password (ciphered)=" + certificatePwd);
        Engine.logAdmin.debug("   group=" + certificateGroup);
        if (certificateType == null) {
            Engine.logAdmin.error("Corrupted certificate '" + certificateName + "' : missing type");
        }
        if (certificatePwd.length() > 0) {
            try {
                certificatePwd = Crypto2.decodeFromHexString((String) storesProperties.getProperty(certificateName));
            } catch (Exception e) {
                Engine.logAdmin.error("Unable to decipher the password", e);
            }
        }
        Element certificateElement = document.createElement("certificate");
        certificateElement.setAttribute("name", certificateName);
        certificateElement.setAttribute("type", certificateType);
        certificateElement.setAttribute("password", certificatePwd);
        certificateElement.setAttribute("validPass", Boolean.toString(CertificateManager.checkCertificatePassword(certificateType, Engine.CERTIFICATES_PATH + "/" + certificateName, certificatePwd)));
        certificateElement.setAttribute("group", certificateGroup);
        installedCertificates.add(certificateName);
        elts.add(certificateElement);
    }
    Collections.sort(elts, (a, b) -> {
        return a.getAttribute("name").compareToIgnoreCase(b.getAttribute("name"));
    });
    for (Element elt : elts) {
        certificates.appendChild(elt);
    }
    Element candidates = document.createElement("candidates");
    rootElement.appendChild(candidates);
    File certifDirectory = new File(Engine.CERTIFICATES_PATH);
    File[] certifList = certifDirectory.listFiles();
    elts.clear();
    for (int k = 0; k < certifList.length; k++) {
        String certifName = certifList[k].getName();
        String certificateExtensionName = certifName.replaceFirst(".*\\.", ".");
        if (CertificateManager.isCertificateExtension(certificateExtensionName)) {
            if (!installedCertificates.contains(certifName)) {
                Element candidateElement = document.createElement("candidate");
                candidateElement.setAttribute("name", certifName);
                elts.add(candidateElement);
            }
        }
    }
    Collections.sort(elts, (a, b) -> {
        return a.getAttribute("name").compareToIgnoreCase(b.getAttribute("name"));
    });
    for (Element elt : elts) {
        candidates.appendChild(elt);
    }
    Element bindings = document.createElement("bindings");
    rootElement.appendChild(bindings);
    Element anonymous = document.createElement("anonymous");
    bindings.appendChild(anonymous);
    boolean cariocaLinksExist = false;
    String link = "";
    storesKeysEnum = Collections.enumeration(linksVector);
    while (storesKeysEnum.hasMoreElements()) {
        // Entire link
        link = (String) storesKeysEnum.nextElement();
        // Name of the certificate linked to this Convertigo link
        certificateName = (String) storesProperties.getProperty(link);
        // CUT OF THE ENTIRE LINK
        // Targetted object of this link : 'tas' (carioca/vic) or 'projects' (Convertigo)
        StringTokenizer st = new StringTokenizer(link.substring(0, link.length() - 13), ".");
        String targettedObject = st.nextToken();
        if (targettedObject.equals("tas")) {
            cariocaLinksExist = true;
            // There isn't more Convertigo links
            break;
        }
        // Convertigo project
        String convProject = "";
        if (st.hasMoreTokens())
            convProject = st.nextToken();
        Element bindingElement = document.createElement("binding");
        bindingElement.setAttribute("projectName", convProject);
        bindingElement.setAttribute("certificateName", certificateName);
        anonymous.appendChild(bindingElement);
    }
    Element carioca = document.createElement("carioca");
    bindings.appendChild(carioca);
    while (cariocaLinksExist || storesKeysEnum.hasMoreElements()) {
        // Entire link
        if (cariocaLinksExist)
            // In the first loop, the entire link is already got (in the loop concerning the Convertigo links)
            cariocaLinksExist = false;
        else
            link = (String) storesKeysEnum.nextElement();
        // Name of the certificate linked to this Carioca link
        certificateName = (String) storesProperties.getProperty(link);
        // CUT OF THE ENTIRE LINK
        // the Targetted object of this link is 'tas' (carioca)
        StringTokenizer st = new StringTokenizer(link.substring(0, link.length() - 13), ".");
        // Project
        String virtualServer = "";
        String group = "";
        String user = "";
        String project = "";
        // tas
        if (st.hasMoreTokens())
            st.nextToken();
        if (link.indexOf("projects") == -1) {
            // Virtual Server
            if (st.hasMoreTokens())
                virtualServer = st.nextToken();
            // Group of the user
            if (st.hasMoreTokens())
                group = st.nextToken();
            // User
            if (st.hasMoreTokens())
                user = st.nextToken();
        } else {
            while (st.hasMoreTokens()) {
                tmp = st.nextToken();
                if (tmp.equals("projects")) {
                    tmp = st.nextToken();
                    project = tmp;
                } else {
                    if (virtualServer.equals(""))
                        virtualServer = tmp;
                    else {
                        if (group.equals(""))
                            group = tmp;
                        else {
                            if (user.equals(""))
                                user = tmp;
                        }
                    }
                }
            }
        }
        Element bindingElement = document.createElement("binding");
        bindingElement.setAttribute("projectName", project);
        bindingElement.setAttribute("virtualServerName", virtualServer);
        bindingElement.setAttribute("imputationGroup", group);
        bindingElement.setAttribute("userName", user);
        bindingElement.setAttribute("certificateName", certificateName);
        carioca.appendChild(bindingElement);
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) StringTokenizer(java.util.StringTokenizer) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) 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