Search in sources :

Example 1 with DefaultRequester

use of com.twinsoft.convertigo.engine.requesters.DefaultRequester in project convertigo by convertigo.

the class Sequence method createDOM.

public Document createDOM() throws EngineException {
    Document doc = null;
    try {
        if (requester == null)
            doc = new DefaultRequester().createDomWithNoXMLDeclaration(getEncodingCharSet());
        else
            doc = ((GenericRequester) requester).createDomWithNoXMLDeclaration(getEncodingCharSet());
        Element rootElement = doc.createElement("document");
        doc.appendChild(rootElement);
    } catch (Exception e) {
    }
    return doc;
}
Also used : GenericRequester(com.twinsoft.convertigo.engine.requesters.GenericRequester) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DefaultRequester(com.twinsoft.convertigo.engine.requesters.DefaultRequester) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 2 with DefaultRequester

use of com.twinsoft.convertigo.engine.requesters.DefaultRequester 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);
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpSession(javax.servlet.http.HttpSession) DevicePool(com.twinsoft.util.DevicePool) DefaultRequester(com.twinsoft.convertigo.engine.requesters.DefaultRequester) File(java.io.File)

Example 3 with DefaultRequester

use of com.twinsoft.convertigo.engine.requesters.DefaultRequester in project convertigo by convertigo.

the class CreateFormFromTransactionAction method generateXSLForm.

private String generateXSLForm(Connector connector, TransactionWithVariables tr) throws Exception {
    // Build a source DOM containing all the variable part of the generatedXSL file
    Document doc = new DefaultRequester().createDomWithNoXMLDeclaration(tr.getEncodingCharSet());
    Element variables = doc.createElement("variables");
    doc.appendChild(variables);
    /*int size = tr.getVariablesDefinitionSize();
		for (int i = 0 ; i < size ; i++) {
			Element variable = doc.createElement("variable");
			
			Element elt = doc.createElement("variableDefinitionName");
			elt.appendChild(doc.createTextNode(tr.getVariableDefinitionName(i)));
			variable.appendChild(elt);

			elt = doc.createElement("variableDefinitionDefaultValue");
			elt.appendChild(doc.createTextNode((String)tr.getVariableDefinitionDefaultValue(i)));
			variable.appendChild(elt);
			
			elt = doc.createElement("VariableDefinitionDescription");
			elt.appendChild(doc.createTextNode(tr.getVariableDefinitionDescription(i)));
			variable.appendChild(elt);
			
			variables.appendChild(variable);
		}*/
    int size = tr.numberOfVariables();
    for (int i = 0; i < size; i++) {
        RequestableVariable rVariable = (RequestableVariable) tr.getVariable(i);
        if (rVariable != null) {
            Element variable = doc.createElement("variable");
            Element elt = doc.createElement("variableDefinitionName");
            elt.appendChild(doc.createTextNode(rVariable.getName()));
            variable.appendChild(elt);
            elt = doc.createElement("variableDefinitionDefaultValue");
            elt.appendChild(doc.createTextNode(rVariable.getDefaultValue().toString()));
            variable.appendChild(elt);
            elt = doc.createElement("VariableDefinitionDescription");
            elt.appendChild(doc.createTextNode(rVariable.getDescription()));
            variable.appendChild(elt);
            variables.appendChild(variable);
        }
    }
    Element elt = doc.createElement("transactionName");
    elt.appendChild(doc.createTextNode(tr.getName()));
    variables.appendChild(elt);
    // Transform using the GenerateForm.xsl template
    // System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
    // TransformerFactory tFactory = TransformerFactory.newInstance();
    TransformerFactory tFactory = new org.apache.xalan.xsltc.trax.TransformerFactoryImpl();
    String filePath = Engine.TEMPLATES_PATH + "/xsl/GenerateForm.xsl";
    StreamSource streamSource = new StreamSource(new File(filePath).toURI().toASCIIString());
    Transformer transformer = tFactory.newTransformer(streamSource);
    StringWriter sw = new StringWriter();
    transformer.transform(new DOMSource(doc), new StreamResult(sw));
    String xslContent = sw.toString();
    xslContent = XMLUtils.prettyPrintDOM(xslContent);
    return xslContent;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) StreamSource(javax.xml.transform.stream.StreamSource) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Document(org.w3c.dom.Document) DefaultRequester(com.twinsoft.convertigo.engine.requesters.DefaultRequester) StringWriter(java.io.StringWriter) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

DefaultRequester (com.twinsoft.convertigo.engine.requesters.DefaultRequester)3 File (java.io.File)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 Connector (com.twinsoft.convertigo.beans.core.Connector)1 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 GenericRequester (com.twinsoft.convertigo.engine.requesters.GenericRequester)1 DevicePool (com.twinsoft.util.DevicePool)1 StringWriter (java.io.StringWriter)1 HttpSession (javax.servlet.http.HttpSession)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 IFile (org.eclipse.core.resources.IFile)1