Search in sources :

Example 16 with HttpConnector

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

the class OpenApiUtils method createRestConnector.

public static HttpConnector createRestConnector(OpenAPI openApi) throws Exception {
    try {
        HttpConnector httpConnector = new HttpConnector();
        httpConnector.bNew = true;
        Info info = openApi.getInfo();
        String title = info != null ? info.getTitle() : "";
        title = title == null || title.isEmpty() ? "RestConnector" : title;
        String description = info != null ? info.getDescription() : "";
        description = description == null || description.isEmpty() ? "" : description;
        httpConnector.setName(StringUtils.normalize(title));
        httpConnector.setComment(description);
        String httpUrl = "";
        List<Server> servers = openApi.getServers();
        if (servers.size() > 0) {
            httpUrl = servers.get(0).getUrl();
        }
        httpUrl = httpUrl.isEmpty() ? getConvertigoServeurUrl() : httpUrl;
        UrlFields urlFields = UrlParser.parse(httpUrl);
        if (urlFields != null) {
            String scheme = urlFields.getScheme();
            String host = urlFields.getHost();
            String port = urlFields.getPort();
            String basePath = urlFields.getPath();
            boolean isHttps = "https".equals(scheme);
            httpConnector.setHttps(isHttps);
            httpConnector.setServer(host);
            httpConnector.setPort(port == null ? (isHttps ? 443 : 80) : Integer.valueOf(port));
            httpConnector.setBaseDir(basePath);
        }
        httpConnector.setBaseUrl(httpUrl);
        List<SecurityRequirement> securityRequirements = openApi.getSecurity();
        if (securityRequirements != null && securityRequirements.size() > 0) {
            Map<String, SecurityScheme> securitySchemes = openApi.getComponents().getSecuritySchemes();
            for (SecurityRequirement sr : securityRequirements) {
                for (String s_name : sr.keySet()) {
                    SecurityScheme securityScheme = securitySchemes.get(s_name);
                    if (securityScheme != null) {
                        String scheme = securityScheme.getScheme() == null ? "" : securityScheme.getScheme();
                        boolean isBasicScheme = scheme.toLowerCase().equals("basic");
                        boolean isHttpType = securityScheme.getType().equals(SecurityScheme.Type.HTTP);
                        if (isHttpType && isBasicScheme) {
                            httpConnector.setAuthenticationType(AuthenticationMode.Basic);
                            break;
                        }
                    }
                }
            }
        }
        Paths paths = openApi.getPaths();
        if (paths != null) {
            AbstractHttpTransaction defTransaction = null;
            for (Entry<String, PathItem> entry : paths.entrySet()) {
                HttpMethodType httpMethodType = null;
                Operation operation = null;
                String customHttpVerb = "";
                String subDir = entry.getKey();
                PathItem pathItem = entry.getValue();
                Map<HttpMethod, Operation> operationMap = pathItem.readOperationsMap();
                for (HttpMethod httpMethod : operationMap.keySet()) {
                    operation = operationMap.get(httpMethod);
                    if (httpMethod.equals(HttpMethod.GET)) {
                        httpMethodType = HttpMethodType.GET;
                    } else if (httpMethod.equals(HttpMethod.POST)) {
                        httpMethodType = HttpMethodType.POST;
                    } else if (httpMethod.equals(HttpMethod.PUT)) {
                        httpMethodType = HttpMethodType.PUT;
                    } else if (httpMethod.equals(HttpMethod.PATCH)) {
                        httpMethodType = HttpMethodType.PUT;
                        customHttpVerb = "PATCH";
                    } else if (httpMethod.equals(HttpMethod.DELETE)) {
                        httpMethodType = HttpMethodType.DELETE;
                    } else if (httpMethod.equals(HttpMethod.HEAD)) {
                        httpMethodType = HttpMethodType.HEAD;
                    } else if (httpMethod.equals(HttpMethod.TRACE)) {
                        httpMethodType = HttpMethodType.TRACE;
                    } else if (httpMethod.equals(HttpMethod.OPTIONS)) {
                        httpMethodType = HttpMethodType.OPTIONS;
                    } else {
                        httpMethodType = null;
                    }
                    if (operation != null && httpMethodType != null) {
                        String operationId = operation.getOperationId();
                        String operationDesc = operation.getDescription();
                        String summary = operation.getSummary();
                        String name = StringUtils.normalize(subDir + ":" + (customHttpVerb.isEmpty() ? httpMethodType.toString() : customHttpVerb));
                        if (name.isEmpty()) {
                            name = StringUtils.normalize(operationId);
                            if (name.isEmpty()) {
                                name = StringUtils.normalize(summary);
                                if (name.isEmpty()) {
                                    name = "operation";
                                }
                            }
                        }
                        String comment = org.apache.commons.lang3.StringUtils.isNotBlank(summary) && !"null".equals(summary) ? summary : (org.apache.commons.lang3.StringUtils.isNotBlank(operationDesc) && !"null".equals(operationDesc) ? operationDesc : "");
                        XMLVector<XMLVector<String>> httpParameters = new XMLVector<XMLVector<String>>();
                        AbstractHttpTransaction transaction = new HttpTransaction();
                        String h_ContentType = MimeType.WwwForm.value();
                        /*if (consumeList != null) {
								if (consumeList.contains(MimeType.Json.value())) {
									h_ContentType = MimeType.Json.value();
								}
								else if (consumeList.contains(MimeType.Xml.value())) {
									h_ContentType = MimeType.Xml.value();
								}
								else {
									h_ContentType = consumeList.size() > 0 ? 
											consumeList.get(0) : MimeType.WwwForm.value();
								}
							}*/
                        String h_Accept = MimeType.Json.value();
                        if (h_Accept != null) {
                            XMLVector<String> xmlv = new XMLVector<String>();
                            xmlv.add("Accept");
                            xmlv.add(h_Accept);
                            httpParameters.add(xmlv);
                            if (h_Accept.equals(MimeType.Xml.value())) {
                                transaction = new XmlHttpTransaction();
                                ((XmlHttpTransaction) transaction).setXmlEncoding("UTF-8");
                            } else if (h_Accept.equals(MimeType.Json.value())) {
                                transaction = new JsonHttpTransaction();
                                ((JsonHttpTransaction) transaction).setIncludeDataType(false);
                            }
                        }
                        // Add variables
                        boolean hasBodyVariable = false;
                        RequestBody body = operation.getRequestBody();
                        if (body != null) {
                            Map<String, MediaType> medias = body.getContent();
                            for (String contentType : medias.keySet()) {
                                MediaType mediaType = medias.get(contentType);
                                Schema<?> mediaSchema = mediaType.getSchema();
                                List<String> requiredList = mediaSchema.getRequired();
                                if (contentType.equals("application/x-www-form-urlencoded")) {
                                    @SuppressWarnings("rawtypes") Map<String, Schema> properties = mediaSchema.getProperties();
                                    if (properties != null) {
                                        for (String p_name : properties.keySet()) {
                                            Schema<?> schema = properties.get(p_name);
                                            String p_description = schema.getDescription();
                                            boolean p_required = requiredList == null ? false : requiredList.contains(p_name);
                                            boolean isMultiValued = false;
                                            if (schema instanceof ArraySchema) {
                                                isMultiValued = true;
                                            }
                                            RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
                                            httpVariable.bNew = true;
                                            httpVariable.setHttpMethod(HttpMethodType.POST.name());
                                            httpVariable.setName(p_name);
                                            httpVariable.setDescription(p_name);
                                            httpVariable.setHttpName(p_name);
                                            httpVariable.setRequired(p_required);
                                            httpVariable.setComment(p_description == null ? "" : p_description);
                                            if (schema instanceof FileSchema) {
                                                httpVariable.setDoFileUploadMode(DoFileUploadMode.multipartFormData);
                                            }
                                            Object defaultValue = schema.getDefault();
                                            if (defaultValue == null && p_required) {
                                                defaultValue = "";
                                            }
                                            httpVariable.setValueOrNull(defaultValue);
                                            transaction.addVariable(httpVariable);
                                        }
                                    }
                                } else if (!hasBodyVariable) {
                                    RequestableHttpVariable httpVariable = new RequestableHttpVariable();
                                    httpVariable.bNew = true;
                                    httpVariable.setHttpMethod(HttpMethodType.POST.name());
                                    httpVariable.setRequired(true);
                                    // overrides variable's name for internal use
                                    httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpBody.getName());
                                    Object defaultValue = null;
                                    httpVariable.setValueOrNull(defaultValue);
                                    transaction.addVariable(httpVariable);
                                    h_ContentType = contentType;
                                    hasBodyVariable = true;
                                }
                            }
                        }
                        List<Parameter> parameters = operation.getParameters();
                        if (parameters != null) {
                            for (Parameter parameter : parameters) {
                                String p_name = parameter.getName();
                                String p_description = parameter.getDescription();
                                boolean p_required = parameter.getRequired();
                                boolean isMultiValued = false;
                                Schema<?> schema = parameter.getSchema();
                                if (schema instanceof ArraySchema) {
                                    isMultiValued = true;
                                }
                                RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
                                httpVariable.bNew = true;
                                httpVariable.setName(p_name);
                                httpVariable.setDescription(p_name);
                                httpVariable.setHttpName(p_name);
                                httpVariable.setRequired(p_required);
                                httpVariable.setComment(p_description == null ? "" : p_description);
                                if (parameter instanceof QueryParameter || parameter instanceof PathParameter || parameter instanceof HeaderParameter) {
                                    httpVariable.setHttpMethod(HttpMethodType.GET.name());
                                    if (parameter instanceof HeaderParameter) {
                                        // overrides variable's name : will be treated as dynamic header
                                        httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpHeader.getName() + p_name);
                                        // do not post on target server
                                        httpVariable.setHttpName("");
                                    }
                                    if (parameter instanceof PathParameter) {
                                        // do not post on target server
                                        httpVariable.setHttpName("");
                                    }
                                } else {
                                    httpVariable.setHttpMethod("");
                                }
                                Object defaultValue = schema.getDefault();
                                if (defaultValue == null && p_required) {
                                    defaultValue = "";
                                }
                                httpVariable.setValueOrNull(defaultValue);
                                transaction.addVariable(httpVariable);
                            }
                        }
                        // Set Content-Type
                        if (h_ContentType != null) {
                            XMLVector<String> xmlv = new XMLVector<String>();
                            xmlv.add(HeaderName.ContentType.value());
                            xmlv.add(hasBodyVariable ? h_ContentType : MimeType.WwwForm.value());
                            httpParameters.add(xmlv);
                        }
                        transaction.bNew = true;
                        transaction.setName(name);
                        transaction.setComment(comment);
                        transaction.setSubDir(subDir);
                        transaction.setHttpVerb(httpMethodType);
                        transaction.setCustomHttpVerb(customHttpVerb);
                        transaction.setHttpParameters(httpParameters);
                        transaction.setHttpInfo(true);
                        httpConnector.add(transaction);
                        if (defTransaction == null) {
                            defTransaction = transaction;
                            httpConnector.setDefaultTransaction(defTransaction);
                        }
                    }
                }
            }
        }
        return httpConnector;
    } catch (Throwable t) {
        Engine.logEngine.error("Unable to create connector", t);
        throw new Exception("Unable to create connector", t);
    }
}
Also used : XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Server(io.swagger.v3.oas.models.servers.Server) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(io.swagger.v3.oas.models.media.Schema) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) Operation(io.swagger.v3.oas.models.Operation) AbstractRestOperation(com.twinsoft.convertigo.beans.rest.AbstractRestOperation) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MediaType(io.swagger.v3.oas.models.media.MediaType) Paths(io.swagger.v3.oas.models.Paths) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) FileSchema(io.swagger.v3.oas.models.media.FileSchema) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) UrlFields(com.twinsoft.convertigo.engine.util.UrlParser.UrlFields) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Info(io.swagger.v3.oas.models.info.Info) JSONException(org.codehaus.jettison.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) LinkParameter(io.swagger.v3.oas.models.links.LinkParameter) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) JSONObject(org.codehaus.jettison.json.JSONObject) HttpMethod(io.swagger.v3.oas.models.PathItem.HttpMethod) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement)

