Search in sources :

Example 1 with RemoteFileReference

use of com.twinsoft.convertigo.beans.references.RemoteFileReference in project convertigo by convertigo.

the class ProjectImportWsReference method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if (treeObject != null) {
                ProjectTreeObject projectTreeObject = null;
                RemoteFileReference reference = null;
                HttpConnector httpConnector = null;
                // Create a new  WS reference
                if (treeObject instanceof ProjectTreeObject) {
                    projectTreeObject = (ProjectTreeObject) treeObject;
                    if (wsType == TYPE_SOAP) {
                        reference = new WebServiceReference();
                        reference.bNew = true;
                    }
                    if (wsType == TYPE_REST) {
                        reference = new RestServiceReference();
                        reference.bNew = true;
                    }
                } else // Update an existing WS reference
                if (treeObject instanceof ReferenceTreeObject) {
                /* For further use
						ReferenceTreeObject referenceTreeObject = (ReferenceTreeObject)treeObject;
						webServiceReference = (WebServiceReference) referenceTreeObject.getObject();
						projectTreeObject = referenceTreeObject.getProjectTreeObject();*/
                }
                if (reference != null) {
                    WsReferenceImportDialog wsReferenceImportDialog = null;
                    if (wsType == TYPE_SOAP) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsSoapReferenceImportDialogComposite.class, "SOAP Web Service reference");
                    }
                    if (wsType == TYPE_REST) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsRestReferenceImportDialogComposite.class, "REST Web Service reference");
                    }
                    wsReferenceImportDialog.setProject(projectTreeObject.getObject());
                    wsReferenceImportDialog.setReference(reference);
                    wsReferenceImportDialog.open();
                    if (wsReferenceImportDialog.getReturnCode() != Window.CANCEL) {
                        httpConnector = wsReferenceImportDialog.getHttpConnector();
                    }
                    Project project = projectTreeObject.getObject();
                    Engine.theApp.schemaManager.clearCache(project.getName());
                    // Reload project in tree
                    explorerView.reloadTreeObject(projectTreeObject);
                    if (httpConnector != null && httpConnector.getParent() != null) {
                        explorerView.objectSelected(new CompositeEvent(httpConnector));
                    } else if (reference != null && reference.getParent() != null) {
                        if (reference.hasChanged)
                            projectTreeObject.hasBeenModified(true);
                        explorerView.objectSelected(new CompositeEvent(reference));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to " + (updateMode ? "update" : "import") + " from remote WS definition!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) WsReferenceImportDialog(com.twinsoft.convertigo.eclipse.dialogs.WsReferenceImportDialog) WsRestReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsRestReferenceImportDialogComposite) Cursor(org.eclipse.swt.graphics.Cursor) WsSoapReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsSoapReferenceImportDialogComposite) Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 2 with RemoteFileReference

use of com.twinsoft.convertigo.beans.references.RemoteFileReference in project convertigo by convertigo.

the class WsReferenceImportDialogComposite method fillReference.

private void fillReference() {
    if (!isUpdateMode()) {
        RemoteFileReference reference = (RemoteFileReference) getDbo();
        reference.setUrlpath(urlPath);
        reference.setFilepath("");
        if (useAuthentication.getSelection()) {
            reference.setNeedAuthentication(true);
            reference.setAuthUser(loginText.getText());
            reference.setAuthPassword(passwordText.getText());
        }
    }
}
Also used : RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference)

Example 3 with RemoteFileReference

use of com.twinsoft.convertigo.beans.references.RemoteFileReference in project convertigo by convertigo.

the class NewProjectWizard method doFinish.

/**
 * The worker method. We create the project here according to the templateId
 * variable
 */
private void doFinish(IProgressMonitor monitor) throws CoreException {
    try {
        if (page10 != null) {
            projectName = page1.getProjectName();
            monitor.beginTask("Creating project " + projectName, 7);
            Project project = createFromBlankProject(monitor);
            boolean needAuth = page10.useAuthentication();
            String wsURL = page10.getWsdlURL().toString();
            String login = page10.getLogin();
            String password = page10.getPassword();
            WebServiceReference webWsReference = null;
            RestServiceReference restWsReference = null;
            RemoteFileReference reference = null;
            if (wizardId.equals("com.twinsoft.convertigo.eclipse.wizards.NewWebServiceSoapReferenceWizard")) {
                reference = webWsReference = new WebServiceReference();
            } else if (wizardId.equals("com.twinsoft.convertigo.eclipse.wizards.NewWebServiceSwaggerReferenceWizard")) {
                reference = restWsReference = new RestServiceReference();
            }
            reference.setUrlpath(wsURL);
            reference.setNeedAuthentication(needAuth);
            reference.setAuthUser(login == null ? "" : login);
            reference.setAuthUser(password == null ? "" : password);
            reference.bNew = true;
            ImportWsReference wsr = webWsReference != null ? new ImportWsReference(webWsReference) : new ImportWsReference(restWsReference);
            HttpConnector httpConnector = wsr.importInto(project);
            if (httpConnector != null) {
                Connector defaultConnector = project.getDefaultConnector();
                project.setDefaultConnector(httpConnector);
                defaultConnector.delete();
            }
        } else if (page1 != null) {
            projectName = page1.getProjectName();
            monitor.beginTask("Creating project " + projectName, 7);
            createFromBlankProject(monitor);
            return;
        } else if (pageSummarySampleProject != null) {
            monitor.beginTask("Creating project", 7);
            createFromArchiveProject(monitor);
            return;
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "An error occured while creating the project", false);
        String message = "An error occured while creating the project (see Error log):\n" + e.getMessage();
        IStatus status = new Status(Status.ERROR, ConvertigoPlugin.PLUGIN_UNIQUE_ID, message, e);
        throw new CoreException(status);
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) CoreException(org.eclipse.core.runtime.CoreException) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference)

