use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class NgxPickerContentProvider method addSequences.
private void addSequences(Map<String, Set<String>> map, TVObject tvs, Object object, boolean isReferenced) {
if (object != null) {
if (object instanceof Project) {
Project project = (Project) object;
for (Sequence s : project.getSequencesList()) {
String label = isReferenced ? s.getQName() : s.getName();
SourceData sd = null;
try {
sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()));
} catch (JSONException e) {
e.printStackTrace();
}
tvs.add(new TVObject(label, s, sd));
Set<String> infos = map.get(s.getQName());
if (infos != null) {
for (String info : infos) {
try {
JSONObject jsonInfo = new JSONObject(info);
if (jsonInfo.has("marker")) {
String marker = jsonInfo.getString("marker");
if (!marker.isEmpty()) {
sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()).put("marker", marker));
tvs.add(new TVObject(label + "#" + marker, s, sd, jsonInfo));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class WebServiceTranslator method __buildOutputData.
/* Old builOutputData method */
public Object __buildOutputData(Context context, Object convertigoResponse) throws Exception {
Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response...");
SOAPMessage responseMessage = null;
String sResponseMessage = "";
String encodingCharSet = "UTF-8";
if (context.requestedObject != null)
encodingCharSet = context.requestedObject.getEncodingCharSet();
if (convertigoResponse instanceof Document) {
Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document.");
Document document = (Document) convertigoResponse;
// MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
MessageFactory messageFactory = MessageFactory.newInstance();
responseMessage = messageFactory.createMessage();
responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet);
SOAPPart sp = responseMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
String targetNamespace = context.project.getTargetNamespace();
String prefix = getPrefix(context.projectName, targetNamespace);
// se.addNamespaceDeclaration(prefix, targetNameSpace);
se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
// Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail
se.getHeader().detachNode();
// Add the method response element
SOAPElement soapMethodResponseElement = null;
String soapElementName = context.sequenceName != null ? context.sequenceName : context.connectorName + "__" + context.transactionName;
soapElementName += "Response";
soapMethodResponseElement = sb.addChildElement(se.createName(soapElementName, prefix, targetNamespace));
if (XsdForm.qualified == context.project.getSchemaElementForm()) {
soapMethodResponseElement.addAttribute(se.createName("xmlns"), targetNamespace);
}
// Add a 'response' root child element or not
SOAPElement soapResponseElement;
if (context.sequenceName != null) {
Sequence sequence = (Sequence) context.requestedObject;
if (sequence.isIncludeResponseElement()) {
soapResponseElement = soapMethodResponseElement.addChildElement("response");
} else {
soapResponseElement = soapMethodResponseElement;
}
} else {
soapResponseElement = soapMethodResponseElement.addChildElement("response");
}
if (soapResponseElement.getLocalName().equals("response")) {
if (document.getDocumentElement().hasAttributes()) {
addAttributes(responseMessage, se, context, document.getDocumentElement().getAttributes(), soapResponseElement);
}
}
NodeList childNodes = document.getDocumentElement().getChildNodes();
int len = childNodes.getLength();
org.w3c.dom.Node node;
for (int i = 0; i < len; i++) {
node = childNodes.item(i);
if (node instanceof Element) {
addElement(responseMessage, se, context, (Element) node, soapResponseElement);
}
}
sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet);
// Correct missing "xmlns" (Bug AXA POC client .NET)
// sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\"");
} else {
Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document.");
sResponseMessage = convertigoResponse.toString();
}
if (Engine.logBeans.isDebugEnabled()) {
Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage);
}
return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage;
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class WebServiceTranslator method buildInputDocument.
public void buildInputDocument(Context context, Object inputData) throws Exception {
Engine.logBeans.debug("[WebServiceTranslator] Making input document");
HttpServletRequest request = (HttpServletRequest) inputData;
SOAPMessage requestMessage = (SOAPMessage) request.getAttribute(WebServiceServlet.REQUEST_MESSAGE_ATTRIBUTE);
SOAPPart sp = requestMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
Iterator<?> iterator = sb.getChildElements();
SOAPElement method, parameter;
String methodName;
InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
while (iterator.hasNext()) {
// jmc 12/06/26
List<RequestableVariable> variableList = null;
Object element = iterator.next();
if (element instanceof SOAPElement) {
method = (SOAPElement) element;
methodName = method.getElementName().getLocalName();
Engine.logBeans.debug("[WebServiceTranslator] Requested web service name: " + methodName);
int i = methodName.indexOf("__");
// for statefull transaction, don't replace the project
if (context.project == null || !context.project.getName().equals(context.projectName)) {
context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName);
}
String connectorName = null;
if (i == -1) {
context.connectorName = null;
context.sequenceName = methodName;
} else {
connectorName = methodName.substring(0, i);
context.transactionName = methodName.substring(i + 2);
}
if ((connectorName != null) && (!connectorName.equals(context.connectorName))) {
Engine.logBeans.debug("Connector name differs from previous one; requiring new session");
context.isNewSession = true;
context.connectorName = connectorName;
Engine.logBeans.debug("[WebServiceTranslator] The connector is overridden to \"" + context.connectorName + "\".");
}
Engine.logBeans.debug("[WebServiceTranslator] Connector: " + (context.connectorName == null ? "(default)" : context.connectorName));
Engine.logBeans.debug("[WebServiceTranslator] Transaction: " + context.transactionName);
// Connector connector = (context.connectorName == null ? context.project.getDefaultConnector() : context.project.getConnectorByName(context.connectorName));
// Transaction transaction = (context.transactionName == null ? connector.getDefaultTransaction() : connector.getTransactionByName(context.transactionName));
RequestableObject requestable = null;
if (context.sequenceName != null) {
requestable = context.project.getSequenceByName(context.sequenceName);
variableList = ((Sequence) requestable).getVariablesList();
} else if (context.connectorName != null) {
if (context.transactionName != null) {
requestable = context.project.getConnectorByName(context.connectorName).getTransactionByName(context.transactionName);
if (requestable instanceof TransactionWithVariables) {
variableList = ((TransactionWithVariables) requestable).getVariablesList();
}
}
}
Iterator<?> iterator2 = method.getChildElements();
String parameterName, parameterValue;
while (iterator2.hasNext()) {
element = iterator2.next();
if (element instanceof SOAPElement) {
parameter = (SOAPElement) element;
parameterName = parameter.getElementName().getLocalName();
parameterValue = parameter.getValue();
if (parameterValue == null) {
parameterValue = "";
}
if (variableList != null) {
// jmc 12/06/26 hide hidden variables in sequences
String str = (String) Visibility.Logs.replaceVariables(variableList, "" + parameterName + "=\"" + parameterValue + "\"");
Engine.logBeans.debug(" Parameter: " + str);
} else
Engine.logBeans.debug(" Parameter: " + parameterName + "=\"" + parameterValue + "\"");
// Handle convertigo parameters
if (parameterName.startsWith("__")) {
webServiceServletRequester.handleParameter(parameterName, parameterValue);
}
// Common parameter handling
if (inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValue)) {
// handled
} else // Compatibility for Convertigo 2.x
if (parameterName.equals("context")) {
// Just ignore it
} else {
SOAPElement soapArrayElement = null;
Iterator<?> iterator3;
String href = parameter.getAttributeValue(se.createName("href"));
String arrayType = parameter.getAttributeValue(se.createName("soapenc:arrayType"));
if (arrayType == null) {
iterator3 = parameter.getAllAttributes();
while (iterator3.hasNext()) {
element = iterator3.next();
if (element instanceof Name) {
String s = ((Name) element).getQualifiedName();
if (s.equals("soapenc:arrayType")) {
arrayType = s;
break;
}
}
}
}
// Array (Microsoft .net)
if (href != null) {
Engine.logBeans.debug("Deserializing Microsoft .net array");
iterator3 = sb.getChildElements();
while (iterator3.hasNext()) {
element = iterator3.next();
if (element instanceof SOAPElement) {
soapArrayElement = (SOAPElement) element;
String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
if (elementId != null) {
if (href.equals("#" + elementId)) {
iterator3 = soapArrayElement.getChildElements();
while (iterator3.hasNext()) {
element = iterator3.next();
if (element instanceof SOAPElement) {
break;
}
}
break;
}
}
}
}
// Find the element with href id
iterator3 = sb.getChildElements();
while (iterator3.hasNext()) {
element = iterator3.next();
if (element instanceof SOAPElement) {
soapArrayElement = (SOAPElement) element;
String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
if (elementId != null) {
if (href.equals("#" + elementId)) {
break;
}
}
}
}
} else // Array (Java/Axis)
if (arrayType != null) {
Engine.logBeans.debug("Deserializing Java/Axis array");
soapArrayElement = parameter;
} else // If the node has children nodes, we assume it is an array.
if (parameter.getChildElements().hasNext()) {
if (isSoapArray((IVariableContainer) requestable, parameterName)) {
Engine.logBeans.debug("Deserializing array");
soapArrayElement = parameter;
}
}
// Deserializing array
if (soapArrayElement != null) {
iterator3 = soapArrayElement.getChildElements();
while (iterator3.hasNext()) {
element = iterator3.next();
if (element instanceof SOAPElement) {
soapArrayElement = (SOAPElement) element;
parameterValue = soapArrayElement.getValue();
if (parameterValue == null)
parameterValue = "";
handleSimpleVariable(context.inputDocument, soapArrayElement, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement);
}
}
} else // Deserializing simple variable
{
handleSimpleVariable(context.inputDocument, parameter, parameterName, parameterValue, inputDocumentBuilder.transactionVariablesElement);
}
}
}
}
if (Engine.logBeans.isDebugEnabled()) {
String soapMessage = SOAPUtils.toString(requestMessage, request.getCharacterEncoding());
if (requestable instanceof TransactionWithVariables)
Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs.replaceVariables(((TransactionWithVariables) (requestable)).getVariablesList(), request));
else if (requestable instanceof Sequence)
Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs.replaceVariables(((Sequence) (requestable)).getVariablesList(), request));
else
Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + soapMessage);
}
break;
}
}
Engine.logBeans.debug("[WebServiceTranslator] SOAP message analyzed");
Engine.logBeans.debug("[WebServiceTranslator] Input document created");
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class StepSourceEditorComposite method addStepsInTree.
private void addStepsInTree(Object parent, DatabaseObject databaseObject) {
TreeItem tItem;
if (parent instanceof Tree) {
stepFound = false;
tItem = new TreeItem((Tree) parent, SWT.NONE);
tItem.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
} else {
tItem = new TreeItem((TreeItem) parent, SWT.NONE);
if (databaseObject instanceof Step) {
Step step = (Step) databaseObject;
if (!step.isPickable()) {
tItem.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
}
}
}
// associate our object with the tree Item.
tItem.setData(databaseObject);
if (databaseObject.priority == step.priority) {
tItem.setText("* " + databaseObject.toString());
tree.showItem(tItem);
stepFound = true;
stepItem = tItem;
} else {
tItem.setText(databaseObject.toString());
}
if (!stepFound && !(tItem.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_RED)))) {
lastSelectableItem = tItem;
}
// disable all steps after founded one
if (stepFound) {
tItem.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
}
// now recurse on children steps
if (databaseObject instanceof StepWithExpressions) {
for (Step step : ((StepWithExpressions) databaseObject).getSteps()) {
addStepsInTree(tItem, step);
}
} else if (databaseObject instanceof Sequence) {
for (Step step : ((Sequence) databaseObject).getSteps()) {
addStepsInTree(tItem, step);
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SequenceStep method prepareForRequestable.
protected void prepareForRequestable(Context javascriptContext, Scriptable scope) throws MalformedURLException, EngineException {
Sequence targetSequence = getTargetSequence();
if (Engine.isStudioMode()) {
if (targetSequence != null) {
if (sequence.getOriginal().equals(targetSequence.getOriginal())) {
throw new EngineException("Execution of recursive sequence is not allowed in Studio mode!");
}
}
}
String ctxName = getContextName(javascriptContext, scope);
boolean useSequenceJSession = sequence.useSameJSessionForSteps();
boolean maintainContext = useSequenceJSession && !ctxName.startsWith("Container-");
boolean maintainSession = useSequenceJSession;
boolean inheritContex = inheritTransactionCtx && sequence.equals(getTransactionContextMaintainer());
String inheritedCxtName = sequence.getInheritedContextName();
inheritedCxtName = (inheritContex && (inheritedCxtName == null)) ? sequence.getContextName() : inheritedCxtName;
inheritedCxtName = (inheritedCxtName == null) ? "" : inheritedCxtName;
if (isInternalInvoke()) {
request.put(Parameter.Project.getName(), new String[] { projectName });
request.put(Parameter.MotherSequenceContext.getName(), new String[] { sequence.context.contextID });
request.put(Parameter.Sequence.getName(), new String[] { targetSequence.getName() });
request.put(Parameter.Context.getName(), new String[] { sequence.addStepContextName(ctxName) });
request.put(Parameter.SequenceInheritedTransactionContext.getName(), inheritContex ? new String[] { inheritedCxtName } : new String[] { "" });
if (!maintainContext)
request.put(Parameter.RemoveContext.getName(), new String[] { "" });
if (!maintainSession)
request.put(Parameter.RemoveSession.getName(), new String[] { "" });
getPostQuery(scope);
} else {
targetUrl = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
targetUrl += "/projects/" + projectName + "/.xml?";
URL url = new URL(targetUrl);
String host = url.getHost();
int port = url.getPort();
Engine.logBeans.trace("(SequenceStep) Host: " + host + ":" + port);
hostConfiguration.setHost(host, port);
// Retrieves new HttpState!!
// This will force a new http session on convertigo server : new context for sequence
httpState = sequence.getNewHttpState();
method = new PostMethod(targetUrl);
method.setRequestHeader("Content-Type", MimeType.WwwForm.value());
// Set transaction sessionId from context maintainer
String sessionId = getTransactionSessionId();
if (useSequenceJSession) {
Engine.logBeans.trace("(SequenceStep) JSESSIONID required : " + sessionId);
if (sessionId != null) {
method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId + ";");
Engine.logBeans.trace("(SequenceStep) JSESSIONID used : " + sessionId);
} else {
Engine.logBeans.trace("(SequenceStep) JSESSIONID is null");
}
} else {
if (sessionId != null) {
method.addRequestHeader("Transaction-JSessionId", sessionId);
Engine.logBeans.trace("(SequenceStep) Transaction JSESSIONID used : " + sessionId);
} else {
Engine.logBeans.trace("(SequenceStep) Transaction JSESSIONID is null");
}
}
String postQuery = getPostQuery(scope);
if (!maintainContext && (postQuery.indexOf(Parameter.RemoveContext.getName()) == -1))
postQuery = addParamToPostQuery(Parameter.RemoveContext.getName(), "", postQuery);
if (!maintainSession && (postQuery.indexOf(Parameter.RemoveSession.getName()) == -1))
postQuery = addParamToPostQuery(Parameter.RemoveSession.getName(), "", postQuery);
if (postQuery.indexOf(Parameter.SequenceInheritedTransactionContext.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.SequenceInheritedTransactionContext.getName(), inheritContex ? inheritedCxtName : "", postQuery);
if (postQuery.indexOf(Parameter.Sequence.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.Sequence.getName(), targetSequence.getName(), postQuery);
if (postQuery.indexOf(Parameter.Context.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.Context.getName(), sequence.addStepContextName(ctxName), postQuery);
if (postQuery.indexOf(Parameter.MotherSequenceContext.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.MotherSequenceContext.getName(), sequence.context.contextID, postQuery);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(SequenceStep) postQuery :" + Visibility.Logs.replaceVariables(getVariables(), postQuery));
try {
method.setRequestEntity(new StringRequestEntity(postQuery, null, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new EngineException("Encoding error", e);
}
}
}
Aggregations