Search in sources :

Example 6 with MDWStatusMessageDocument

use of com.centurylink.mdw.bpm.MDWStatusMessageDocument in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method retrieveRemoteAppSummary.

public void retrieveRemoteAppSummary(final boolean errorDialogOnFailure) {
    Runnable runnable = new Runnable() {

        public void run() {
            // bypass designer proxy to delay lazy loading if project hasn't
            // been opened
            HttpHelper httpHelper;
            String url = getAppSummaryUrl() + "/Services/AppSummary?format=json";
            try {
                httpHelper = new HttpHelper(new URL(url));
                httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                remoteAppSummary = new AppSummary(new JSONObject(httpHelper.get()));
            } catch (JSONException ex) {
                try {
                    url = getAppSummaryUrl() + "/Services/GetAppSummary";
                    httpHelper = new HttpHelper(new URL(url));
                    httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                    httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                    String response = httpHelper.get();
                    if (response != null && (response.trim().startsWith("<xs:MDWStatusMessage") || response.trim().startsWith("<bpm:MDWStatusMessage"))) {
                        MDWStatusMessageDocument msgDoc = MDWStatusMessageDocument.Factory.parse(response, Compatibility.namespaceOptions());
                        throw new IOException("Server error: " + msgDoc.getMDWStatusMessage().getStatusMessage());
                    }
                    ApplicationSummary docAppSummary = ApplicationSummaryDocument.Factory.parse(response, Compatibility.namespaceOptions()).getApplicationSummary();
                    remoteAppSummary = new AppSummary();
                    remoteAppSummary.setAppId(docAppSummary.getApplicationName());
                    remoteAppSummary.setMdwVersion(docAppSummary.getMdwVersion());
                    remoteAppSummary.setMdwBuild(docAppSummary.getBuild());
                    remoteAppSummary.setMdwHubUrl(docAppSummary.getMdwHubUrl());
                    remoteAppSummary.setServicesUrl(docAppSummary.getServicesUrl());
                    if (docAppSummary.getRepository() != null) {
                        Repository repo = new Repository();
                        remoteAppSummary.setRepository(repo);
                        repo.setBranch(docAppSummary.getRepository().getBranch());
                        repo.setCommit(docAppSummary.getRepository().getCommit());
                        repo.setProvider(docAppSummary.getRepository().getProvider());
                        repo.setUrl(docAppSummary.getRepository().getUrl());
                    }
                    DbInfo dbInfo = new DbInfo();
                    remoteAppSummary.setDbInfo(dbInfo);
                    dbInfo.setJdbcUrl(docAppSummary.getDbInfo().getJdbcUrl());
                    dbInfo.setUser(docAppSummary.getDbInfo().getUser());
                } catch (IOException e) {
                    PluginMessages.log(ex);
                    if (errorDialogOnFailure)
                        MessageDialog.openError(MdwPlugin.getShell(), "Authentication", "Server appears to be offline: " + e.getMessage());
                } catch (Exception e) {
                    PluginMessages.log(e);
                    if (errorDialogOnFailure)
                        PluginMessages.uiError(e, "Remote App Summary", WorkflowProject.this);
                }
            } catch (IOException ex) {
                PluginMessages.log(ex);
                if (errorDialogOnFailure)
                    MessageDialog.openError(MdwPlugin.getShell(), "Authentication", "Server appears to be offline: " + ex.getMessage());
            } catch (Exception ex) {
                PluginMessages.log(ex);
                if (errorDialogOnFailure)
                    PluginMessages.uiError(ex, "Remote App Summary", WorkflowProject.this);
            }
        }
    };
    if (MdwPlugin.isUiThread())
        BusyIndicator.showWhile(MdwPlugin.getDisplay(), runnable);
    else
        runnable.run();
}
Also used : JSONException(org.json.JSONException) IOException(java.io.IOException) ApplicationSummary(com.centurylink.mdw.service.ApplicationSummaryDocument.ApplicationSummary) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) MalformedURLException(java.net.MalformedURLException) Repository(com.centurylink.mdw.designer.model.Repository) JSONObject(org.json.JSONObject) MDWStatusMessageDocument(com.centurylink.mdw.bpm.MDWStatusMessageDocument) AppSummary(com.centurylink.mdw.designer.model.AppSummary) DesignerHttpHelper(com.centurylink.mdw.designer.utils.DesignerHttpHelper) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DbInfo(com.centurylink.mdw.designer.model.DbInfo)

Example 7 with MDWStatusMessageDocument

use of com.centurylink.mdw.bpm.MDWStatusMessageDocument in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method launchProcess.

public MDWStatusMessage launchProcess(WorkflowProcess processVersion, String masterRequestId, String owner, Long ownerId, List<VariableValue> variableValues, Long activityId) throws DataAccessException, XmlException, JSONException, IOException {
    Map<VariableVO, String> variables = new HashMap<>();
    for (VariableValue variableValue : variableValues) {
        variables.put(variableValue.getVariableVO(), variableValue.getValue());
    }
    MDWStatusMessageDocument statusMessageDoc = restfulServer.launchProcess(processVersion.getId(), masterRequestId, owner, ownerId, variables, activityId, project.isOldNamespaces());
    if (statusMessageDoc.getMDWStatusMessage().getStatusCode() != 0)
        throw new RemoteException("Error launching process: " + statusMessageDoc.getMDWStatusMessage().getStatusMessage());
    // audit log in separate dao since launch is multi-threaded
    UserActionVO userAction = new UserActionVO(project.getUser().getUsername(), Action.Run, processVersion.getActionEntity(), processVersion.getId(), processVersion.getLabel());
    userAction.setSource("Eclipse/RCP Designer");
    try {
        new DesignerDataAccess(dataAccess.getDesignerDataAccess()).auditLog(userAction);
    } catch (Exception ex) {
        throw new DataAccessException(-1, ex.getMessage(), ex);
    }
    return statusMessageDoc.getMDWStatusMessage();
}
Also used : UserActionVO(com.centurylink.mdw.model.value.user.UserActionVO) HashMap(java.util.HashMap) VariableValue(com.centurylink.mdw.plugin.designer.model.VariableValue) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) MDWStatusMessageDocument(com.centurylink.mdw.bpm.MDWStatusMessageDocument) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) RemoteException(java.rmi.RemoteException) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 8 with MDWStatusMessageDocument

