use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.
the class SwaggerUtils method createRestConnector.
@SuppressWarnings("unused")
private static HttpConnector createRestConnector(JSONObject json) throws Exception {
try {
HttpConnector httpConnector = new HttpConnector();
httpConnector.bNew = true;
JSONObject info = json.getJSONObject("info");
httpConnector.setName(StringUtils.normalize(info.getString("title")));
String host = json.getString("host");
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.setServer(server);
httpConnector.setPort(port <= 0 ? 80 : port);
String basePath = json.getString("basePath");
httpConnector.setBaseDir(basePath);
JSONArray _consumes = new JSONArray();
if (json.has("consumes")) {
_consumes = json.getJSONArray("consumes");
}
JSONArray _produces = new JSONArray();
if (json.has("produces")) {
_produces = json.getJSONArray("produces");
}
Map<String, JSONObject> models = new HashMap<String, JSONObject>();
JSONObject definitions = new JSONObject();
if (json.has("definitions")) {
definitions = json.getJSONObject("definitions");
for (Iterator<String> i = GenericUtils.cast(definitions.keys()); i.hasNext(); ) {
String key = i.next();
JSONObject model = definitions.getJSONObject(key);
models.put(key, model);
}
}
JSONObject paths = json.getJSONObject("paths");
for (Iterator<String> i1 = GenericUtils.cast(paths.keys()); i1.hasNext(); ) {
String subDir = i1.next();
JSONObject path = paths.getJSONObject(subDir);
for (Iterator<String> i2 = GenericUtils.cast(path.keys()); i2.hasNext(); ) {
String httpVerb = i2.next();
JSONObject verb = path.getJSONObject(httpVerb);
XMLVector<XMLVector<String>> httpParameters = new XMLVector<XMLVector<String>>();
AbstractHttpTransaction transaction = new HttpTransaction();
JSONArray consumes = verb.has("consumes") ? verb.getJSONArray("consumes") : _consumes;
List<String> consumeList = new ArrayList<String>();
for (int i = 0; i < consumes.length(); i++) {
consumeList.add(consumes.getString(i));
}
String h_ContentType = null;
if (consumeList.contains(MimeType.Xml.value())) {
h_ContentType = MimeType.Xml.value();
} else if (consumeList.contains(MimeType.Json.value())) {
h_ContentType = MimeType.Json.value();
} else {
h_ContentType = consumeList.size() > 0 ? consumeList.get(0) : MimeType.WwwForm.value();
}
JSONArray produces = verb.has("produces") ? verb.getJSONArray("produces") : _produces;
List<String> produceList = new ArrayList<String>();
for (int i = 0; i < produces.length(); i++) {
produceList.add(produces.getString(i));
}
String h_Accept = null;
if (produceList.contains(h_ContentType)) {
h_Accept = h_ContentType;
} else {
if (produceList.contains(MimeType.Xml.value())) {
h_Accept = MimeType.Xml.value();
} else if (produceList.contains(MimeType.Json.value())) {
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);
}
}
if (h_ContentType != null) {
XMLVector<String> xmlv = new XMLVector<String>();
xmlv.add(HeaderName.ContentType.value());
xmlv.add(h_ContentType);
httpParameters.add(xmlv);
}
String operationId = "";
if (verb.has("operationId")) {
operationId = verb.getString("operationId");
}
String summary = "";
if (verb.has("summary")) {
summary = verb.getString("summary");
}
String description = "";
if (verb.has("description")) {
description = verb.getString("description");
}
String name = StringUtils.normalize(operationId);
if (name.isEmpty()) {
name = StringUtils.normalize(summary);
if (name.isEmpty()) {
name = "operation";
}
}
String comment = summary;
if (comment.isEmpty()) {
comment = description;
}
JSONArray parameters = new JSONArray();
if (verb.has("parameters")) {
parameters = verb.getJSONArray("parameters");
for (int i = 0; i < parameters.length(); i++) {
JSONObject parameter = (JSONObject) parameters.get(i);
String type = "string";
if (parameter.has("collectionFormat")) {
type = parameter.getString("type");
}
String collectionFormat = "csv";
if (parameter.has("collectionFormat")) {
collectionFormat = parameter.getString("collectionFormat");
}
boolean isMultiValued = type.equalsIgnoreCase("array") && collectionFormat.equals("multi");
RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
httpVariable.bNew = true;
httpVariable.setName(parameter.getString("name"));
httpVariable.setHttpName(parameter.getString("name"));
String in = parameter.getString("in");
if (in.equals("query") || in.equals("path") || in.equals("header")) {
httpVariable.setHttpMethod(HttpMethodType.GET.name());
if (in.equals("header")) {
// overrides variable's name : will be treated as dynamic header
httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpHeader.getName() + parameter.getString("name"));
// do not post on target server
httpVariable.setHttpName("");
}
} else if (in.equals("formData") || in.equals("body")) {
httpVariable.setHttpMethod(HttpMethodType.POST.name());
if (in.equals("body")) {
// 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(com.twinsoft.convertigo.engine.enums.Parameter.HttpContentType.getName());
// do not post on target server
ct.setHttpName("");
ct.setHttpMethod(HttpMethodType.POST.name());
ct.setValueOrNull(null);
ct.bNew = true;
transaction.addVariable(ct);
//
if (parameter.has("schema")) {
// String schema = parameter.getString("schema");
}
}
} else {
httpVariable.setHttpMethod("");
}
Object defaultValue = null;
if (parameter.has("default")) {
defaultValue = parameter.get("default");
}
if (defaultValue == null && type.equalsIgnoreCase("array")) {
JSONObject items = parameter.getJSONObject("items");
if (items.has("default")) {
defaultValue = items.get("default");
}
}
httpVariable.setValueOrNull(defaultValue);
if (parameter.has("description")) {
httpVariable.setDescription(parameter.getString("description"));
}
transaction.addVariable(httpVariable);
}
}
transaction.bNew = true;
transaction.setName(name);
transaction.setComment(comment);
transaction.setSubDir(subDir);
transaction.setHttpVerb(HttpMethodType.valueOf(httpVerb.toUpperCase()));
transaction.setHttpParameters(httpParameters);
transaction.setHttpInfo(true);
httpConnector.add(transaction);
}
}
return httpConnector;
} catch (Throwable t) {
System.out.println(t);
throw new Exception("Invalid Swagger format", t);
}
}
use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.
the class PropertyTableTreeObject method hasBeenModified.
protected synchronized void hasBeenModified() {
if (isInherited())
return;
XMLVector<XMLVector<Object>> xmlv = new XMLVector<XMLVector<Object>>();
for (PropertyTableRowTreeObject rowTreeObject : getChildren()) {
XMLVector<Object> row = new XMLVector<Object>(rowTreeObject.getObject());
xmlv.add(row);
}
data = xmlv;
try {
DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
java.beans.PropertyDescriptor databaseObjectPropertyDescriptor = databaseObjectTreeObject.getPropertyDescriptor(getObject());
Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
Object[] args = { data };
setter.invoke(databaseObject, args);
databaseObject.hasChanged = true;
databaseObjectTreeObject.hasBeenModified(true);
} catch (Exception e) {
}
TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
viewer.update(databaseObjectTreeObject, null);
}
use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.
the class XMLSplitStep method split.
private List<Element> split(Document doc, boolean withRoot, String text) {
List<Element> list = new ArrayList<Element>();
if (!text.equals("")) {
Pattern myPattern = Pattern.compile(regexp);
Matcher myMatcher = myPattern.matcher(text);
XMLVector<String> splitString = new XMLVector<String>();
int beginIndex = 0, startIndex, endIndex;
while (myMatcher.find()) {
startIndex = myMatcher.start();
endIndex = myMatcher.end();
if (beginIndex != startIndex) {
splitString.add(new String(text.substring(beginIndex, startIndex)));
}
if (keepSeparator) {
splitString.add(new String(text.substring(startIndex, endIndex)));
}
beginIndex = endIndex;
}
if (beginIndex != text.length()) {
splitString.add(new String(text.substring(beginIndex, text.length())));
}
Element root = null;
if (withRoot) {
root = doc.createElement("splits");
list.add(root);
}
// for all split string : create a node and add it
for (int j = 0; j < splitString.size(); j++) {
String splitted = (String) splitString.get(j);
Element split = doc.createElement(getTag(j));
split.appendChild(doc.createTextNode(splitted));
if (withRoot)
root.appendChild(split);
else
list.add(split);
}
}
return list;
}
use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.
the class AbstractHttpTransaction method parseInputDocument.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.beans.core.TransactionWithVariables#parseInputDocument(com.twinsoft.convertigo.engine.Context)
*/
@Override
public void parseInputDocument(Context context) throws EngineException {
super.parseInputDocument(context);
// Overrides uri using given __uri request parameter
NodeList uriNodes = context.inputDocument.getElementsByTagName("uri");
if (uriNodes.getLength() == 1) {
Element uriNode = (Element) uriNodes.item(0);
String uri = uriNode.getAttribute("value");
if (!uri.equals("")) {
setCurrentSubDir(uri);
// needRestoreVariablesDefinition = true;
needRestoreVariables = true;
}
}
// Overrides static HTTP headers using __header_ request parameters
NodeList headerNodes = context.inputDocument.getElementsByTagName("header");
int len = headerNodes.getLength();
if (len > 0) {
XMLVector<XMLVector<String>> headers = getCurrentHttpParameters();
for (int i = 0; i < len; i++) {
Element headerNode = (Element) headerNodes.item(i);
XMLVector<String> header = new XMLVector<String>();
header.add(headerNode.getAttribute("name"));
header.add(headerNode.getAttribute("value"));
headers.add(header);
}
setCurrentHttpParameters(headers);
// needRestoreVariablesDefinition = true;
needRestoreVariables = true;
}
}
use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.
the class AbstractHttpTransaction method getVariablesDefinition.
/**
* Compatibility for version older than 4.6.0 *
*/
@Deprecated
public XMLVector<XMLVector<Object>> getVariablesDefinition() {
XMLVector<XMLVector<Object>> xmlv = new XMLVector<XMLVector<Object>>();
getVariablesList();
if (hasVariables()) {
for (int i = 0; i < numberOfVariables(); i++) {
RequestableHttpVariable variable = (RequestableHttpVariable) getVariable(i);
XMLVector<Object> v = new XMLVector<Object>();
v.add(variable.getName());
v.add(variable.getDescription());
v.add(variable.getDefaultValue());
v.add(variable.isWsdl());
v.add(variable.isMultiValued());
v.add(variable.isPersonalizable());
v.add(variable.isCachedKey());
v.add(variable.getHttpMethod());
v.add(variable.getHttpName());
xmlv.add(v);
}
}
return xmlv;
}
Aggregations