Example 17 with HttpConnector

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

the class SwaggerUtils method createRestConnector.

public static HttpConnector createRestConnector(Swagger swagger) throws Exception {
    try {
        HttpConnector httpConnector = new HttpConnector();
        httpConnector.bNew = true;
        Info info = swagger.getInfo();
        String title = info != null ? info.getTitle() : "";
        title = title == null || title.isEmpty() ? "RestConnector" : title;
        httpConnector.setName(StringUtils.normalize(title));
        boolean isHttps = false;
        for (Scheme scheme : swagger.getSchemes()) {
            if (scheme.equals(Scheme.HTTPS)) {
                isHttps = true;
            }
        }
        String host = swagger.getHost();
        int index = host.indexOf(":");
        String server = index == -1 ? host : host.substring(0, index);
        int port = index == -1 ? 0 : Integer.parseInt(host.substring(index + 1), 10);
        httpConnector.setHttps(isHttps);
        httpConnector.setServer(server);
        httpConnector.setPort(port <= 0 ? (isHttps ? 443 : 80) : port);
        String basePath = swagger.getBasePath();
        httpConnector.setBaseDir(basePath);
        Map<String, SecuritySchemeDefinition> securityMap = swagger.getSecurityDefinitions();
        if (securityMap != null && securityMap.size() > 0) {
            for (String securityName : securityMap.keySet()) {
                SecuritySchemeDefinition securityScheme = securityMap.get(securityName);
                if (securityScheme != null) {
                    boolean isBasicScheme = securityScheme.getType().toLowerCase().equals("basic");
                    if (isBasicScheme) {
                        httpConnector.setAuthenticationType(AuthenticationMode.Basic);
                        break;
                    }
                }
            }
        }
        List<String> _consumeList = swagger.getConsumes();
        List<String> _produceList = swagger.getProduces();
        // Map<String, Model> models = swagger.getDefinitions();
        Map<String, Path> paths = swagger.getPaths();
        for (String subDir : paths.keySet()) {
            Path path = paths.get(subDir);
            // Add transactions
            List<Operation> operations = path.getOperations();
            for (Operation operation : operations) {
                HttpMethodType httpMethodType = null;
                if (operation.equals(path.getGet())) {
                    httpMethodType = HttpMethodType.GET;
                } else if (operation.equals(path.getPost())) {
                    httpMethodType = HttpMethodType.POST;
                } else if (operation.equals(path.getPut())) {
                    httpMethodType = HttpMethodType.PUT;
                } else if (operation.equals(path.getDelete())) {
                    httpMethodType = HttpMethodType.DELETE;
                } else if (operation.equals(path.getHead())) {
                    httpMethodType = HttpMethodType.HEAD;
                } else if (operation.equals(path.getOptions())) {
                    httpMethodType = HttpMethodType.OPTIONS;
                } else {
                    httpMethodType = null;
                }
                if (httpMethodType != null) {
                    List<String> consumeList = operation.getConsumes();
                    consumeList = consumeList == null || consumeList.isEmpty() ? _consumeList : consumeList;
                    List<String> produceList = operation.getProduces();
                    produceList = produceList == null || produceList.isEmpty() ? _produceList : produceList;
                    String operationId = operation.getOperationId();
                    String description = operation.getDescription();
                    String summary = operation.getSummary();
                    String name = StringUtils.normalize(subDir + ":" + httpMethodType.toString());
                    if (name.isEmpty()) {
                        name = StringUtils.normalize(operationId);
                        if (name.isEmpty()) {
                            name = StringUtils.normalize(summary);
                            if (name.isEmpty()) {
                                name = "operation";
                            }
                        }
                    }
                    String comment = summary;
                    if (comment == null)
                        comment = "";
                    if (comment.isEmpty()) {
                        comment = description;
                    }
                    XMLVector<XMLVector<String>> httpParameters = new XMLVector<XMLVector<String>>();
                    AbstractHttpTransaction transaction = new HttpTransaction();
                    String h_ContentType = MimeType.WwwForm.value();
                    if (consumeList != null) {
                        if (consumeList.contains(MimeType.Json.value())) {
                            h_ContentType = MimeType.Json.value();
                        } else if (consumeList.contains(MimeType.Xml.value())) {
                            h_ContentType = MimeType.Xml.value();
                        } else {
                            h_ContentType = consumeList.size() > 0 ? consumeList.get(0) : MimeType.WwwForm.value();
                        }
                    }
                    String h_Accept = MimeType.Json.value();
                    if (produceList != null) {
                        if (produceList.contains(h_ContentType)) {
                            h_Accept = h_ContentType;
                        } else {
                            if (produceList.contains(MimeType.Json.value())) {
                                h_Accept = MimeType.Json.value();
                            } else if (produceList.contains(MimeType.Xml.value())) {
                                h_Accept = MimeType.Xml.value();
                            }
                        }
                        if (consumeList == null && h_Accept != null) {
                            h_ContentType = h_Accept;
                        }
                    }
                    if (h_Accept != null) {
                        XMLVector<String> xmlv = new XMLVector<String>();
                        xmlv.add("Accept");
                        xmlv.add(h_Accept);
                        httpParameters.add(xmlv);
                        if (h_Accept.equals(MimeType.Xml.value())) {
                            transaction = new XmlHttpTransaction();
                            ((XmlHttpTransaction) transaction).setXmlEncoding("UTF-8");
                        } else if (h_Accept.equals(MimeType.Json.value())) {
                            transaction = new JsonHttpTransaction();
                            ((JsonHttpTransaction) transaction).setIncludeDataType(false);
                        }
                    }
                    // Add variables
                    boolean hasBodyVariable = false;
                    List<io.swagger.models.parameters.Parameter> parameters = operation.getParameters();
                    for (io.swagger.models.parameters.Parameter parameter : parameters) {
                        // String p_access = parameter.getAccess();
                        String p_description = parameter.getDescription();
                        // String p_in = parameter.getIn();
                        String p_name = parameter.getName();
                        // String p_pattern = parameter.getPattern();
                        boolean p_required = parameter.getRequired();
                        // Map<String,Object> p_extensions = parameter.getVendorExtensions();
                        boolean isMultiValued = false;
                        if (parameter instanceof SerializableParameter) {
                            SerializableParameter serializable = (SerializableParameter) parameter;
                            if (serializable.getType().equalsIgnoreCase("array")) {
                                if (serializable.getCollectionFormat().equalsIgnoreCase("multi")) {
                                    isMultiValued = true;
                                }
                            }
                        }
                        RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
                        httpVariable.bNew = true;
                        httpVariable.setName(p_name);
                        httpVariable.setHttpName(p_name);
                        httpVariable.setRequired(p_required);
                        if (parameter instanceof QueryParameter || parameter instanceof PathParameter || parameter instanceof HeaderParameter) {
                            httpVariable.setHttpMethod(HttpMethodType.GET.name());
                            if (parameter instanceof HeaderParameter) {
                                // overrides variable's name : will be treated as dynamic header
                                httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpHeader.getName() + p_name);
                                // do not post on target server
                                httpVariable.setHttpName("");
                            }
                            if (parameter instanceof PathParameter) {
                                // do not post on target server
                                httpVariable.setHttpName("");
                            }
                        } else if (parameter instanceof FormParameter || parameter instanceof BodyParameter) {
                            httpVariable.setHttpMethod(HttpMethodType.POST.name());
                            if (parameter instanceof FormParameter) {
                                FormParameter formParameter = (FormParameter) parameter;
                                if (formParameter.getType().equalsIgnoreCase("file")) {
                                    httpVariable.setDoFileUploadMode(DoFileUploadMode.multipartFormData);
                                }
                            } else if (parameter instanceof BodyParameter) {
                                hasBodyVariable = true;
                                // overrides variable's name for internal use
                                httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpBody.getName());
                                // add internal __contentType variable
                                /*RequestableHttpVariable ct = new RequestableHttpVariable();
									ct.setName(Parameter.HttpContentType.getName());
									ct.setHttpMethod(HttpMethodType.POST.name());
									ct.setValueOrNull(null);
									ct.bNew = true;
									transaction.addVariable(ct);*/
                                BodyParameter bodyParameter = (BodyParameter) parameter;
                                Model model = bodyParameter.getSchema();
                                if (model != null) {
                                }
                            }
                        } else {
                            httpVariable.setHttpMethod("");
                        }
                        Object defaultValue = null;
                        if (parameter instanceof AbstractSerializableParameter<?>) {
                            defaultValue = ((AbstractSerializableParameter<?>) parameter).getDefaultValue();
                        }
                        if (defaultValue == null && parameter instanceof SerializableParameter) {
                            SerializableParameter serializable = (SerializableParameter) parameter;
                            if (serializable.getType().equalsIgnoreCase("array")) {
                                Property items = serializable.getItems();
                                try {
                                    Class<?> c = items.getClass();
                                    defaultValue = c.getMethod("getDefault").invoke(items);
                                } catch (Exception e) {
                                }
                            }
                        }
                        if (defaultValue == null && p_required) {
                            defaultValue = "";
                        }
                        httpVariable.setValueOrNull(defaultValue);
                        if (p_description != null) {
                            httpVariable.setDescription(p_description);
                            httpVariable.setComment(p_description);
                        }
                        transaction.addVariable(httpVariable);
                    }
                    // Set Content-Type
                    if (h_ContentType != null) {
                        XMLVector<String> xmlv = new XMLVector<String>();
                        xmlv.add(HeaderName.ContentType.value());
                        xmlv.add(hasBodyVariable ? h_ContentType : MimeType.WwwForm.value());
                        httpParameters.add(xmlv);
                    }
                    transaction.bNew = true;
                    transaction.setName(name);
                    transaction.setComment(comment);
                    transaction.setSubDir(subDir);
                    transaction.setHttpVerb(httpMethodType);
                    transaction.setHttpParameters(httpParameters);
                    transaction.setHttpInfo(true);
                    httpConnector.add(transaction);
                }
            }
        }
        return httpConnector;
    } catch (Throwable t) {
        Engine.logEngine.error("Unable to create connector", t);
        throw new Exception("Unable to create connector", t);
    }
}
Also used : SerializableParameter(io.swagger.models.parameters.SerializableParameter) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) QueryParameter(io.swagger.models.parameters.QueryParameter) Scheme(io.swagger.models.Scheme) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) Operation(io.swagger.models.Operation) AbstractRestOperation(com.twinsoft.convertigo.beans.rest.AbstractRestOperation) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) Path(io.swagger.models.Path) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Parameter(io.swagger.models.parameters.Parameter) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition) Info(io.swagger.models.Info) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) IMappingRefModel(com.twinsoft.convertigo.beans.core.IMappingRefModel) SerializableParameter(io.swagger.models.parameters.SerializableParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 18 with HttpConnector

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

the class ProjectUtils method getStatByProject.

public static Map<String, String> getStatByProject(Project project) throws Exception {
    final Map<String, String> result = new HashMap<String, String>();
    try {
        if (project != null) {
            try {
                new WalkHelper() {

                    String displayString = "";

                    @SuppressWarnings("unused")
                    int depth = 0;

                    int sequenceJavascriptLines;

                    int sequenceJavascriptFunction;

                    int connectorCount = 0;

                    int httpConnectorCount = 0;

                    int httpsConnectorCount = 0;

                    int htmlConnectorCount = 0;

                    int cicsConnectorCount = 0;

                    int siteClipperConnectorCount = 0;

                    int sqlConnectorCount = 0;

                    int javelinConnectorCount = 0;

                    int htmlScreenclassCount = 0;

                    int htmlCriteriaCount = 0;

                    int siteClipperScreenclassCount = 0;

                    int siteClipperCriteriaCount = 0;

                    int htmlExtractionRuleCount = 0;

                    int htmlTransactionVariableCount = 0;

                    int sqlTransactionVariableCount = 0;

                    int javelinTransactionVariableCount = 0;

                    int javelinScreenclassCount = 0;

                    int javelinCriteriaCount = 0;

                    int javelinExtractionRuleCount = 0;

                    int javelinEntryHandlerCount = 0;

                    int javelinExitHandlerCount = 0;

                    int javelinHandlerCount = 0;

                    int javelinJavascriptLines = 0;

                    int statementCount = 0;

                    int poolCount = 0;

                    int handlerstatementCount = 0;

                    @SuppressWarnings("unused")
                    int reqVariableCount = 0;

                    int sequenceVariableCount = 0;

                    @SuppressWarnings("unused")
                    int transactionVariableCount = 0;

                    int testcaseVariableCount = 0;

                    int testcaseCount = 0;

                    int sequenceCount = 0;

                    int stepCount = 0;

                    int sheetCount = 0;

                    int referenceCount = 0;

                    int selectInQueryCount = 0;

                    /*
    					 * transaction counters
    					 */
                    @SuppressWarnings("unused")
                    int transactionCount = 0;

                    @SuppressWarnings("unused")
                    int transactionWithVariablesCount = 0;

                    int htmltransactionCount = 0;

                    int httpTransactionCount = 0;

                    int httpsTransactionCount = 0;

                    int xmlHttpTransactionCount = 0;

                    int xmlHttpsTransactionCount = 0;

                    int jsonHttpTransactionCount = 0;

                    int jsonHttpsTransactionCount = 0;

                    int proxyTransactionCount = 0;

                    int siteClipperTransactionCount = 0;

                    int javelinTransactionCount = 0;

                    int sqlTransactionCount = 0;

                    int totalC8oObjects = 0;

                    public void go(DatabaseObject project) {
                        try {
                            String projectName = project.getName();
                            init(project);
                            connectorCount = htmlConnectorCount + httpConnectorCount + httpsConnectorCount + cicsConnectorCount + siteClipperConnectorCount + sqlConnectorCount + javelinConnectorCount;
                            totalC8oObjects = 1 + // connectors
                            connectorCount + htmlScreenclassCount + htmlCriteriaCount + htmlExtractionRuleCount + htmlTransactionVariableCount + handlerstatementCount + statementCount + javelinScreenclassCount + javelinCriteriaCount + javelinExtractionRuleCount + javelinTransactionCount + javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount + javelinTransactionVariableCount + sqlTransactionCount + sqlTransactionVariableCount + sheetCount + jsonHttpTransactionCount + jsonHttpsTransactionCount + xmlHttpTransactionCount + xmlHttpsTransactionCount + httpTransactionCount + httpsTransactionCount + proxyTransactionCount + siteClipperTransactionCount + siteClipperScreenclassCount + siteClipperCriteriaCount + sequenceCount + stepCount + sequenceVariableCount + sequenceJavascriptFunction + poolCount + referenceCount + testcaseCount + testcaseVariableCount;
                            displayString = // ok
                            totalC8oObjects + " object(s)<br/>" + connectorCount + // ok
                            " connector(s)";
                            result.put(projectName, displayString);
                            if (htmltransactionCount > 0) {
                                displayString = // ok
                                (htmlScreenclassCount > 0 ? "&nbsp;screenclassCount = " + htmlScreenclassCount + "<br/>" : "") + (htmlCriteriaCount > 0 ? "&nbsp;criteriaCount = " + htmlCriteriaCount + "<br/>" : "") + (htmlExtractionRuleCount > 0 ? "&nbsp;extractionRuleCount = " + htmlExtractionRuleCount + "<br/>" : "") + "&nbsp;transactionCount = " + htmltransactionCount + // ok
                                "<br/>" + (htmlTransactionVariableCount > 0 ? "&nbsp;transactionVariableCount = " + htmlTransactionVariableCount + "<br/>" : "") + "&nbsp;statementCount (handlers=" + handlerstatementCount + ", statements=" + statementCount + ", total=" + (int) (handlerstatementCount + statementCount) + ")";
                                result.put("HTML connector", displayString);
                            }
                            /*
								 * javelin connector
								 */
                            if (javelinScreenclassCount > 0) {
                                displayString = // ok
                                "&nbsp;screenclassCount = " + javelinScreenclassCount + "<br/>" + (javelinCriteriaCount > 0 ? "&nbsp;criteriaCount = " + javelinCriteriaCount + "<br/>" : "") + (javelinExtractionRuleCount > 0 ? "&nbsp;extractionRuleCount = " + javelinExtractionRuleCount + "<br/>" : "") + // ok
                                (javelinTransactionCount > 0 ? "&nbsp;transactionCount = " + javelinTransactionCount + "<br/>" : "") + "&nbsp;handlerCount (Entry = " + javelinEntryHandlerCount + ", Exit = " + javelinExitHandlerCount + ", Screenclass = " + javelinHandlerCount + "), total = " + (int) (javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount) + " in " + javelinJavascriptLines + " lines<br/>" + (javelinTransactionVariableCount > 0 ? "&nbsp;variableCount = " + javelinTransactionVariableCount : "");
                                result.put("Javelin connector", displayString);
                            }
                            /*
								 * SQL connector
								 */
                            if (sqlTransactionCount > 0) {
                                displayString = // ok
                                "&nbsp;sqltransactionCount = " + sqlTransactionCount + "<br/>" + // ok
                                (selectInQueryCount > 0 ? "&nbsp;selectInQueryCount = " + selectInQueryCount + "<br/>" : "") + (sqlTransactionVariableCount > 0 ? "&nbsp;transactionVariableCount = " + sqlTransactionVariableCount : "");
                                if (sheetCount > 0) {
                                    displayString += "<br/>Sheets<br/>" + "&nbsp;sheetCount = " + sheetCount;
                                }
                                result.put("SQL connector", displayString);
                            }
                            /*
								 * Http connector
								 */
                            if (httpConnectorCount > 0) {
                                displayString = "&nbsp;connectorCount = " + httpConnectorCount + "<br/>";
                            }
                            if (jsonHttpTransactionCount > 0) {
                                displayString += // ok
                                "&nbsp;JSONTransactionCount = " + jsonHttpTransactionCount + "<br/>" + // ok
                                (xmlHttpTransactionCount > 0 ? "&nbsp;XmlTransactionCount = " + xmlHttpTransactionCount + "<br/>" : "") + (httpTransactionCount > 0 ? "&nbsp;HTTPtransactionCount = " + httpTransactionCount : "");
                                result.put("HTTP connector", displayString);
                            }
                            /*
								 * Https connector
								 */
                            if (httpsConnectorCount > 0) {
                                displayString = "&nbsp;connectorCount = " + httpsConnectorCount + "<br/>" + // ok
                                (jsonHttpsTransactionCount > 0 ? "&nbsp;JSONTransactionCount = " + jsonHttpsTransactionCount + "<br/>" : "") + // ok
                                (xmlHttpsTransactionCount > 0 ? "&nbsp;XmlTransactionCount = " + xmlHttpsTransactionCount + "<br/>" : "") + // ok
                                (httpsTransactionCount > 0 ? "&nbsp;HTTPStransactionCount = " + httpsTransactionCount : "");
                                result.put("HTTPS connector", displayString);
                            }
                            /*
								 * Proxy connector
								 */
                            if (proxyTransactionCount > 0) {
                                displayString = "&nbsp;TransactionCount = " + proxyTransactionCount;
                                result.put("Proxy connector", displayString);
                            }
                            /*
								 * Siteclipper connector
								 */
                            if (siteClipperTransactionCount > 0) {
                                displayString = // ok
                                "&nbsp;TransactionCount = " + siteClipperTransactionCount + "<br/>" + // ok
                                (siteClipperScreenclassCount > 0 ? "&nbsp;screenclassCount = " + siteClipperScreenclassCount + "<br/>" : "") + (siteClipperCriteriaCount > 0 ? "&nbsp;criteriaCount = " + siteClipperCriteriaCount : "");
                                result.put("SiteClipper connector", displayString);
                            }
                            /*
								 * Sequencer
								 */
                            if (sequenceCount > 0) {
                                displayString = // ok
                                "&nbsp;sequenceCount = " + sequenceCount + "<br/>" + // ok
                                (stepCount > 0 ? "&nbsp;stepCount = " + stepCount + "<br/>" : "") + (sequenceVariableCount > 0 ? "&nbsp;variableCount = " + sequenceVariableCount + "<br/>" : "") + "&nbsp;javascriptCode = " + sequenceJavascriptFunction + " functions in " + sequenceJavascriptLines + " lines" + ((boolean) (sequenceJavascriptFunction == 0) ? " (declarations or so)" : "");
                                result.put("Sequencer", displayString);
                            }
                            if (poolCount > 0) {
                                displayString = "&nbsp;poolCount = " + poolCount;
                                result.put("Pools", displayString);
                            }
                            if (referenceCount > 0) {
                                displayString = "&nbsp;referenceCount = " + referenceCount;
                                result.put("References", displayString);
                            }
                            if (testcaseCount > 0) {
                                displayString = "&nbsp;testcaseCount = " + testcaseCount + "<br/>" + (testcaseVariableCount > 0 ? "&nbsp;testcaseVariableCount = " + testcaseVariableCount : "");
                                result.put("Test cases", displayString);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        depth++;
                        // deal with connectors
                        if (databaseObject instanceof Connector) {
                            if (databaseObject instanceof HtmlConnector) {
                                htmlConnectorCount++;
                            } else if (databaseObject instanceof HttpConnector) {
                                if (((HttpConnector) databaseObject).isHttps())
                                    httpsConnectorCount++;
                                else
                                    httpConnectorCount++;
                            } else if (databaseObject instanceof CicsConnector) {
                                cicsConnectorCount++;
                            } else if (databaseObject instanceof SiteClipperConnector) {
                                siteClipperConnectorCount++;
                            } else if (databaseObject instanceof SqlConnector) {
                                sqlConnectorCount++;
                            } else if (databaseObject instanceof JavelinConnector) {
                                javelinConnectorCount++;
                            }
                        } else // deal with screenclasses
                        if (databaseObject instanceof ScreenClass) {
                            if (databaseObject instanceof JavelinScreenClass) {
                                // deal with javelinScreenClasses
                                javelinScreenclassCount++;
                            } else if (databaseObject instanceof SiteClipperScreenClass) {
                                // deal with siteClipperScreenClasses
                                siteClipperScreenclassCount++;
                            } else {
                                // deal with html ScreenClasses
                                htmlScreenclassCount++;
                            }
                        } else if (databaseObject instanceof Criteria) {
                            if (databaseObject.getParent() instanceof JavelinScreenClass) {
                                javelinCriteriaCount++;
                            } else if (databaseObject.getParent() instanceof SiteClipperScreenClass) {
                                siteClipperCriteriaCount++;
                            } else {
                                htmlCriteriaCount++;
                            }
                        } else if (databaseObject instanceof ExtractionRule) {
                            if (databaseObject.getParent() instanceof JavelinScreenClass) {
                                javelinExtractionRuleCount++;
                            } else {
                                htmlExtractionRuleCount++;
                            }
                        } else if (databaseObject instanceof Transaction) {
                            if (databaseObject instanceof TransactionWithVariables) {
                                if (databaseObject instanceof HtmlTransaction) {
                                    htmltransactionCount++;
                                } else if (databaseObject instanceof JsonHttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        jsonHttpsTransactionCount++;
                                    else
                                        jsonHttpTransactionCount++;
                                } else if (databaseObject instanceof HttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        httpsTransactionCount++;
                                    else
                                        httpTransactionCount++;
                                } else if (databaseObject instanceof XmlHttpTransaction) {
                                    if (((HttpConnector) databaseObject.getParent()).isHttps())
                                        xmlHttpsTransactionCount++;
                                    else
                                        xmlHttpTransactionCount++;
                                } else if (databaseObject instanceof ProxyTransaction) {
                                    proxyTransactionCount++;
                                } else if (databaseObject instanceof SiteClipperTransaction) {
                                    siteClipperTransactionCount++;
                                } else if (databaseObject instanceof JavelinTransaction) {
                                    JavelinTransaction javelinTransaction = (JavelinTransaction) databaseObject;
                                    // Functions
                                    String line;
                                    int lineNumber = 0;
                                    BufferedReader br = new BufferedReader(new StringReader(javelinTransaction.handlers));
                                    while ((line = br.readLine()) != null) {
                                        line = line.trim();
                                        lineNumber++;
                                        if (line.startsWith("function ")) {
                                            try {
                                                String functionName = line.substring(9, line.indexOf(')') + 1);
                                                if (functionName.endsWith(JavelinTransaction.EVENT_ENTRY_HANDLER + "()")) {
                                                    // TYPE_FUNCTION_SCREEN_CLASS_ENTRY
                                                    javelinEntryHandlerCount++;
                                                } else if (functionName.endsWith(JavelinTransaction.EVENT_EXIT_HANDLER + "()")) {
                                                    // TYPE_FUNCTION_SCREEN_CLASS_EXIT
                                                    javelinExitHandlerCount++;
                                                } else {
                                                    // TYPE_OTHER
                                                    javelinHandlerCount++;
                                                }
                                            } catch (StringIndexOutOfBoundsException e) {
                                            // Ignore
                                            }
                                        }
                                    }
                                    // compute total number of lines of javascript
                                    javelinJavascriptLines += lineNumber;
                                    javelinTransactionCount++;
                                } else if (databaseObject instanceof SqlTransaction) {
                                    SqlTransaction sqlTransaction = (SqlTransaction) databaseObject;
                                    /*
										 * count the number of SELECT
										 */
                                    String query = sqlTransaction.getSqlQuery();
                                    if (query != null) {
                                        query = query.toLowerCase();
                                        String pattern = "select";
                                        int lastIndex = 0;
                                        while (lastIndex != -1) {
                                            lastIndex = query.indexOf(pattern, lastIndex);
                                            if (lastIndex != -1) {
                                                selectInQueryCount++;
                                                lastIndex += pattern.length();
                                            }
                                        }
                                    }
                                    sqlTransactionCount++;
                                }
                                transactionWithVariablesCount++;
                            } else {
                                // transaction with no variables
                                transactionCount++;
                            }
                        } else // deal with statements
                        if (databaseObject instanceof Statement) {
                            // System.out.println(databaseObject.getClass().getName() + "\r\n");
                            if (databaseObject instanceof HandlerStatement) {
                                handlerstatementCount++;
                            } else {
                                statementCount++;
                            }
                        } else // deal with variables
                        if (databaseObject instanceof Variable) {
                            if (databaseObject.getParent() instanceof Transaction) {
                                if (databaseObject.getParent() instanceof JavelinTransaction) {
                                    javelinTransactionVariableCount++;
                                } else if (databaseObject.getParent() instanceof HtmlTransaction) {
                                    htmlTransactionVariableCount++;
                                } else if (databaseObject.getParent() instanceof SqlTransaction) {
                                    sqlTransactionVariableCount++;
                                } else {
                                    // should be zero
                                    transactionVariableCount++;
                                }
                            } else if (databaseObject.getParent() instanceof Sequence) {
                                sequenceVariableCount++;
                            } else if (databaseObject.getParent() instanceof TestCase) {
                                testcaseVariableCount++;
                            }
                        } else if (databaseObject instanceof TestCase) {
                            testcaseCount++;
                        } else if (databaseObject instanceof Sequence) {
                            sequenceCount++;
                        } else if (databaseObject instanceof Step) {
                            if (databaseObject instanceof SimpleStep) {
                                SimpleStep simpleStep = (SimpleStep) databaseObject;
                                // Functions
                                String line;
                                int lineNumber = 0;
                                BufferedReader br = new BufferedReader(new StringReader(simpleStep.getExpression()));
                                while ((line = br.readLine()) != null) {
                                    line = line.trim();
                                    lineNumber++;
                                    if (line.startsWith("function ")) {
                                        try {
                                            sequenceJavascriptFunction++;
                                        } catch (StringIndexOutOfBoundsException e) {
                                        // Ignore
                                        }
                                    }
                                }
                                sequenceJavascriptLines += lineNumber;
                                stepCount++;
                            } else
                                stepCount++;
                        } else if (databaseObject instanceof Sheet) {
                            sheetCount++;
                        } else if (databaseObject instanceof Pool) {
                            poolCount++;
                        }
                        super.walk(databaseObject);
                    }
                }.go(project);
            } catch (Exception e) {
            // Just ignore, should never happen
            }
        }
    } catch (Throwable e) {
        throw new Exception("Unable to compute statistics of the project!: \n" + e.getMessage());
    } finally {
    }
    return result;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Variable(com.twinsoft.convertigo.beans.core.Variable) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) HashMap(java.util.HashMap) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) SiteClipperScreenClass(com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) SiteClipperScreenClass(com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) Step(com.twinsoft.convertigo.beans.core.Step) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) ProxyTransaction(com.twinsoft.convertigo.engine.proxy.translated.ProxyTransaction) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) StringReader(java.io.StringReader) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Pool(com.twinsoft.convertigo.beans.core.Pool) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) TransformerException(javax.xml.transform.TransformerException) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) ProxyTransaction(com.twinsoft.convertigo.engine.proxy.translated.ProxyTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) BufferedReader(java.io.BufferedReader) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 19 with HttpConnector

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