Example 4 with RemoteFileReference

use of com.twinsoft.convertigo.beans.references.RemoteFileReference in project convertigo by convertigo.

the class RemoteFileWizardPage method dialogChanged.

public void dialogChanged() {
    String message = null;
    if (!urlPath.isEmpty()) {
        try {
            URL url = new URL(urlPath);
            if (urlPath.startsWith("file:/")) {
                if (FileUtils.toFile(url).exists()) {
                    // wsRefAuthenticated.getFilterExtension()[0].split(";");
                    String[] filterExtensions = wsRefAuthenticated.getFilterExtension();
                    for (String fileFilter : filterExtensions) {
                        String fileExtension = fileFilter.substring(fileFilter.lastIndexOf("."));
                        if (!urlPath.endsWith(fileExtension)) {
                            message = "Please select a compatible file";
                        } else {
                            message = null;
                            break;
                        }
                    }
                } else {
                    message = "Please select an existing file";
                }
            }
        } catch (Exception e) {
            message = "Please enter a valid URL";
        }
    } else if (!filePath.equals("")) {
        File file = new File(filePath);
        if (!file.exists()) {
            message = "Please select an existing file";
        } else {
            // filterExtension[0].split(";");
            String[] filterExtensions = getFilterExtension();
            for (String fileFilter : filterExtensions) {
                String fileExtension = fileFilter.substring(fileFilter.lastIndexOf("."));
                if (!filePath.endsWith(fileExtension)) {
                    message = "Please select a compatible file";
                } else {
                    message = null;
                    break;
                }
            }
        }
    } else {
        message = "Please enter an URL!";
    }
    if (message == null) {
        if (useAuthentication.getSelection() && (loginText.getText().equals("") || passwordText.getText().equals(""))) {
            message = "Please enter login and password";
        }
    }
    if (message == null) {
        try {
            RemoteFileReference reference = (RemoteFileReference) getDbo();
            String localPath = "";
            if (urlPath.startsWith("file:/")) {
                localPath = getLocalFilePath(urlPath.substring("file:/".length()));
            }
            if (reference instanceof WebServiceReference || reference instanceof RestServiceReference) {
                reference.setUrlpath(urlPath);
                reference.setFilepath("");
            } else {
                reference.setUrlpath(localPath.isEmpty() ? urlPath : "");
                reference.setFilepath(localPath.isEmpty() ? "" : localPath);
            }
            if (useAuthentication.getSelection()) {
                reference.setNeedAuthentication(true);
                reference.setAuthUser(loginText.getText());
                reference.setAuthPassword(passwordText.getText());
            }
        } catch (Exception e) {
            message = e.getMessage();
        }
    }
    setTextStatus(message);
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 5 with RemoteFileReference

use of com.twinsoft.convertigo.beans.references.RemoteFileReference in project convertigo by convertigo.

the class WsReference method importInto.

protected HttpConnector importInto(Project project) throws Exception {
    boolean needAuthentication = false;
    try {
        if (project != null) {
            RemoteFileReference wsReference = getReference();
            if (wsReference != null) {
                String wsdlUrl = wsReference.getUrlpath();
                // test for valid URL
                new URL(wsdlUrl);
                needAuthentication = wsReference.needAuthentication();
                // SOAP web service
                if (wsReference instanceof WebServiceReference) {
                    try {
                        // Configure SoapUI settings
                        configureSoapUI(wsdlUrl);
                        // Authenticate
                        if (needAuthentication) {
                            String login = wsReference.getAuthUser();
                            String password = wsReference.getAuthPassword();
                            try {
                                // We add login/password into the connection
                                System.setProperty("soapui.loader.username", login);
                                System.setProperty("soapui.loader.password", password);
                                tryAuthentication(wsReference);
                            } catch (Exception e) {
                                throw new Exception("Authentication failure !", e);
                            }
                        }
                        WebServiceReference soapServiceReference = (WebServiceReference) wsReference;
                        return importSoapWebService(project, soapServiceReference);
                    } finally {
                        if (needAuthentication) {
                            // We clear login/password
                            System.setProperty("soapui.loader.username", "");
                            System.setProperty("soapui.loader.password", "");
                        }
                    }
                }
                // REST web service
                if (wsReference instanceof RestServiceReference) {
                    RestServiceReference restServiceReference = (RestServiceReference) wsReference;
                    return importRestWebService(project, restServiceReference);
                }
            }
        }
    } catch (Throwable t) {
        throw new EngineException("Unable to import the web service reference", t);
    }
    return null;
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) EngineException(com.twinsoft.convertigo.engine.EngineException) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) URL(java.net.URL) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

RemoteFileReference (com.twinsoft.convertigo.beans.references.RemoteFileReference)5 RestServiceReference (com.twinsoft.convertigo.beans.references.RestServiceReference)4 WebServiceReference (com.twinsoft.convertigo.beans.references.WebServiceReference)4 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)2 Project (com.twinsoft.convertigo.beans.core.Project)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 URL (java.net.URL)2 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)1 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)1 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)1 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)1 Connector (com.twinsoft.convertigo.beans.core.Connector)1 WsReferenceImportDialog (com.twinsoft.convertigo.eclipse.dialogs.WsReferenceImportDialog)1 WsRestReferenceImportDialogComposite (com.twinsoft.convertigo.eclipse.dialogs.WsRestReferenceImportDialogComposite)1 WsSoapReferenceImportDialogComposite (com.twinsoft.convertigo.eclipse.dialogs.WsSoapReferenceImportDialogComposite)1 CompositeEvent (com.twinsoft.convertigo.eclipse.editors.CompositeEvent)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)1 ReferenceTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject)1