Search in sources :

Example 6 with HTTPStatement

use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.

the class HtmlConnector method prepareForHTTPStatement.

public void prepareForHTTPStatement(Context context) throws EngineException {
    Engine.logBeans.debug("(HtmlConnector) Preparing for http statement");
    // Retrieve current executing transaction
    HtmlTransaction htmlTransaction = getCurrentHtmlTransaction(context);
    if ((htmlTransaction == null) || (!htmlTransaction.runningThread.bContinue)) {
        return;
    }
    // Retrieve current statement : the statement being executed
    Statement statement = htmlTransaction.currentStatement;
    if (statement == null) {
        return;
    }
    if (!(statement instanceof HTTPStatement)) {
        return;
    }
    HTTPStatement httpStatement = (HTTPStatement) statement;
    handleCookie = httpStatement.isHandleCookie();
    httpParameters = httpStatement.getHttpParameters();
    sUrl = httpStatement.getUrl(isHttps(), getServer(), getPort());
    Engine.logBeans.debug("(HtmlConnector) URL: " + sUrl);
    // Parse input document for HTTPStatement variables
    httpStatement.parseInputDocument(context);
    // Getting all input variables marked as GET
    Engine.logBeans.trace("(HtmlConnector) Loading all GET input variables");
    String queryString = httpStatement.getQueryString(context);
    if (Engine.logBeans.isDebugEnabled())
        Engine.logBeans.debug("(HtmlConnector) GET query: " + Visibility.Logs.replaceVariables(httpStatement.getVariables(), queryString));
    // Encodes URL if it contains special characters
    sUrl = URLUtils.encodeAbsoluteURL(sUrl, htmlTransaction.getComputedUrlEncodingCharset());
    if (queryString.length() != 0) {
        sUrl += (sUrl.indexOf('?') == -1 ? "?" : "&") + queryString;
    }
    // Posting all input variables marked as POST
    Engine.logBeans.trace("(HtmlConnector) Loading all POST input variables");
    postQuery = httpStatement.getPostQuery(context);
    if (Engine.logBeans.isDebugEnabled()) {
        Engine.logBeans.debug("(HtmlConnector) POST query: " + Visibility.Logs.replaceVariables(httpStatement.getVariables(), postQuery));
    }
    // Setup the SSL properties if needed
    if (isHttps() || httpStatement.isHttps()) {
        Engine.logBeans.debug("(HtmlConnector) Setting up SSL properties");
        certificateManager.collectStoreInformation(context);
    }
    Engine.logBeans.debug("(HtmlConnector) Connector successfully prepared for statement");
}
Also used : HTTPUploadStatement(com.twinsoft.convertigo.beans.statements.HTTPUploadStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement)

Example 7 with HTTPStatement

use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method modelChanged.