the class WsReference method importRestWebService.

private static HttpConnector importRestWebService(Project project, RestServiceReference restServiceReference) throws Exception {
    try {
        HttpConnector httpConnector = null;
        if (restServiceReference == null) {
            throw new Exception("Reference is null");
        }
        Object restApi = null;
        String urlPath = restServiceReference.getUrlpath();
        if (urlPath.startsWith("http")) {
            // Try to parse as a Swagger definition (oas2)
            restApi = new SwaggerParser().read(urlPath);
            // Try to parse as an OpenAPI definition (oas3)
            if (restApi == null) {
                restApi = new OpenAPIV3Parser().read(urlPath);
            }
        } else if (urlPath.startsWith("file")) {
            URL url = new URL(urlPath);
            File f = FileUtils.toFile(url);
            String filePath = f.getAbsolutePath();
            // Try to parse as a Swagger definition (oas2)
            restApi = new SwaggerParser().read(filePath);
            // Try to parse as an OpenAPI definition (oas3)
            if (restApi == null) {
                restApi = new OpenAPIV3Parser().read(filePath);
            }
        }
        if (restApi != null) {
            httpConnector = createRestConnector(restApi);
        } else // Try to parse as a ? definition
        {
            throw new Exception("Invalid REST definition");
        }
        if (httpConnector != null) {
            project.add(httpConnector);
            if (project.getDefaultConnector() == null) {
                project.setDefaultConnector(httpConnector);
            }
            project.hasChanged = true;
        }
        return httpConnector;
    } catch (Throwable t) {
        throw new Exception("Unable to import REST service", t);
    }
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) URL(java.net.URL)