use of com.centurylink.mdw.bpm.MDWStatusMessageDocument in project mdw-designer by CenturyLinkCloud.

the class RestfulServer method invokeService.

public MDWStatusMessageDocument invokeService(String request) throws DataAccessException, RemoteException {
    String response = null;
    try {
        // append to Services context root since sometimes only Services/* are excluded from CT auth
        HttpHelper httpHelper = getHttpHelper(getMdwWebUrl() + "/Services/REST");
        httpHelper.setConnectTimeout(getConnectTimeout());
        httpHelper.setReadTimeout(getReadTimeout());
        response = httpHelper.post(request);
        MDWStatusMessageDocument statusMessageDoc;
        if (response.startsWith("{")) {
            StatusMessage statusMessage = new StatusMessage(new JSONObject(response));
            statusMessageDoc = statusMessage.getStatusDocument();
        } else {
            statusMessageDoc = MDWStatusMessageDocument.Factory.parse(response, Compatibility.namespaceOptions());
        }
        MDWStatusMessage statusMessage = statusMessageDoc.getMDWStatusMessage();
        if (statusMessage.getStatusCode() == -3) {
            // event handler not registered
            throw new RemoteException("No event handler is registered for instance-level actions on: " + getMdwWebUrl());
        } else if (statusMessage.getStatusCode() != 0) {
            throw new RemoteException("Error response from server: " + statusMessage.getStatusMessage());
        }
        return statusMessageDoc;
    } catch (RemoteException ex) {
        // don't fall through to IOException catch block
        throw ex;
    } catch (SocketTimeoutException ex) {
        throw new DataAccessOfflineException("Timeout after " + getReadTimeout() + " ms", ex);
    } catch (IOException ex) {
        throw new DataAccessOfflineException("Unable to connect to " + getMdwWebUrl(), ex);
    } catch (JSONException ex) {
        throw new DataAccessException("Unparsable JSON response:\n" + response);
    } catch (XmlException ex) {
        throw new DataAccessException("Unparsable XML response:\n" + response);
    }
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) JSONException(org.json.JSONException) IOException(java.io.IOException) MDWStatusMessage(com.centurylink.mdw.bpm.MDWStatusMessageDocument.MDWStatusMessage) StatusMessage(com.centurylink.mdw.common.service.types.StatusMessage) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(org.json.JSONObject) MDWStatusMessage(com.centurylink.mdw.bpm.MDWStatusMessageDocument.MDWStatusMessage) XmlException(org.apache.xmlbeans.XmlException) MDWStatusMessageDocument(com.centurylink.mdw.bpm.MDWStatusMessageDocument) RemoteException(java.rmi.RemoteException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 9 with MDWStatusMessageDocument

use of com.centurylink.mdw.bpm.MDWStatusMessageDocument in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method validateEngineCallResponse.

protected JSONObject validateEngineCallResponse(String response) throws ValidationException, XmlException, JSONException {
    MDWStatusMessageDocument statusMessageDoc;
    if (response.startsWith("{")) {
        StatusMessage statusMessage = new StatusMessage(new JSONObject(response));
        statusMessageDoc = statusMessage.getStatusDocument();
    } else {
        statusMessageDoc = MDWStatusMessageDocument.Factory.parse(response, Compatibility.namespaceOptions());
    }
    MDWStatusMessage statusMessage = statusMessageDoc.getMDWStatusMessage();
    if (statusMessage.getStatusCode() == -3) {
        // event handler not registered
        throw new ValidationException("No event handler is registered for regression test actions");
    } else if (statusMessage.getStatusCode() != 0) {
        throw new ValidationException("Error response from server: " + statusMessage.getStatusMessage());
    }
    if (statusMessage.getStatusMessage().startsWith("{"))
        return new JSONObject(statusMessage.getStatusMessage());
    else
        return null;
}
Also used : ValidationException(com.centurylink.mdw.designer.utils.ValidationException) JSONObject(org.json.JSONObject) MDWStatusMessage(com.centurylink.mdw.bpm.MDWStatusMessageDocument.MDWStatusMessage) MDWStatusMessageDocument(com.centurylink.mdw.bpm.MDWStatusMessageDocument) MDWStatusMessage(com.centurylink.mdw.bpm.MDWStatusMessageDocument.MDWStatusMessage) StatusMessage(com.centurylink.mdw.common.service.types.StatusMessage)

Aggregations

MDWStatusMessageDocument (com.centurylink.mdw.bpm.MDWStatusMessageDocument)9 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)4 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 JSONException (org.json.JSONException)4 MDWStatusMessage (com.centurylink.mdw.bpm.MDWStatusMessageDocument.MDWStatusMessage)3 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)3 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)3 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)3 XmlException (org.apache.xmlbeans.XmlException)3 JSONObject (org.json.JSONObject)3 StatusMessage (com.centurylink.mdw.common.service.types.StatusMessage)2 FileNotFoundException (java.io.FileNotFoundException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)1 AppSummary (com.centurylink.mdw.designer.model.AppSummary)1 DbInfo (com.centurylink.mdw.designer.model.DbInfo)1