use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.
the class NewProjectWizard method createFromBlankProject.
private Project createFromBlankProject(IProgressMonitor monitor, boolean updateTreeView) throws Exception {
String newProjectName = projectName;
String oldProjectName = projectUrlParser.getProjectName();
monitor.setTaskName("Creating new project");
monitor.worked(1);
if (Engine.theApp.databaseObjectsManager.existsProject(newProjectName)) {
throw new EngineException("Unable to create new project ! A project with the same name (\"" + newProjectName + "\") already exists.");
}
monitor.setTaskName("Loading the projet");
monitor.worked(1);
projectUrlParser.setProjectName(projectName);
Project newProject = Engine.theApp.referencedProjectManager.importProject(projectUrlParser, true);
monitor.worked(1);
try {
// set values of elements to configure on the new project
String newEmulatorTechnology = "";
String emulatorTechnologyName = "";
String newIbmTerminalType = "";
switch(wizardId) {
case "com.twinsoft.convertigo.eclipse.wizards.New3270ConnectorWizard":
case "com.twinsoft.convertigo.eclipse.wizards.New3270WebWizard":
newEmulatorTechnology = Session.SNA;
newIbmTerminalType = "IBM-3279";
emulatorTechnologyName = "IBM3270";
break;
case "com.twinsoft.convertigo.eclipse.wizards.New5250ConnectorWizard":
case "com.twinsoft.convertigo.eclipse.wizards.New5250WebWizard":
newEmulatorTechnology = Session.AS400;
newIbmTerminalType = "IBM-3179";
emulatorTechnologyName = "IBM5250";
break;
case "com.twinsoft.convertigo.eclipse.wizards.NewDKUConnectorWizard":
case "com.twinsoft.convertigo.eclipse.wizards.NewDKUWebWizard":
newEmulatorTechnology = Session.DKU;
emulatorTechnologyName = "BullDKU7107";
break;
case "com.twinsoft.convertigo.eclipse.wizards.NewVT220ConnectorWizard":
newEmulatorTechnology = Session.VT;
emulatorTechnologyName = "UnixVT220";
break;
}
monitor.setTaskName("Reset project version");
monitor.worked(1);
newProject.setVersion("");
monitor.setTaskName("Change connector name");
monitor.worked(1);
String oldConnectorName = "void";
String newConnectorName = "void";
boolean connectorChanged = false;
if (page2 != null) {
newConnectorName = page2.getConnectorName();
monitor.setTaskName("Connector renamed");
monitor.worked(1);
oldConnectorName = newProject.getDefaultConnector().getName();
newProject.getDefaultConnector().setName(newConnectorName);
connectorChanged = true;
}
if (page5 != null) {
CicsConnector cicsConnector = (CicsConnector) newProject.getDefaultConnector();
monitor.setTaskName("Update connector mainframe name");
monitor.worked(1);
cicsConnector.setMainframeName(page5.getCtgName());
monitor.setTaskName("Update connector server");
monitor.worked(1);
cicsConnector.setServer(page5.getCtgServer());
monitor.setTaskName("Update connector port");
monitor.worked(1);
try {
cicsConnector.setPort(Integer.parseInt(page5.getCtgPort()));
} catch (Exception e) {
}
}
if (page6 != null) {
monitor.setTaskName("Update connector server");
monitor.worked(1);
// change connector server and port,
// change https mode
// and change proxy server and proxy port
HttpConnector httpConnector = (HttpConnector) newProject.getDefaultConnector();
httpConnector.setServer(page6.getHttpServer());
monitor.setTaskName("Update connector port");
monitor.worked(1);
try {
httpConnector.setPort(Integer.parseInt(page6.getHttpPort()));
} catch (Exception e) {
}
monitor.setTaskName("Update connector https mode");
monitor.worked(1);
httpConnector.setHttps(page6.isBSSL());
}
if (page7 != null) {
// change emulator technology
// and change service code
monitor.setTaskName("Set connector service code");
monitor.worked(1);
JavelinConnector javelinConnector = (JavelinConnector) newProject.getDefaultConnector();
javelinConnector.setServiceCode(page7.getServiceCode());
monitor.setTaskName("Set connector emulator technology");
monitor.worked(1);
javelinConnector.setEmulatorTechnology(newEmulatorTechnology);
monitor.setTaskName("Set terminal type");
monitor.worked(1);
javelinConnector.setIbmTerminalType(newIbmTerminalType);
// rename emulatorTechnology criteria
monitor.setTaskName("Rename emulator technology criteria");
monitor.worked(1);
javelinConnector.getDefaultScreenClass().getLocalCriterias().get(0).setName(emulatorTechnologyName);
}
if (page11 != null) {
SiteClipperConnector scConnector = (SiteClipperConnector) newProject.getDefaultConnector();
monitor.setTaskName("Update connector certificates policy");
monitor.worked(1);
scConnector.setTrustAllServerCertificates(page11.isTrustAllServerCertificates());
monitor.setTaskName("Update host url");
monitor.worked(1);
scConnector.getDefaultTransaction().setTargetURL(page11.getTargetURL());
}
if (configureSQLConnectorPage != null) {
SqlConnector sqlConnector = (SqlConnector) newProject.getDefaultConnector();
monitor.setTaskName("Update JDBC URL");
monitor.worked(1);
sqlConnector.setJdbcURL(configureSQLConnectorPage.getJdbcURL());
monitor.setTaskName("Update JDBC driver");
monitor.worked(1);
sqlConnector.setJdbcDriverClassName(configureSQLConnectorPage.getJdbcDriver());
monitor.setTaskName("Update Username");
monitor.worked(1);
sqlConnector.setJdbcUserName(configureSQLConnectorPage.getUsername());
monitor.setTaskName("Update Password");
monitor.worked(1);
sqlConnector.setJdbcUserPassword(configureSQLConnectorPage.getPassword());
}
if (configureSAPConnectorPage != null) {
SapJcoConnector sapConnector = (SapJcoConnector) newProject.getDefaultConnector();
// Application Server Host
monitor.setTaskName("Update application Server Host");
monitor.worked(1);
sapConnector.setAsHost(configureSAPConnectorPage.getAsHost());
// System Number
monitor.setTaskName("Update system number");
monitor.worked(1);
sapConnector.setSystemNumber(configureSAPConnectorPage.getSystemNumber());
// Client
monitor.setTaskName("Update client");
monitor.worked(1);
sapConnector.setClient(configureSAPConnectorPage.getClient());
// User
monitor.setTaskName("Update user");
monitor.worked(1);
sapConnector.setUser(configureSAPConnectorPage.getUser());
// Password
monitor.setTaskName("Update password");
monitor.worked(1);
sapConnector.setPassword(configureSAPConnectorPage.getPassword());
// Language
monitor.setTaskName("Update language");
monitor.worked(1);
sapConnector.setLanguage(configureSAPConnectorPage.getLanguage());
}
monitor.setTaskName("Saving updated project");
monitor.worked(1);
Engine.theApp.databaseObjectsManager.exportProject(newProject);
monitor.setTaskName("New project saved");
monitor.worked(1);
try {
File eProject = new File(newProject.getDirPath(), ".project");
if (eProject.exists()) {
String txt = FileUtils.readFileToString(eProject, StandardCharsets.UTF_8);
txt = txt.replaceFirst("(<name>)(.*?)(</name>)", "$1" + newProjectName + "$3");
FileUtils.writeStringToFile(eProject, txt, StandardCharsets.UTF_8);
}
String xsdInternalPath = newProject.getDirPath() + "/" + Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
File xsdInternalDir = new File(xsdInternalPath).getCanonicalFile();
if (xsdInternalDir.exists() && connectorChanged) {
boolean needConnectorRename = !oldConnectorName.equals(newConnectorName);
if (needConnectorRename) {
File srcDir = new File(xsdInternalDir, oldConnectorName);
File destDir = new File(xsdInternalDir, newConnectorName);
if (oldConnectorName.equalsIgnoreCase(newConnectorName)) {
File destDirTmp = new File(xsdInternalDir, "tmp" + oldConnectorName).getCanonicalFile();
FileUtils.moveDirectory(srcDir, destDirTmp);
srcDir = destDirTmp;
}
FileUtils.moveDirectory(srcDir, destDir);
}
for (File connectorDir : xsdInternalDir.listFiles()) {
if (connectorDir.isDirectory()) {
String connectorName = connectorDir.getName();
for (File transactionXsdFile : connectorDir.listFiles()) {
String xsdFilePath = transactionXsdFile.getCanonicalPath();
ProjectUtils.xsdRenameProject(xsdFilePath, oldProjectName, newProjectName);
if (needConnectorRename && connectorName.equals(newConnectorName)) {
ProjectUtils.xsdRenameConnector(xsdFilePath, oldConnectorName, newConnectorName);
}
}
}
}
}
monitor.setTaskName("Schemas updated");
monitor.worked(1);
if (updateTreeView) {
updateProjectTreeView();
}
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("An error occured while updating transaction schemas", e);
}
} catch (Exception e) {
// Delete everything
try {
Engine.logBeans.error("An error occured while creating project, everything will be deleted. Please see Studio logs for more informations.", null);
// TODO : see if we can delete oldProjectName : a real project
// could exist with this oldProjectName ?
// Engine.theApp.databaseObjectsManager.deleteProject(oldProjectName,
// false, false);
Engine.theApp.databaseObjectsManager.deleteProject(newProjectName, false, false);
projectName = null;
} catch (Exception ex) {
}
throw new Exception("Unable to create project from template", e);
}
return newProject;
}
use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.
the class AdoptClientCookies method execute.
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
HttpConnector connector = this.getConnector();
com.twinsoft.convertigo.engine.Context context = this.getParentTransaction().context;
if (connector.handleCookie) {
HttpState httpState = context.httpState;
if (httpState == null) {
connector.resetHttpState(context);
httpState = context.httpState;
}
Map<String, List<String>> requestHeaders = context.getRequestHeaders();
List<String> lCookies = requestHeaders.get("cookie");
if (lCookies != null) {
for (String sCookies : lCookies) {
Engine.logBeans.debug("(AdoptClientCookies) adding cookies: " + sCookies);
String[] cookies = sCookies.split(";");
for (String cookie : cookies) {
String[] cookieParams = cookie.split("=");
String name = cookieParams[0].trim();
String value = (cookieParams.length > 1 ? cookieParams[1] : "");
String domain;
try {
String url = context.httpServletRequest.getRequestURL().toString();
Engine.logBeans.debug("(AdoptClientCookies) requested url: " + url);
domain = new URL(url).getHost();
Matcher matcher = regexpHost.matcher(domain);
if (matcher.matches()) {
domain = matcher.group(1);
Engine.logBeans.debug("(AdoptClientCookies) sub domain match: " + domain);
} else {
Engine.logBeans.debug("(AdoptClientCookies) using default domain: " + domain);
}
CookiesUtils.addCookie(httpState, domain, name, value, "/", new Date(Long.MAX_VALUE), false);
} catch (MalformedURLException e) {
Engine.logBeans.error("(AdoptClientCookies) unable to add cookie: " + cookie, e);
}
}
}
}
}
return true;
}
return false;
}
use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.
the class CookiesAddStatement method execute.
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.execute(javascriptContext, scope)) {
HttpConnector connector = this.getConnector();
if (connector.handleCookie) {
HttpState httpState = this.getParentTransaction().context.httpState;
if (httpState == null) {
connector.resetHttpState(this.getParentTransaction().context);
httpState = this.getParentTransaction().context.httpState;
}
evaluate(javascriptContext, scope, expression, "CookiesGet", true);
if (evaluated != null) {
if (evaluated instanceof NativeArray) {
NativeArray array = (NativeArray) evaluated;
long len = array.getLength();
for (int i = 0; i < len; i++) addCookie(httpState, array.get(i, array).toString());
} else {
addCookie(httpState, evaluated.toString());
}
}
}
return true;
}
}
return false;
}
use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.
the class HttpTransaction method makeDocument.
@Override
public void makeDocument(byte[] httpData) throws Exception {
String t = context.statistics.start(EngineStatistics.GENERATE_DOM);
try {
/**
*********************************************************************
* For projects with no DownloadHttpTransaction - CEMS version < 8.0.0
* [SP47] Download file and add attachment
**********************************************************************
*/
if (getAllowDownloadAttachment() && Boolean.TRUE.equals(context.get("doAddAttachment"))) {
try {
String contentDisposition = null;
Header[] responseHeaders = context.getResponseHeaders();
for (int i = 0; i < responseHeaders.length; i++) {
Header head = responseHeaders[i];
if (HeaderName.ContentDisposition.is(head)) {
contentDisposition = head.getValue();
break;
}
}
if (contentDisposition != null && context.contentType != null) {
int i = contentDisposition.indexOf("filename=");
if (i != -1) {
int j = contentDisposition.indexOf(';', i + "filename=".length());
if (j != -1) {
String referer = ((HttpConnector) parent).getReferer();
String downloadDir = getParameterStringValue("downloadDir");
String filename = contentDisposition.substring(i + "filename=".length(), j);
String filepath = downloadDir != null ? downloadDir + (downloadDir.endsWith("/") ? "" : "/") + filename : filename;
getAttachmentManager().addAttachment(httpData, filename, context.contentType, referer, null, null, filepath, Status.direct);
httpData = new byte[] {};
}
}
}
} catch (Exception e) {
Engine.logBeans.error("(HttpTransaction) Unable to handle attachment", e);
}
}
/**
********************************************************************
*/
String stringData = "";
if (httpData == null || httpData.length == 0) {
// nothing to do
} else if (dataEncoding == HTTP_DATA_ENCODING_STRING) {
String charset = dataStringCharset;
if (StringUtils.isBlank(charset)) {
charset = ((HttpConnector) parent).getCharset();
Engine.logBeans.debug("(HttpTransaction) 'HTTP string charset' is blank, use detected charset: " + charset);
}
if (charset == null) {
charset = "ascii";
Engine.logBeans.info("(HttpTransaction) No valid charset defined, use basic charset: " + charset);
}
try {
stringData = new String(httpData, charset);
} catch (UnsupportedEncodingException e) {
Engine.logBeans.warn("(HttpTransaction) Unsupported Encoding to decode the response, use ascii instead", e);
stringData = new String(httpData, "ascii");
}
} else if (dataEncoding == HTTP_DATA_ENCODING_BASE64) {
stringData = Base64.encodeBase64String(httpData);
} else {
throw new IllegalArgumentException("Unknown data encoding: " + dataEncoding);
}
Node child = responseInCDATA ? // remove TextCodec.UTF8Encode for #453
context.outputDocument.createCDATASection(stringData) : context.outputDocument.createTextNode(stringData);
Element outputDocumentRootElement = context.outputDocument.getDocumentElement();
outputDocumentRootElement.appendChild(child);
} finally {
context.statistics.stop(t);
}
}
use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.
the class AbstractHttpTransaction method runCore.
@Override
public void runCore() throws EngineException {
HttpConnector connector = (HttpConnector) parent;
byte[] httpData = null;
try {
String t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
try {
Engine.logBeans.debug("(HttpTransaction) Retrieving data...");
httpData = connector.getData(context);
Engine.logBeans.debug("(HttpTransaction) Data retrieved!");
} finally {
context.statistics.stop(t);
}
// Applying handler
executeHandler(EVENT_DATA_RETRIEVED, ((RequestableThread) Thread.currentThread()).javascriptContext);
// Applying the underlying process
makeDocument(httpData);
score += 1;
} catch (EngineException e) {
// If we have an error we put the pure HTTP data
if (httpData != null && getHttpInfo()) {
Engine.logEngine.warn("(AbstractHttpTransaction) EngineException during transaction execution", e);
Engine.logBeans.debug("(AbstractHttpTransaction) Adding pure Http Data in Http Info");
Document document = connector.httpInfoElement.getOwnerDocument();
Element err = document.createElement("errors");
Element puredata = document.createElement("puredata");
err.setAttribute("class", e.getClass().getCanonicalName());
err.setTextContent(e.getLocalizedMessage());
try {
String contentType, stringData;
// get content type
try {
contentType = requester.context.contentType;
} catch (Throwable t) {
Engine.logBeans.debug("Exception occured retrieving response's content-type", t);
contentType = "";
}
// if we have a text
if (contentType != null && contentType.contains("text")) {
int index = contentType.indexOf("=");
// a charset is given (Content-Type: text/plain; charset=utf-8)
if (index != -1) {
stringData = new String(httpData, contentType.substring(index + 1));
} else // no charset
{
stringData = new String(httpData);
}
// else a binary content
} else {
stringData = new String(httpData);
}
// http://qualifpc:18080/convertigo/admin/services/logs.Get
puredata.appendChild(document.createCDATASection(stringData));
} catch (Exception e2) {
throw new EngineException("An unexpected exception occured while trying to decode the HTTP data.", e2);
}
connector.httpInfoElement.appendChild(err);
connector.httpInfoElement.appendChild(puredata);
} else {
throw e;
}
} catch (MalformedURLException e) {
throw new EngineException("The URL is malformed: " + connector.sUrl + "\nPlease check your project and/or transaction settings...", e);
} catch (IOException e) {
throw new EngineException("An IO exception occured while trying to connect to the URL.\nURL: " + connector.sUrl + "\nPost query: " + connector.postQuery, e);
} catch (Exception e) {
throw new EngineException("An unexpected exception occured while trying to get the document via HTTP.", e);
} finally {
// restoreVariablesDefinition();
restoreVariables();
}
}
Aggregations