Search in sources :

Example 6 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class Biller method insertVicBilling.

public void insertVicBilling(Context context, Object data) {
    String sSqlRequest = null;
    try {
        Engine.logBillers.debug("[Biller] Trying to insert the billing into a VIC database ");
        sqlRequester.checkConnection();
        CertificateManager certificateManager = ((HttpConnector) context.getConnector()).certificateManager;
        if (!certificateManager.storeInformationCollected) {
            certificateManager.collectStoreInformation(context);
        }
        int cache = 0;
        double cost = getCost(context, data);
        if (cost == -1) {
            Engine.logBillers.debug("[Biller] Billing aborted because the returned cost is -1, i.e. do not need to bill.");
            return;
        } else if (cost == -2) {
            Engine.logBillers.debug("[Biller] Billing zero cost because the response was in cache.");
            cost = 0;
            cache = 1;
        }
        TransactionWithVariables transaction = null;
        try {
            transaction = (TransactionWithVariables) context.requestedObject;
        } catch (ClassCastException e) {
            throw new Exception("Requested object is not a transaction");
        }
        StringEx sqlRequest = new StringEx(sqlRequester.getProperty(Biller.PROPERTIES_SQL_REQUEST_INSERT_BILLING));
        sqlRequest.replace("{UserName}", context.tasUserName);
        sqlRequest.replace("{UserGroup}", context.tasUserGroup);
        sqlRequest.replace("{Service}", context.tasServiceCode);
        sqlRequest.replace("{CVX25}", "0");
        String cdbanque = transaction.getVariableValue("cdbanque").toString();
        if (cdbanque == null)
            cdbanque = context.get("cdbanque").toString();
        String cdguichet = transaction.getVariableValue("cdguichet").toString();
        if (cdguichet == null)
            cdguichet = context.get("cdguichet").toString();
        sqlRequest.replace("{CodeBanque}", cdbanque);
        sqlRequest.replace("{CodeGuichet}", cdguichet);
        String certificate = new File(certificateManager.keyStore).getName();
        int idx = certificate.indexOf('.');
        if (idx != -1) {
            certificate = certificate.substring(0, idx);
        }
        sqlRequest.replace("{Certificat}", certificate);
        sqlRequest.replace("{Cache}", Integer.toString(cache));
        Engine.logBillers.debug("[Biller] Replacement done");
        Calendar rightNow = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat(sqlRequester.getProperty(Biller.PROPERTIES_SQL_DATE_FORMAT));
        String date = df.format(rightNow.getTime());
        sqlRequest.replace("{StartHour}", date);
        sqlRequest.replace("{EndHour}", date);
        Engine.logBillers.debug("[Biller] Start and End hour done");
        sqlRequest.replace("{NomSv}", context.tasVirtualServerName);
        Engine.logBillers.debug("[Biller] NomSv done");
        sqlRequest.replace("{Cost}", Double.toString(cost));
        Engine.logBillers.debug("[Biller] Cost Done");
        sSqlRequest = sqlRequest.toString();
        Engine.logBillers.debug("[Biller] SQL: " + sSqlRequest);
        Statement statement = null;
        long startBilling = System.currentTimeMillis();
        try {
            statement = sqlRequester.connection.createStatement();
            int nResult = statement.executeUpdate(sSqlRequest);
            Engine.logBillers.debug("[Biller] " + nResult + " row(s) inserted.");
        } finally {
            if (statement != null) {
                statement.close();
            }
            Engine.logBillers.info("[Biller] insertVicBilling, 1 request in " + (System.currentTimeMillis() - startBilling) + " ms");
        }
    } catch (SQLException e) {
        Engine.logBillers.warn("[Biller] Unable to insert the billing.\n" + e.getMessage() + " (error code: " + e.getErrorCode() + ")\nSQL: " + sSqlRequest);
    } catch (Exception e) {
        Engine.logBillers.error("[Biller] Unable to insert the billing", e);
    }
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Calendar(java.util.Calendar) IOException(java.io.IOException) SQLException(java.sql.SQLException) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) StringEx(com.twinsoft.util.StringEx) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class HttpBridge method convertIncomingRequest.

