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);
}
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);
}
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();
}
}
}
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);
}
}
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);
}
}
Aggregations