use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.
the class Context method loadConnector.
public void loadConnector() throws EngineException {
if (connectorName == null) {
connectorName = project.getDefaultConnector().getName();
}
String key = project.getName() + '\n' + connectorName;
Connector connector = used_connectors.get(key);
if (connector != null && connector.getProject() == project) {
Engine.logContext.debug("Re-use connector: " + connectorName);
} else {
used_connectors.remove(key);
connector = project.getConnectorByName(connectorName);
Engine.logContext.debug("Loaded connector: " + connectorName);
used_connectors.put(key, connector);
}
setConnector(connector);
connector.checkSymbols();
}
use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.
the class ContextManager method remove.
public void remove(Context context) {
if (context == null) {
// Silently ignore
Engine.logContextManager.warn("The context cannot be removed because it does not exist any more!");
return;
}
if (context.isDestroying) {
return;
}
context.isDestroying = true;
context.requireRemoval(false);
try {
String contextID = context.contextID;
Engine.logContextManager.info("Removing context " + contextID);
contexts.remove(contextID, context);
if ((context.requestedObject != null) && (context.requestedObject.runningThread != null)) {
Engine.logContextManager.debug("Stopping requestable thread for context " + contextID);
// context.requestedObject.runningThread.bContinue = false;
context.abortRequestable();
}
// Trying to execute the end transaction (only in the engine mode)
if (Engine.isEngineMode()) {
for (Connector connector : context.getOpenedConnectors()) {
// Execute the end transaction
String endTransactionName = "n/a";
try {
endTransactionName = connector.getEndTransactionName();
if (endTransactionName != null && !endTransactionName.equals("")) {
Engine.logContextManager.debug("Trying to execute the end transaction: \"" + endTransactionName + "\"");
context.connectorName = connector.getName();
context.connector = connector;
context.transactionName = endTransactionName;
context.sequenceName = null;
DefaultRequester defaultRequester = new DefaultRequester();
// #4910 - prevent loop for destroying context renew
context.isDestroying = false;
context.requireRemoval(false);
defaultRequester.processRequest(context);
Engine.logContextManager.debug("End transaction successfull");
}
} catch (Throwable e) {
Engine.logContextManager.error("Unable to execute the end transaction; " + "context: " + context.contextID + ", " + "project: " + context.projectName + ", " + "connector: " + context.connectorName + ", " + "end transaction: " + endTransactionName, e);
} finally {
context.isDestroying = true;
}
// Unlocks device if any
// WARNING: removing the device pool MUST BE DONE AFTER the end transaction!!!
String connectorQName = connector.getQName();
DevicePool devicePool = getDevicePool(connectorQName);
if (devicePool != null) {
long contextNum = (Long.valueOf(Integer.toString(context.contextNum, 10))).longValue();
Engine.logContextManager.trace("DevicePool for '" + connectorQName + "' exist: unlocking device for context number " + contextNum + ".");
devicePool.unlockDevice(contextNum);
}
Engine.logContextManager.trace("Releasing " + connector.getName() + " connector (" + connector.getClass().getName() + ") for context id " + context.contextID);
Engine.execute(new Runnable() {
public void run() {
connector.release();
}
});
}
}
context.clearConnectors();
// Set TwsCachedXPathAPI to null
context.cleanXpathApi();
try {
Set<File> files = GenericUtils.cast(context.get("fileToDeleteAtEndOfContext"));
if (files != null) {
for (File file : files) {
FileUtils.deleteQuietly(file);
}
}
} catch (Exception e) {
}
Engine.theApp.sessionManager.removeSession(contextID);
String projectName = (String) context.projectName;
/* Fix: #1754 - Slower transaction execution with many session */
// HTTP session maintain its own context list in order to
// improve context removal on session unbound process
// See also #4198 which fix a regression
String sessionID = context.httpSession != null ? context.httpSession.getId() : context.contextID.substring(0, context.contextID.indexOf("_"));
HttpSession httpSession = HttpSessionListener.getHttpSession(sessionID);
if (httpSession != null) {
synchronized (httpSession) {
try {
List<Context> contextList = GenericUtils.cast(SessionAttribute.contexts.get(httpSession));
if ((contextList != null) && contextList.contains(context)) {
contextList.remove(context);
Engine.logContextManager.debug("(ContextManager) context " + contextID + " has been removed from http session's context list");
}
} catch (Exception e) {
// Ignore: HTTP session may have already been invalidated
}
}
}
Engine.logContextManager.debug("Context " + contextID + " has been removed");
Engine.logContext.debug("[" + contextID + "] Context removed, project: " + projectName);
Engine.logContextManager.info("Current in-use contexts: " + contexts.size());
Engine.logUsageMonitor.info("[Contexts] Current in-use contexts: " + contexts.size());
} catch (Exception e) {
Engine.logContextManager.warn("Failed to remove the context " + context.contextID, e);
}
}
use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.
the class ContextManager method createPoolContext.
private void createPoolContext(Pool pool, int contextNumber) {
try {
if (!isRunning)
return;
Connector connector = pool.getConnector();
Project project = connector.getProject();
String poolContextID = getPoolContextID(project.getName(), connector.getName(), pool.getName(), "" + contextNumber);
Engine.logContextManager.info("Creating context");
Context context = get(poolContextID, contextNumber + "", project.getName());
context.project = project;
context.projectName = project.getName();
// context.sequence = null;
// context.sequenceName = null;
context.setConnector(connector);
context.pool = pool;
context.poolContextNumber = contextNumber;
context.transactionName = pool.getStartTransaction();
if ((context.transactionName != null) && !context.transactionName.equals("")) {
context.requestedObject = connector.getTransactionByName(context.transactionName);
// For compatibility with older javelin projects, set the transaction context property
context.transaction = (Transaction) context.requestedObject;
Engine.logContextManager.debug("Launching the auto-start transaction \"" + context.transactionName + "\" for the context " + context.contextID);
context.remoteAddr = "127.0.0.1";
context.remoteHost = "localhost";
context.userAgent = "Convertigo ContextManager pools launcher";
try {
if (!isRunning)
return;
PoolRequester poolRequester = new PoolRequester();
poolRequester.processRequest(context);
} catch (Exception e) {
Engine.logContextManager.error("Unable to launch the context " + context.contextID, e);
}
}
} catch (EngineException e) {
Engine.logContextManager.error("An unexpected error has occured in the ContextManager vulture while creating the pool context.", e);
}
}
use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.
the class WebServiceServlet method generateWsdlForDocLiteral.
public static String generateWsdlForDocLiteral(String servletURI, String projectName) throws EngineException {
Engine.logEngine.debug("(WebServiceServlet) Generating WSDL...");
long timeStart = System.currentTimeMillis();
String locationPath = servletURI.substring(0, servletURI.indexOf("/.w"));
String targetNamespace = Project.CONVERTIGO_PROJECTS_NAMESPACEURI + projectName;
Project project = null;
// server mode
if (Engine.isEngineMode()) {
project = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
targetNamespace = project.getTargetNamespace();
} else // studio mode
{
project = Engine.objectsProvider.getProject(projectName);
targetNamespace = project.getTargetNamespace();
}
// Create WSDL definition
Definition definition = new DefinitionImpl();
definition.setExtensionRegistry(new PopulatedExtensionRegistry());
definition.setTargetNamespace(targetNamespace);
definition.setQName(new QName(targetNamespace, projectName));
definition.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
definition.addNamespace("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
definition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
definition.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
definition.addNamespace(projectName + "_ns", targetNamespace);
// Add WSDL Types
Types types = definition.createTypes();
definition.setTypes(types);
// Add WSDL service
Service service = definition.createService();
service.setQName(new QName(targetNamespace, projectName));
definition.addService(service);
// Add WSDL binding
PortType portType = definition.createPortType();
portType.setQName(new QName(targetNamespace, projectName + "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
SOAPBindingImpl soapBinding = new SOAPBindingImpl();
soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
soapBinding.setStyle("document");
Binding binding = definition.createBinding();
binding.setQName(new QName(targetNamespace, projectName + "SOAPBinding"));
binding.setUndefined(false);
definition.addBinding(binding);
binding.addExtensibilityElement(soapBinding);
binding.setPortType(portType);
// Add WSDL port
SOAPAddress soapAddress = new SOAPAddressImpl();
soapAddress.setLocationURI(locationPath + "/.wsl");
Port port = definition.createPort();
port.setName(projectName + "SOAP");
port.addExtensibilityElement(soapAddress);
port.setBinding(binding);
service.addPort(port);
// Add all WSDL operations
// remember qnames for accessibility
List<QName> partElementQNames = new ArrayList<QName>();
if (project != null) {
for (Connector connector : project.getConnectorsList()) {
for (Transaction transaction : connector.getTransactionsList()) {
if (transaction.isPublicAccessibility()) {
addWsdlOperation(definition, transaction, partElementQNames);
}
}
}
for (Sequence sequence : project.getSequencesList()) {
if (sequence.isPublicAccessibility()) {
addWsdlOperation(definition, sequence, partElementQNames);
}
}
}
// Add all schemas of project under WSDL Types
try {
// Retrieve the only needed schema objects map
XmlSchemaCollection xmlSchemaCollection = Engine.theApp.schemaManager.getSchemasForProject(projectName);
XmlSchema projectSchema = xmlSchemaCollection.getXmlSchema(targetNamespace)[0];
LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, true);
for (QName qname : partElementQNames) {
dw.walkByElementRef(projectSchema, qname);
}
if (Engine.logEngine.isTraceEnabled()) {
String message = "";
for (QName qname : map.keySet()) {
message += "\n\t" + qname.toString();
}
Engine.logEngine.trace("(WebServiceServlet) needed schema objects :" + message);
}
// Read schemas into a new Collection in order to modify them
XmlSchemaCollection wsdlSchemaCollection = new XmlSchemaCollection();
for (XmlSchema xmlSchema : xmlSchemaCollection.getXmlSchemas()) {
String tns = xmlSchema.getTargetNamespace();
if (tns.equals(Constants.URI_2001_SCHEMA_XSD))
continue;
if (tns.equals(SchemaUtils.URI_SOAP_ENC))
continue;
if (wsdlSchemaCollection.schemaForNamespace(tns) == null) {
wsdlSchemaCollection.read(xmlSchema.getSchemaDocument(), xmlSchema.getSourceURI(), null);
}
}
// Modify schemas and add them
Map<String, Schema> schemaMap = new HashMap<String, Schema>();
for (XmlSchema xmlSchema : wsdlSchemaCollection.getXmlSchemas()) {
if (xmlSchema.getTargetNamespace().equals(Constants.URI_2001_SCHEMA_XSD))
continue;
if (xmlSchema.getTargetNamespace().equals(SchemaUtils.URI_SOAP_ENC))
continue;
String tns = xmlSchema.getTargetNamespace();
// Reduce schema to needed objects
reduceSchema(xmlSchema, map.keySet());
// Retrieve schema Element
Schema wsdlSchema = schemaMap.get(tns);
if (wsdlSchema == null) {
wsdlSchema = (Schema) definition.getExtensionRegistry().createExtension(Types.class, SchemaConstants.Q_ELEM_XSD_2001);
Element schemaElt = xmlSchema.getSchemaDocument().getDocumentElement();
// Remove 'schemaLocation' attribute on imports
NodeList importList = schemaElt.getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "import");
if (importList.getLength() > 0) {
for (int i = 0; i < importList.getLength(); i++) {
Element importElt = (Element) importList.item(i);
importElt.removeAttribute("schemaLocation");
}
}
// Remove includes
NodeList includeList = schemaElt.getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "include");
if (includeList.getLength() > 0) {
for (int i = 0; i < includeList.getLength(); i++) {
schemaElt.removeChild(includeList.item(i));
}
}
// Add schema Element
schemaMap.put(tns, wsdlSchema);
wsdlSchema.setElement(schemaElt);
types.addExtensibilityElement(wsdlSchema);
} else {
// case of schema include (same targetNamespace) or same schema
Element schemaElt = wsdlSchema.getElement();
// Add missing attributes
NamedNodeMap attributeMap = xmlSchema.getSchemaDocument().getDocumentElement().getAttributes();
for (int i = 0; i < attributeMap.getLength(); i++) {
Node node = attributeMap.item(i);
if (schemaElt.getAttributes().getNamedItem(node.getNodeName()) == null) {
schemaElt.setAttribute(node.getNodeName(), node.getNodeValue());
}
}
// Add children
NodeList children = xmlSchema.getSchemaDocument().getDocumentElement().getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
// Special cases
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element el = (Element) node;
// Do not add include
if (el.getTagName().endsWith("include"))
continue;
// Add import at first
if (el.getTagName().endsWith("import")) {
String ins = el.getAttribute("namespace");
if (!tns.equals(ins) && el.hasAttribute("schemaLocation")) {
if (!hasElement(schemaElt, el.getLocalName(), ins))
schemaElt.insertBefore(schemaElt.getOwnerDocument().importNode(el, true), schemaElt.getFirstChild());
continue;
}
}
// Else
if (!hasElement(schemaElt, el.getLocalName(), el.getAttribute("name")))
schemaElt.appendChild(schemaElt.getOwnerDocument().importNode(el, true));
} else {
// Others
schemaElt.appendChild(schemaElt.getOwnerDocument().importNode(node, true));
}
}
}
}
} catch (Exception e1) {
Engine.logEngine.error("An error occured while adding schemas for WSDL", e1);
}
// Write WSDL to string
WSDLWriter wsdlWriter = new WSDLWriterImpl();
StringWriter sw = new StringWriter();
try {
wsdlWriter.writeWSDL(definition, sw);
} catch (WSDLException e) {
Engine.logEngine.error("An error occured while generating WSDL", e);
}
String wsdl = sw.toString();
long timeStop = System.currentTimeMillis();
System.out.println("Wsdl for " + projectName + " | Times >> total : " + (timeStop - timeStart) + " ms");
return wsdl;
}
use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.
the class DatabaseObjectDeleteAction method delete.
private void delete(DatabaseObject databaseObject) throws EngineException, IOException {
if (databaseObject instanceof Connector) {
if (((Connector) databaseObject).isDefault) {
throw new EngineException("Cannot delete the default connector!");
}
String projectName = databaseObject.getParent().getName();
deleteResourcesFolder(projectName, "soap-templates", databaseObject.getName());
deleteResourcesFolder(projectName, "Traces", databaseObject.getName());
} else if (databaseObject instanceof Transaction) {
if (((Transaction) databaseObject).isDefault) {
throw new EngineException("Cannot delete the default transaction!");
}
} else if (databaseObject instanceof ScreenClass) {
if ((databaseObject.getParent()) instanceof Project) {
throw new EngineException("Cannot delete the root screen class!");
}
} else if (databaseObject instanceof Statement) {
if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
throw new EngineException("Cannot delete this statement!");
}
} else if (databaseObject instanceof Step) {
if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
throw new EngineException("Cannot delete this step!");
}
} else if (databaseObject instanceof MobilePlatform) {
MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
File resourceFolder = mobilePlatform.getResourceFolder();
if (resourceFolder.exists()) {
// MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
// messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
// messageBox.setText("Delete the \""+resourceFolder.getName()+"\" folder?");
// if (messageBox.open() == SWT.YES) {
// FileUtils.deleteQuietly(resourceFolder);
// }
}
} else if (databaseObject instanceof PageComponent) {
if (((PageComponent) databaseObject).isRoot) {
throw new EngineException("Cannot delete the root page!");
}
}
if (databaseObject instanceof Project) {
// Deleted project will be backup, car will be deleted to avoid its deployment at engine restart
// Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName());
// ConvertigoPlugin.getDefault().deleteProjectPluginResource(databaseObject.getName());
} else {
databaseObject.delete();
}
if (databaseObject instanceof CouchDbConnector) {
CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
String db = couchDbConnector.getDatabaseName();
if (!db.isEmpty()) {
// MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
// messageBox.setMessage("Do you want to delete the \""+db+"\" database from the CouchDb server?");
// messageBox.setText("Delete the database?");
// if (messageBox.open() == SWT.YES) {
// couchDbConnector.getCouchClient().deleteDatabase(db);
// }
}
}
// ConvertigoPlugin.logDebug("The object \"" + databaseObject.getQName() + "\" has been deleted from the database repository!");
}
Aggregations