Search in sources :

Example 11 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method discoverWorkflowApps.

public List<WorkflowApplication> discoverWorkflowApps() throws DiscoveryException {
    String urlBase = MdwPlugin.getSettings().getProjectDiscoveryUrl();
    if (!urlBase.endsWith("/"))
        urlBase += "/";
    String ctxRoot = urlBase.endsWith("Discovery/") ? "" : "MDWWeb/";
    if (urlBase.indexOf("lxdnd696") >= 0)
        // old discovery server
        ctxRoot = "MDWExampleWeb/";
    String path = urlBase.endsWith("Discovery/") ? "ConfigManagerProjects.xml" : "Services/GetConfigFile?name=ConfigManagerProjects.xml";
    String cfgMgrUrl = urlBase + ctxRoot + path;
    try {
        URL url = new URL(cfgMgrUrl);
        HttpHelper httpHelper = new HttpHelper(url);
        httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
        httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
        String xml = httpHelper.get();
        ConfigManagerProjectsDocument doc = ConfigManagerProjectsDocument.Factory.parse(xml, Compatibility.namespaceOptions());
        return doc.getConfigManagerProjects().getWorkflowAppList();
    } catch (XmlException ex) {
        PluginMessages.log(ex);
        throw new DiscoveryException("Unable to obtain/parse Config Manager info from " + cfgMgrUrl);
    } catch (Exception ex) {
        throw new DiscoveryException(ex.getMessage(), ex);
    }
}
Also used : ConfigManagerProjectsDocument(com.centurylink.mdw.workflow.ConfigManagerProjectsDocument) XmlException(org.apache.xmlbeans.XmlException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) URL(java.net.URL) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException)

Example 12 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class ImportPackageWizard method performFinish.

@Override
public boolean performFinish() {
    final List<WorkflowPackage> importedPackages = new ArrayList<>();
    final List<java.io.File> includes = new ArrayList<>();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                WorkflowProject wfp = topFolder.getProject();
                DesignerProxy designerProxy = wfp.getDesignerProxy();
                java.io.File assetDir = wfp.getAssetDir();
                java.io.File zipFile = null;
                java.io.File tempDir = wfp.getTempDir();
                monitor.beginTask("Import Packages", 100 * importPackageSelectPage.getSelectedPackages().size());
                monitor.subTask("Importing selected packages...");
                monitor.worked(10);
                StringBuilder sb = new StringBuilder();
                ProgressMonitor progressMonitor = new SwtProgressMonitor(new SubProgressMonitor(monitor, 100));
                for (File pkgFile : importPackageSelectPage.getSelectedPackages()) {
                    if (pkgFile.getContent() == null) {
                        // discovered
                        if (pkgFile.getUrl() != null) {
                            // assets
                            HttpHelper httpHelper = new HttpHelper(pkgFile.getUrl());
                            httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                            httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                            pkgFile.setContent(httpHelper.get());
                        } else if (mavenDiscovery)
                            importFromMaven(pkgFile.getName(), wfp, includes, monitor);
                        else {
                            getPackageNames(pkgFile.getName(), sb);
                        }
                    }
                    String pkgFileContent = pkgFile.getContent();
                    if (pkgFileContent != null) {
                        Importer importer = new Importer(designerProxy.getPluginDataAccess(), wfp.isFilePersist() && wfp.isRemote() ? null : getShell());
                        WorkflowPackage importedPackage = importer.importPackage(wfp, pkgFileContent, progressMonitor);
                        if (// canceled
                        importedPackage == null) {
                            progressMonitor.done();
                            break;
                        } else {
                            if (upgradeAssets) {
                                progressMonitor.subTask("Upgrading activity implementors and other assets...");
                                designerProxy.upgradeAssets(importedPackage);
                            }
                            if (// file system eclipse
                            wfp.isFilePersist())
                                // sync
                                wfp.getSourceProject().refreshLocal(2, null);
                            // TODO refresh Archive in case existing package
                            // was
                            // moved there
                            importedPackages.add(importedPackage);
                            includes.add(new java.io.File(assetDir + "/" + importedPackage.getName().replace('.', '/')));
                        }
                        progressMonitor.done();
                    }
                }
                if (sb.length() > 0) {
                    String url = wfp.getServiceUrl() + "/Services/Assets";
                    Map<String, String> hdrs = new HashMap<>();
                    hdrs.put("Content-Type", "application/json");
                    hdrs.put("request-query-string", "discoveryUrl=" + discoveryUrl + "&discoveryType=distributed");
                    DesignerHttpHelper httpHelper = new DesignerHttpHelper(new URL(url), wfp.getUser().getJwtToken());
                    httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                    httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                    httpHelper.setHeaders(hdrs);
                    httpHelper.put("{packages: [" + sb.toString() + "]}");
                }
                if (zipFormat) {
                    zipFile = importFile;
                    if (!wfp.isRemote())
                        unzipToLocal(wfp, zipFile, tempDir, assetDir, importedPackages, progressMonitor);
                }
                if (!includes.isEmpty()) {
                    if (!tempDir.exists() && !tempDir.mkdirs()) {
                        throw new IOException("Unable to create temp directory: " + tempDir);
                    }
                    zipFile = new java.io.File(tempDir + "/packages" + StringHelper.filenameDateToString(new Date()) + ".zip");
                    ZipHelper.zipWith(assetDir, zipFile, includes);
                }
                if (zipFile != null && wfp.isRemote() && wfp.isFilePersist()) {
                    uploadToRemoteServer(wfp, zipFile);
                    if (!zipFile.delete())
                        PluginMessages.log("Unable to delete the file " + zipFile.getPath());
                    progressMonitor.done();
                }
                wfp.getDesignerProxy().getCacheRefresh().doRefresh(true);
            } catch (ActionCancelledException ex) {
                throw new OperationCanceledException();
            } catch (Exception ex) {
                PluginMessages.log(ex);
                throw new InvocationTargetException(ex);
            }
        }
    };
    try {
        boolean confirmed = true;
        if (topFolder.getProject().checkRequiredVersion(6, 0, 13) && topFolder.getProject().isRemote())
            confirmed = MessageDialog.openConfirm(getShell(), "Confirm Import", "This import will impact the remote environment. Are you sure you want to import?");
        if (confirmed) {
            getContainer().run(true, true, op);
            if (!importedPackages.isEmpty())
                DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), importedPackages.get(0));
            IWorkbenchPage page = MdwPlugin.getActivePage();
            ProcessExplorerView processExplorer = (ProcessExplorerView) page.findView(ProcessExplorerView.VIEW_ID);
            if (processExplorer != null) {
                processExplorer.handleRefresh();
                processExplorer.expand(topFolder);
            }
        }
        return true;
    } catch (InterruptedException ex) {
        MessageDialog.openInformation(getShell(), "Import Package", "Import Cancelled");
        return true;
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Import Package", importPackagePage.getProject());
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) DesignerHttpHelper(com.centurylink.mdw.designer.utils.DesignerHttpHelper) URL(java.net.URL) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Importer(com.centurylink.mdw.plugin.designer.Importer) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) ProcessExplorerView(com.centurylink.mdw.plugin.designer.views.ProcessExplorerView) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Date(java.util.Date) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(com.centurylink.mdw.plugin.designer.model.File) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DesignerHttpHelper(com.centurylink.mdw.designer.utils.DesignerHttpHelper)