public void modelChanged(HttpProxyEvent event) {
    if (!checkProxySource(event)) {
        return;
    }
    String requestString = event.getRequest();
    String responseString = event.getResponse();
    boolean https = event.isHttps();
    int status = Integer.parseInt(event.getStatus());
    // do not record client redirection
    if ((status == HttpStatus.SC_MOVED_TEMPORARILY) || (status == HttpStatus.SC_MOVED_PERMANENTLY) || (status == HttpStatus.SC_SEE_OTHER) || (status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
        return;
    }
    /*if (requestString.indexOf(getServer()) == -1) {
			return;
		}*/
    Map<String, String> headers = parseResponseString(responseString);
    String contentType = headers.get(HeaderName.ContentType.value().toLowerCase());
    // record only text/html or null Content-Type ...
    if (contentType == null) {
        return;
    }
    if (MimeType.Html.is(contentType) && MimeType.Plain.is(contentType)) {
        return;
    }
    ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Learning statement...");
    try {
        String url, method, handlerName, transactionName, statementName, scHandlerName;
        String normalizedScreenClassName, screenClassName;
        HtmlTransaction htmlTransaction = null;
        HTTPStatement httpStatement = null;
        HtmlScreenClass htmlScreenClass = null;
        HandlerStatement handlerStatement = null;
        ScHandlerStatement scHandlerStatement = null;
        // Document dom = null;
        // Log log = null;
        int size, index1;
        boolean bContinue;
        index1 = 0;
        bContinue = true;
        normalizedScreenClassName = "Unknown";
        htmlTransaction = (HtmlTransaction) htmlConnector.getLearningTransaction();
        synchronized (htmlConnector) {
            // dom = htmlConnector.getCurrentXmlDocument();
            htmlScreenClass = htmlConnector.getCurrentScreenClass();
        }
        screenClassName = htmlScreenClass.getName();
        normalizedScreenClassName = StringUtils.normalize(htmlScreenClass.getName());
        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) current screen class is '" + screenClassName + "'");
        if (htmlTransaction != null) {
            transactionName = htmlTransaction.getName();
            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) creating new HTTPStatement");
            ConvertigoPlugin.logDebug2(requestString);
            httpStatement = parseRequestString(requestString);
            httpStatement.setHttps(https);
            httpStatement.setPort(https ? 443 : 80);
            method = httpStatement.getMethod().toLowerCase();
            // size = httpStatement.getVariablesDefinitionSize();
            size = httpStatement.numberOfVariables();
            url = httpStatement.getUrl(htmlConnector.isHttps(), htmlConnector.getServer(), htmlConnector.getPort());
            while (bContinue) {
                statementName = method + ((index1 == 0) ? " " : " " + index1) + " (" + url + " - " + size + ")";
                statementName = StringUtils.normalize(statementName);
                httpStatement.setName(statementName);
                httpStatement.hasChanged = true;
                httpStatement.bNew = true;
                if (htmlScreenClass == null) {
                    try {
                        httpStatement.priority = 0;
                        htmlTransaction.addStatement(httpStatement);
                        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to default transaction '" + transactionName + "'");
                        fireObjectChanged(new CompositeEvent(htmlTransaction));
                        Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                        bContinue = false;
                    } catch (ObjectWithSameNameException owsne) {
                        index1++;
                    }
                } else {
                    if (htmlConnector.isAccumulating())
                        handlerName = "on" + normalizedScreenClassName + "Exit";
                    else
                        handlerName = "on" + normalizedScreenClassName + "Entry";
                    handlerStatement = htmlTransaction.getHandlerStatement(handlerName);
                    if (handlerStatement != null) {
                        try {
                            handlerStatement.addStatement(httpStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to handler '" + handlerName + "' of transaction '" + transactionName + "'");
                            fireObjectChanged(new CompositeEvent(handlerStatement));
                            Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                            bContinue = false;
                        } catch (ObjectWithSameNameException owsne) {
                            index1++;
                        }
                    } else {
                        try {
                            if (htmlConnector.isAccumulating())
                                scHandlerStatement = new ScExitHandlerStatement(normalizedScreenClassName);
                            else
                                scHandlerStatement = new ScEntryHandlerStatement(normalizedScreenClassName);
                            scHandlerName = scHandlerStatement.getName();
                            scHandlerStatement.setName(scHandlerName);
                            scHandlerStatement.hasChanged = true;
                            scHandlerStatement.bNew = true;
                            scHandlerStatement.priority = 0;
                            htmlTransaction.addStatement(scHandlerStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new ScExitHandlerStatement '" + handlerName + "' of transaction '" + transactionName + "'");
                            try {
                                scHandlerStatement.addStatement(httpStatement);
                                ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement '" + statementName + "' to ScExitHandlerStatement '" + handlerName + "'");
                                fireObjectChanged(new CompositeEvent(htmlTransaction));
                                Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                                bContinue = false;
                            } catch (ObjectWithSameNameException owsne) {
                                index1++;
                            }
                        }// Should not append
                         catch (ObjectWithSameNameException owsne) {
                            throw new EngineException(owsne.getMessage());
                        }
                    }
                }
            }
        } else {
            throw new EngineException("Found none learning transaction");
        }
    } catch (EngineException e) {
        ConvertigoPlugin.logException(e, "An exception occured while learning");
    }
}
Also used : HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 8 with HTTPStatement

use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method parseRequestString.

public HTTPStatement parseRequestString(String requestString) {
    String httpHeader, httpValue;
    String method, uri, version, host;
    String line, token, data;
    int index, i = 0;
    HTTPStatement httpStatement = new HTTPStatement();
    try {
        StringTokenizer st = new StringTokenizer(requestString, "\r");
        while (st.hasMoreTokens()) {
            line = st.nextToken();
            // line is not empty
            if (line.trim().length() > 0) {
                // this is an header ==> <headername>:<space><headervalue>
                if ((index = line.indexOf(":")) != -1) {
                    // skip the first space
                    httpHeader = line.substring(1, index).toLowerCase();
                    // skip the space after ':'
                    httpValue = line.substring(index + 2).toLowerCase();
                    if (httpHeader.equalsIgnoreCase("host")) {
                        host = httpValue;
                        httpStatement.setHost(host);
                    } else if (HeaderName.Accept.is(httpHeader) && !HeaderName.AcceptEncoding.is(httpHeader) || HeaderName.Referer.is(httpHeader) || HeaderName.ContentType.is(httpHeader)) {
                        // keep this header
                        ;
                    } else {
                        // skip this header
                        httpHeader = HttpConnector.DYNAMIC_HEADER_PREFIX + httpHeader;
                    }
                    httpStatement.addHeader(httpHeader, httpValue);
                } else {
                    // this is the request-line with HTTP verb
                    StringTokenizer stk = new StringTokenizer(line, " ");
                    while (stk.hasMoreTokens()) {
                        token = stk.nextToken();
                        if (i == 0) {
                            method = token;
                            httpStatement.setMethod(method);
                        }
                        if (i == 1) {
                            uri = token;
                            if ((index = uri.indexOf("?")) != -1) {
                                data = uri.substring(index + 1);
                                uri = uri.substring(0, index);
                                parseHttpData(httpStatement, data, "GET");
                            }
                            // set uri as constant string
                            httpStatement.setRequestUri("\"" + uri + "\"");
                        }
                        if (i == 2) {
                            version = token;
                            httpStatement.setHttpVersion(version);
                        }
                        i++;
                    }
                }
            } else {
                // there was an empty line ==> Next token is DATA
                line = st.nextToken();
                parseHttpData(httpStatement, line, "POST");
                break;
            }
        }
    } catch (Exception e) {
        ;
    }
    return httpStatement;
}
Also used : StringTokenizer(java.util.StringTokenizer) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) EngineException(com.twinsoft.convertigo.engine.EngineException) TransformerException(javax.xml.transform.TransformerException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 9 with HTTPStatement

use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.

the class StatementAddVariableToTransactionAction 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();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof HTTPStatement)) {
                HTTPStatement httpStatement = (HTTPStatement) databaseObject;
                HtmlTransaction htmlTransaction = (HtmlTransaction) httpStatement.getParentTransaction();
                List<String> variables = new ArrayList<String>();
                int i, size;
                /*size = htmlTransaction.getVariablesDefinitionSize();
    				for (i = 0 ; i < size ; i++) {
    					variables.add(htmlTransaction.getVariableDefinitionHttpName(i));
    				}*/
                size = htmlTransaction.numberOfVariables();
                for (i = 0; i < size; i++) {
                    RequestableHttpVariable httpVariable = (RequestableHttpVariable) htmlTransaction.getVariable(i);
                    variables.add(httpVariable.getHttpName());
                }
                String variableName, variableDescription, variableMethod;
                Boolean variableType, variableRequired;
                Object variableValue;
                int variableVisibility;
                size = httpStatement.numberOfVariables();
                for (i = 0; i < size; i++) {
                    HttpStatementVariable httpStatementVariable = (HttpStatementVariable) httpStatement.getVariable(i);
                    if (httpStatementVariable != null) {
                        variableName = httpStatementVariable.getName();
                        variableDescription = httpStatementVariable.getDescription();
                        variableRequired = httpStatementVariable.isRequired();
                        variableValue = httpStatementVariable.getValueOrNull();
                        variableType = httpStatementVariable.isMultiValued();
                        variableMethod = httpStatementVariable.getHttpMethod();
                        variableVisibility = httpStatementVariable.getVisibility();
                        if (!variables.contains(variableName)) {
                            RequestableHttpVariable requestableVariable = (variableType ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable());
                            requestableVariable.setName(variableName);
                            requestableVariable.setDescription(variableDescription);
                            requestableVariable.setRequired(variableRequired);
                            requestableVariable.setValueOrNull(variableValue);
                            requestableVariable.setWsdl(Boolean.TRUE);
                            requestableVariable.setPersonalizable(Boolean.FALSE);
                            requestableVariable.setCachedKey(Boolean.TRUE);
                            requestableVariable.setHttpMethod(variableMethod);
                            requestableVariable.setHttpName("");
                            requestableVariable.setVisibility(variableVisibility);
                            requestableVariable.bNew = true;
                            requestableVariable.hasChanged = true;
                            htmlTransaction.add(requestableVariable);
                        }
                    }
                }
                htmlTransaction.hasChanged = true;
                explorerView.reloadDatabaseObject(htmlTransaction);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to add HTTP variables to transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ArrayList(java.util.ArrayList) Cursor(org.eclipse.swt.graphics.Cursor) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) Shell(org.eclipse.swt.widgets.Shell) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)9 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)5 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)4 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)4 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)3 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 Statement (com.twinsoft.convertigo.beans.core.Statement)3 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)3 IOException (java.io.IOException)3 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 Criteria (com.twinsoft.convertigo.beans.core.Criteria)2 Project (com.twinsoft.convertigo.beans.core.Project)2 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)2