Example 20 with HttpConnector

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

the class WsReference method createSoapConnector.

private static HttpConnector createSoapConnector(WsdlInterface iface) throws Exception {
    HttpConnector httpConnector = null;
    if (iface != null) {
        String[] endPoints = iface.getEndpoints();
        if (endPoints.length > 0) {
            String comment = iface.getDescription();
            try {
                comment = (comment.equals("") ? iface.getBinding().getDocumentationElement().getTextContent() : comment);
            } catch (Exception e) {
            }
            String endPoint = endPoints[0];
            String host, server, port, baseDir;
            boolean isHttps = endPoint.startsWith("https://");
            if (endPoint.indexOf("://") != -1) {
                int beginIndex = endPoint.indexOf("://") + "://".length();
                int endIndex = endPoint.indexOf("/", beginIndex);
                if (endIndex != -1) {
                    host = endPoint.substring(beginIndex, endIndex);
                    baseDir = endPoint.substring(endIndex + 1);
                } else {
                    host = endPoint.substring(beginIndex);
                    baseDir = "";
                }
                int middleIndex = host.indexOf(":");
                if (middleIndex != -1) {
                    server = host.substring(0, middleIndex);
                    port = host.substring(middleIndex + 1);
                } else {
                    server = host;
                    port = isHttps ? "443" : "80";
                }
            } else {
                server = endPoint;
                port = isHttps ? "443" : "80";
                baseDir = "";
            }
            httpConnector = new HttpConnector();
            httpConnector.bNew = true;
            httpConnector.setComment(comment);
            httpConnector.setHttps(isHttps);
            httpConnector.setServer(server);
            httpConnector.setPort(Integer.valueOf(port).intValue());
            httpConnector.setBaseDir("/" + baseDir);
            httpConnector.hasChanged = true;
        }
    }
    return httpConnector;
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

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