Example 13 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class ServerStatusChecker method run.

public void run() {
    updateServerStatus(ServerStatusListener.SERVER_STATUS_WAIT);
    while (!stopping) {
        try {
            HttpHelper httpHelper = null;
            try {
                URL url = new URL(serverSettings.getConsoleUrl());
                httpHelper = new HttpHelper(url);
                httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                if (httpHelper.get() == null)
                    updateServerStatus(ServerStatusListener.SERVER_STATUS_STOPPED);
                else
                    updateServerStatus(ServerStatusListener.SERVER_STATUS_RUNNING);
            } catch (FileNotFoundException ex) {
                if ((serverSettings.isServiceMix() || serverSettings.isFuse()) && httpHelper.getResponseCode() == 404)
                    // expected
                    updateServerStatus(ServerStatusListener.SERVER_STATUS_RUNNING);
                else
                    updateServerStatus(ServerStatusListener.SERVER_STATUS_STOPPED);
            } catch (IOException ex) {
                updateServerStatus(ServerStatusListener.SERVER_STATUS_STOPPED);
            } catch (Exception ex) {
                updateServerStatus(ServerStatusListener.SERVER_STATUS_ERRORED);
                PluginMessages.log(ex);
            }
            Thread.sleep(6000);
        } catch (InterruptedException ex) {
            break;
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) URL(java.net.URL) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper 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 15 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class MdwAuthenticator method doAuthentication.

/**
 * <p>
 * Takes a cuid and pass combination and authenticates against JWT.
 * </p>
 *
 * @param cuid
 * @param pass
 * @return the JWT access token
 */
public String doAuthentication(String cuid, String pass) throws MdwSecurityException {
    String accessToken = null;
    try {
        if (StringHelper.isEmpty(tokenLocation)) {
            throw new MdwSecurityException("Token location is empty, should point to an JWT token location endpoint." + " Unable to authenticate user " + cuid + " with JWT");
        }
        JSONObject json = new JSONObject();
        json.put("user", cuid);
        json.put("password", pass);
        json.put("appId", appId);
        try {
            HttpHelper helper = new HttpHelper(new URL(tokenLocation));
            Map<String, String> hdrs = new HashMap<>();
            hdrs.put("Content-Type", "application/json; charset=utf-8");
            helper.setHeaders(hdrs);
            String response = helper.post(json.toString());
            JSONObject responseJson = new JSONObject(response);
            accessToken = responseJson.getString("mdwauth");
            if (accessToken == null || accessToken.isEmpty())
                throw new IOException("User authentication failed with response:" + responseJson);
        } catch (IOException ex) {
            throw new ServiceException(ex.getMessage(), ex);
        }
    } catch (Exception ex) {
        String msg = "Unable to authenticate user " + cuid + " with JWT";
        throw new AuthenticationException(msg, ex);
    }
    return accessToken;
}
Also used : JSONObject(org.json.JSONObject) ServiceException(com.centurylink.mdw.common.service.ServiceException) HashMap(java.util.HashMap) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) URL(java.net.URL) ServiceException(com.centurylink.mdw.common.service.ServiceException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException)

Aggregations

HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)21 IOException (java.io.IOException)17 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)10 URL (java.net.URL)9 JSONException (org.json.JSONException)6 XmlException (org.apache.xmlbeans.XmlException)5 SocketTimeoutException (java.net.SocketTimeoutException)4 RemoteException (java.rmi.RemoteException)4 JSONObject (org.json.JSONObject)4 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)3 MDWStatusMessageDocument (com.centurylink.mdw.bpm.MDWStatusMessageDocument)3 HashMap (java.util.HashMap)3 CoreException (org.eclipse.core.runtime.CoreException)3 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 AppSummary (com.centurylink.mdw.designer.model.AppSummary)2 DesignerHttpHelper (com.centurylink.mdw.designer.utils.DesignerHttpHelper)2 File (com.centurylink.mdw.plugin.designer.model.File)2 FileNotFoundException (java.io.FileNotFoundException)2 GeneralSecurityException (java.security.GeneralSecurityException)2