public static void convertIncomingRequest(ParameterShuttle infoShuttle) {
    HttpConnector connector = (HttpConnector) infoShuttle.context.getConnector();
    connector.setBaseUrl();
    // compose target siteURL by Http Bridge parameters
    String bridgeGoto = infoShuttle.userGoto;
    // BUGFIX: if the url contains blank spaces, replace them by "%20"
    if (bridgeGoto != null) {
        StringEx sx = new StringEx(bridgeGoto);
        sx.replaceAll(" ", "%20");
        bridgeGoto = sx.toString();
    }
    String bridgeThen = infoShuttle.userThen;
    // BUGFIX: if the url contains blank spaces, replace them by "%20"
    if (bridgeThen != null) {
        StringEx sx = new StringEx(bridgeThen);
        sx.replaceAll(" ", "%20");
        bridgeThen = sx.toString();
    }
    if (bridgeGoto == null) {
        bridgeGoto = connector.sUrl;
    } else if (!bridgeGoto.startsWith(connector.sUrl)) {
        bridgeGoto = connector.sUrl + bridgeGoto;
    }
    Engine.logEngine.debug("(Proxy) goto: " + bridgeGoto);
    Engine.logEngine.debug("(Proxy) then: " + bridgeThen);
    if (bridgeGoto == null)
        bridgeGoto = infoShuttle.prevSiteURL.toString();
    URI gotoURI = null, thenURI = null;
    if (bridgeThen != null) {
        try {
            thenURI = new URI(bridgeThen);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("2nd target address in wrong syntax: " + bridgeThen);
        }
        if (thenURI.isAbsolute()) {
            gotoURI = thenURI;
            thenURI = null;
            bridgeGoto = bridgeThen;
            bridgeThen = null;
        }
    }
    if (gotoURI == null) {
        try {
            if (bridgeGoto.charAt(0) == '/' && infoShuttle.siteURL != null) {
                if (bridgeGoto.startsWith("//"))
                    gotoURI = new URI(infoShuttle.siteURL.getProtocol() + ":" + bridgeGoto);
                else
                    gotoURI = new URI(infoShuttle.siteURL.getProtocol() + "://" + infoShuttle.siteURL.getHost() + (infoShuttle.siteURL.getPort() == -1 ? "" : ":" + infoShuttle.siteURL.getPort()) + bridgeGoto);
            } else if (bridgeGoto.indexOf("://") < 0)
                gotoURI = new URI("http://" + bridgeGoto);
            else
                gotoURI = new URI(bridgeGoto);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("main target address in wrong syntax: " + bridgeGoto);
        }
    }
    if (gotoURI.getScheme() == null || !gotoURI.getScheme().startsWith("http"))
        throw new IllegalArgumentException("missing or unsupported protocol in address: " + bridgeGoto);
    if (gotoURI.getHost() == null)
        throw new IllegalArgumentException("missing server in address: " + bridgeGoto);
    if (thenURI != null)
        gotoURI = gotoURI.resolve(thenURI);
    if (infoShuttle.postFromUser && !infoShuttle.postToSite) {
        StringBuffer sb = new StringBuffer(128 + infoShuttle.userContentLength);
        sb.append(gotoURI.getScheme()).append("://").append(gotoURI.getHost());
        if (gotoURI.getPort() != -1)
            sb.append(":").append(gotoURI.getPort());
        sb.append(gotoURI.getPath()).append("?");
        try {
            sb.append(infoShuttle.userPostData);
            infoShuttle.siteURL = new URL(sb.toString());
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Cannot compose an URL (A): " + sb.toString());
        }
    } else {
        try {
            infoShuttle.siteURL = gotoURI.toURL();
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Cannot compose an URL (B): " + gotoURI.toString());
        }
    }
    // filter http headers
    int index = 0;
    while (index < infoShuttle.userHeaderNames.size()) {
        String name = (String) infoShuttle.userHeaderNames.get(index);
        int pos = findString(name, ALL_HEADERS, AllowedToRequest, true);
        if (pos == -1 || (pos == HH_CONTENT_TYPE && !infoShuttle.postToSite)) {
            infoShuttle.userHeaderNames.remove(index);
            infoShuttle.userHeaderValues.remove(index);
            continue;
        }
        index++;
    }
    // always set Accept-Encoding to empty
    infoShuttle.userHeaderNames.add(ALL_HEADERS[HH_ACCEPT_ENCODING]);
    infoShuttle.userHeaderValues.add("");
    // compose cookie for target site
    String serverCookieStr = cookieMgr.getServerCookieString(infoShuttle.sessionID, infoShuttle.siteURL.getHost(), infoShuttle.siteURL.getPath());
    if (serverCookieStr != null) {
        infoShuttle.userHeaderNames.add("cookie");
        infoShuttle.userHeaderValues.add(serverCookieStr);
    }
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) StringEx(com.twinsoft.util.StringEx) URI(java.net.URI) URL(java.net.URL)

Example 8 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class HttpClient method connect.

public void connect(ParameterShuttle infoShuttle) throws Exception {
    boolean noEncoding = false;
    boolean zipEncoding = false;
    boolean doConvert = false;
    HttpConnector connector = (HttpConnector) infoShuttle.context.getConnector();
    // filter/convert http headers before they are outgoing to remote site
    HttpBridge.convertIncomingRequest(infoShuttle);
    // create HttpURLConnection
    Engine.logEngine.debug("(HttpClient) Site URL: " + infoShuttle.siteURL);
    String resourceUrl = infoShuttle.siteURL.toString();
    infoShuttle.siteInputStream = ProxyServletRequester.proxyCacheManager.getResource(resourceUrl);
    if (infoShuttle.siteInputStream == null) {
        Engine.logEngine.debug("(HttpClient) Resource requested: " + resourceUrl);
        // Getting result
        Engine.logEngine.debug("(HttpClient) Getting response");
        byte[] result = getData(connector, resourceUrl, infoShuttle);
        Engine.logEngine.trace("(HttpClient) Data received:\n" + new String(result));
        // get connected and get info from HTTP headers and save them into ParameterShuttle
        infoShuttle.httpCode = method.getStatusCode();
        Engine.logEngine.debug("(HttpClient) Response code: " + infoShuttle.httpCode);
        Header contentLength = method.getResponseHeader("Content-Length");
        if (contentLength != null)
            infoShuttle.siteContentSize = Integer.parseInt(contentLength.getValue());
        Header contentType = method.getResponseHeader("Content-Type");
        if (contentType != null)
            infoShuttle.siteContentType = contentType.getValue();
        Engine.logEngine.debug("(HttpClient) Content type: " + infoShuttle.siteContentType);
        infoShuttle.siteContentHTML = infoShuttle.siteContentType != null && infoShuttle.siteContentType.toLowerCase().startsWith("text/html");
        if (infoShuttle.siteContentHTML) {
            noEncoding = true;
            Header encodingHeader = method.getResponseHeader("Content-Encoding");
            if (encodingHeader != null) {
                String contentEncoding = encodingHeader.getValue();
                if (contentEncoding == null || contentEncoding.length() == 0)
                    noEncoding = true;
                else if (contentEncoding.toLowerCase().equals("gzip"))
                    zipEncoding = true;
            }
            doConvert = noEncoding || zipEncoding;
        }
        // filter/convert http headers before they are outgoing to user
        Engine.logEngine.debug("(HttpClient) Outcoming HTTP headers:");
        Header[] headers = method.getResponseHeaders();
        Header header;
        String value, key;
        for (int index = 0; index < headers.length; index++) {
            header = headers[index];
            value = header.getValue();
            key = header.getName();
            if (key == null)
                continue;
            infoShuttle.siteHeaderNames.add(key.toLowerCase());
            infoShuttle.siteHeaderValues.add(value);
            Engine.logEngine.debug(key.toLowerCase() + "=" + value);
        }
        HttpBridge.convertOutgoingHeaders(infoShuttle, !doConvert);
        try {
            infoShuttle.siteInputStream = method.getResponseBodyAsStream();
        } catch (Exception e) {
            return;
        }
        Engine.logEngine.debug("(HttpClient) Connection opened");
    } else {
        Engine.logEngine.debug("(HttpClient) Resource returned from the cache: " + resourceUrl);
        CacheEntry cacheEntry = ProxyServletRequester.proxyCacheManager.getCacheEntry(resourceUrl);
        infoShuttle.siteContentSize = cacheEntry.contentLength;
        infoShuttle.siteContentType = cacheEntry.contentType;
        infoShuttle.siteContentHTML = false;
    }
    // choose right InputStream to output to browser
    if (doConvert) {
        if (zipEncoding) {
            infoShuttle.siteInputStream = htmlInputStream.open(infoShuttle, new GZIPInputStream(infoShuttle.siteInputStream), infoShuttle.siteURL);
        } else if (noEncoding) {
            infoShuttle.siteInputStream = htmlInputStream.open(infoShuttle, infoShuttle.siteInputStream, infoShuttle.siteURL);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Header(org.apache.commons.httpclient.Header) CacheEntry(com.twinsoft.convertigo.engine.proxy.cache.CacheEntry) URIException(org.apache.commons.httpclient.URIException) ConnectionException(com.twinsoft.convertigo.beans.connectors.ConnectionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 9 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class ObjectInfoWizardPage method createControl.

public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Name:");
    beanName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    beanName.setLayoutData(gd);
    beanName.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged(false);
        }
    });
    if (parentObject instanceof CouchDbConnector || parentObject instanceof FullSyncConnector) {
        couchVariablesComposite = new CouchVariablesComposite(container, SWT.V_SCROLL);
        gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalSpan = 2;
        couchVariablesComposite.setLayoutData(gd);
    } else if (parentObject instanceof HttpConnector) {
        httpTransactionVariablesComposite = new HttpTransactionVariablesComposite(container, SWT.V_SCROLL);
        gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalSpan = 2;
        httpTransactionVariablesComposite.setLayoutData(gd);
    } else {
        tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
        tree.setHeaderVisible(false);
        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        gd.verticalSpan = 20;
        gd.horizontalSpan = 2;
        tree.setLayoutData(gd);
        tree.addListener(SWT.Selection, new Listener() {

            public void handleEvent(final Event event) {
                TreeItem item = (TreeItem) event.item;
                treeItemName = item.getText();
                String suffix = getBeanName().endsWith(ScHandlerStatement.EVENT_ENTRY_HANDLER) ? ScHandlerStatement.EVENT_ENTRY_HANDLER : getBeanName().endsWith(ScHandlerStatement.EVENT_EXIT_HANDLER) ? ScHandlerStatement.EVENT_EXIT_HANDLER : "";
                setBeanName("on" + treeItemName + suffix);
                dialogChanged(true);
            }
        });
        tree.setVisible(false);
    }
    initialize();
    dialogChanged(true);
    setControl(container);
}
Also used : CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) HttpTransactionVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.HttpTransactionVariablesComposite) CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) HttpTransactionVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.HttpTransactionVariablesComposite) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event)

Example 10 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector 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, false);
            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();
                project.hasChanged = true;
            }
            updateProjectTreeView();
        } 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)

Aggregations

HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)23 EngineException (com.twinsoft.convertigo.engine.EngineException)10 IOException (java.io.IOException)9 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)6 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)6 File (java.io.File)6 HttpTransaction (com.twinsoft.convertigo.beans.transactions.HttpTransaction)5 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)5 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)4 Project (com.twinsoft.convertigo.beans.core.Project)4 JsonHttpTransaction (com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 JSONException (org.codehaus.jettison.json.JSONException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)3 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)3 Connector (com.twinsoft.convertigo.beans.core.Connector)3