use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class WebServiceServletRequester method coreProcessRequest.
@Override
protected Object coreProcessRequest() throws Exception {
Object result;
try {
if (!Engine.isSOA) {
throw new EngineException("Web Services are not available with this version of Convertigo.");
}
// fire event for plugins
Engine.theApp.pluginsManager.fireRequesterCoreProcessRequestStart(context, inputData);
makeInputDocument();
preGetDocument();
Document document = getDocument();
result = postGetDocument(document);
} catch (Throwable e) {
context.isErrorDocument = true;
result = SOAPUtils.writeSoapFault(e, context.requestedObject != null ? context.requestedObject.getEncodingCharSet() : "UTF-8");
} finally {
// fire event for plugins
Engine.theApp.pluginsManager.fireRequesterCoreProcessRequestEnd(context, inputData);
}
return result;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class WebServiceServlet method generateWsdl.
protected String generateWsdl(HttpServletRequest request) throws EngineException {
Engine.logEngine.debug("(WebServiceServlet) WSDL required");
String servletPath = request.getServletPath();
Engine.logEngine.debug("(WebServiceServlet) Servlet path: " + servletPath);
String servletURI = HttpUtils.originalRequestURL(request);
Engine.logEngine.debug("(WebServiceServlet) Servlet uri: " + servletURI);
try {
int projectNameStartIndex = servletPath.indexOf("/projects/") + 10;
int slashIndex = servletPath.indexOf("/", projectNameStartIndex);
String projectName = servletPath.substring(projectNameStartIndex, slashIndex);
Engine.logEngine.debug("(WebServiceServlet) Project name: " + projectName);
if (servletPath.endsWith(".wsl") || servletPath.endsWith(".ws") || servletPath.endsWith(".wsr")) {
return generateWsdlForDocLiteral(servletURI, projectName);
}
throw new EngineException("Unhandled SOAP method (RPC or literal accepted)");
} catch (StringIndexOutOfBoundsException e) {
throw new EngineException("Unable to find the project name into the provided URL (\"" + servletPath + "\").");
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class PdfServletRequester method performXSLT.
protected Object performXSLT(Document document) throws Exception {
String t1 = context.statistics.start(EngineStatistics.XSLT);
try {
Engine.logEngine.debug("XSL/FO process is beginning");
Object result = null;
Engine.logEngine.debug("Sheet absolute URL: " + context.absoluteSheetUrl);
if (context.absoluteSheetUrl == null)
throw new EngineException("You have required an XSL/FO process, but Convertigo has been unable to find a stylesheet for your request. Verify your project's settings.");
// XSL/FO engine
StreamSource streamSource = null;
try {
// Configure foUserAgent as desired
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.setBaseURL(new File(context.getProjectDirectory()).toURI().toASCIIString());
foUserAgent.setAuthor("Convertigo EMS");
// Setup output
org.apache.commons.io.output.ByteArrayOutputStream out = new org.apache.commons.io.output.ByteArrayOutputStream();
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
streamSource = new StreamSource(new File(context.absoluteSheetUrl).toURI().toASCIIString());
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(streamSource);
// Setup input for XSLT transformation
Element element = document.getDocumentElement();
DOMSource src = new DOMSource(element);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
result = out.toByteArray();
} finally {
if (streamSource != null) {
InputStream inputStream = streamSource.getInputStream();
if (inputStream != null)
inputStream.close();
}
}
Engine.logEngine.trace("XSLT result:\n" + result);
return result;
} finally {
Engine.logEngine.debug("XSLT process has finished");
context.statistics.stop(t1);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ProxyServletRequester method coreProcessRequest.
protected Object coreProcessRequest() throws Exception {
// The proxy converts HTML data on the fly
ParameterShuttle infoShuttle = threadParameterShuttle.get();
HttpClient httpClient = threadHttpClient.get();
HttpServletRequest request = (HttpServletRequest) inputData;
InputStream siteIn = null;
try {
try {
getUserRequest(infoShuttle, context, request);
// Loading project
if (context.projectName == null)
throw new EngineException("The project name has not been specified!");
Project currentProject;
if (Engine.isStudioMode()) {
currentProject = Engine.objectsProvider.getProject(context.projectName);
if (currentProject == null) {
throw new EngineException("No project has been opened in the Studio. A project should be opened in the Studio in order that the Convertigo engine can work.");
} else if (!currentProject.getName().equalsIgnoreCase(context.projectName)) {
throw new EngineException("The requested project (\"" + context.projectName + "\") does not match with the opened project (\"" + currentProject.getName() + "\") in the Studio.\nYou cannot make a request on a different project than the one opened in the Studio.");
}
Engine.logEngine.debug("Using project from Studio");
context.project = currentProject;
} else {
if ((context.project == null) || (context.isNewSession)) {
Engine.logEngine.debug("New project requested: '" + context.projectName + "'");
context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName);
Engine.logEngine.debug("Project loaded: " + context.project.getName());
}
}
// Loading sequence
if (context.sequenceName != null) {
context.requestedObject = context.project.getSequenceByName(context.sequenceName);
Engine.logEngine.debug("Loaded sequence: " + context.requestedObject.getName());
}
// Loading connector
context.loadConnector();
if (context.requestedObject != null)
context.requestedObject.context = context;
if (context.getConnector() != null)
context.getConnector().context = context;
if (Boolean.parseBoolean(EnginePropertiesManager.getProperty(PropertyName.SSL_DEBUG))) {
System.setProperty("javax.net.debug", "all");
Engine.logEngine.trace("(ProxyServletRequester) Enabling SSL debug mode");
} else {
System.setProperty("javax.net.debug", "");
Engine.logEngine.debug("(ProxyServletRequester) Disabling SSL debug mode");
}
if (context.getConnector().isTasAuthenticationRequired() && (context.tasSessionKey == null)) {
throw new EngineException("A Carioca authentication is required in order to process the transaction.");
}
infoShuttle.userID = context.tasUserName;
infoShuttle.userIP = context.remoteAddr;
// gather user id, parameters, headers from request
gatherRequestInfo(infoShuttle, request);
String t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
try {
// get connected
httpClient.connect(infoShuttle);
} finally {
context.statistics.stop(t);
}
if (infoShuttle.siteInputStream == null) {
Engine.logEngine.debug("(ProxyServletRequester) No input stream!");
return null;
}
siteIn = infoShuttle.siteInputStream;
Engine.logEngine.debug("(ProxyServletRequester) Start of document retransmission");
Object result;
ProxyHttpConnector proxyHttpConnector = (ProxyHttpConnector) infoShuttle.context.getConnector();
String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
String newBaseUrl = host + request.getRequestURI() + "?" + Parameter.Connector.getName() + "=" + proxyHttpConnector.getName() + "&" + Parameter.ProxyGoto.getName() + "=";
String newBaseUrlThen = newBaseUrl + URLEncoder.encode(infoShuttle.siteURL.getPath(), "UTF-8") + "&" + Parameter.ProxyThen.getName() + "=";
if (isDynamicContent(infoShuttle.siteURL.getPath(), proxyHttpConnector.getDynamicContentFiles())) {
Engine.logEngine.debug("(ProxyServletRequester) Dynamic content");
String sResponse;
StringBuffer sbResponse = new StringBuffer("");
t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
try {
int c = siteIn.read();
char cc;
while (c > -1) {
cc = (char) c;
sbResponse.append(cc);
c = siteIn.read();
}
} finally {
context.statistics.stop(t, true);
}
sResponse = sbResponse.toString();
result = sResponse;
if (infoShuttle.siteContentType == null) {
Engine.logEngine.warn("(ProxyServletRequester) Aborting string replacements because of null mimetype! Resource: " + infoShuttle.siteURL);
} else {
Engine.logEngine.debug("(ProxyServletRequester) String replacements");
// Text/html replacements
Engine.logEngine.debug("(ProxyServletRequester) Replacements for mime type '" + infoShuttle.siteContentType + "'");
Replacements replacements = proxyHttpConnector.getReplacementsForMimeType(infoShuttle.siteContentType);
if (!replacements.isEmpty()) {
StringEx sxResponse = new StringEx(sResponse);
StringEx sx;
String strSearched, strReplacing;
for (int i = 0; i < replacements.strReplacing.length; i++) {
strSearched = replacements.strSearched[i];
sx = new StringEx(strSearched);
sx.replaceAll("{tab}", "\t");
sx.replaceAll("{apos0x92}", "" + (char) 146);
sx.replaceAll("{newBaseUrl}", newBaseUrl);
sx.replaceAll("{newBaseUrlThen}", newBaseUrlThen);
strSearched = sx.toString();
replacements.strSearched[i] = strSearched;
Engine.logEngine.debug("(ProxyServletRequester) Replacing: " + strSearched);
strReplacing = replacements.strReplacing[i];
sx = new StringEx(strReplacing);
sx.replaceAll("{newBaseUrl}", newBaseUrl);
sx.replaceAll("{newBaseUrlThen}", newBaseUrlThen);
strReplacing = sx.toString();
replacements.strReplacing[i] = strReplacing;
Engine.logEngine.debug("(ProxyServletRequester) By: " + strReplacing);
}
Engine.logEngine.debug("(ProxyServletRequester) Replacements in progress");
sxResponse.replaceAll(replacements.strSearched, replacements.strReplacing);
Engine.logEngine.debug("(ProxyServletRequester) Replacements done!");
if (Engine.isStudioMode()) {
sxResponse.replaceAll("?" + Parameter.Connector.getName() + "=", "?" + Parameter.Context.getName() + "=" + infoShuttle.context.name + "&" + Parameter.Connector.getName() + "=");
}
result = sxResponse.toString();
}
}
infoShuttle.siteContentSize = ((String) result).length();
Engine.logEngine.debug("(ProxyServletRequester) HTML data retrieved!");
String billingClassName = context.getConnector().getBillingClassName();
if (billingClassName != null) {
try {
Engine.logContext.debug("Billing class name required: " + billingClassName);
AbstractBiller biller = (AbstractBiller) Class.forName(billingClassName).getConstructor().newInstance();
Engine.logContext.debug("Executing the biller");
biller.insertBilling(context);
} catch (Throwable e) {
Engine.logContext.warn("Unable to execute the biller (the billing is thus ignored): [" + e.getClass().getName() + "] " + e.getMessage());
}
}
} else {
Engine.logEngine.debug("(ProxyServletRequester) Static content: " + infoShuttle.siteContentType);
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
try {
// Read either from the cache, either from the remote server
int c = siteIn.read();
while (c > -1) {
baos.write(c);
c = siteIn.read();
}
} finally {
context.statistics.stop(t, true);
}
result = baos.toByteArray();
Engine.logEngine.debug("(ProxyServletRequester) Static data retrieved!");
// Determine if the resource has already been cached or not
String resourceUrl = infoShuttle.siteURL.toString();
CacheEntry cacheEntry = ProxyServletRequester.proxyCacheManager.getCacheEntry(resourceUrl);
if (cacheEntry == null) {
// Managing text replacements
Engine.logEngine.debug("(ProxyServletRequester) Replacements for mime type '" + infoShuttle.siteContentType + "'");
Replacements replacements = proxyHttpConnector.getReplacementsForMimeType(infoShuttle.siteContentType);
if (!replacements.isEmpty()) {
String sResult = new String((byte[]) result);
StringEx sxResponse = new StringEx(sResult);
StringEx sx;
String strSearched, strReplacing;
for (int i = 0; i < replacements.strReplacing.length; i++) {
strSearched = replacements.strSearched[i];
sx = new StringEx(strSearched);
sx.replaceAll("{tab}", "\t");
sx.replaceAll("{newBaseUrl}", newBaseUrl);
sx.replaceAll("{newBaseUrlThen}", newBaseUrlThen);
strSearched = sx.toString();
replacements.strSearched[i] = strSearched;
Engine.logEngine.debug("(ProxyServletRequester) Replacing: " + strSearched);
strReplacing = replacements.strReplacing[i];
sx = new StringEx(strReplacing);
sx.replaceAll("{newBaseUrl}", newBaseUrl);
sx.replaceAll("{newBaseUrlThen}", newBaseUrlThen);
strReplacing = sx.toString();
replacements.strReplacing[i] = strReplacing;
Engine.logEngine.debug("(ProxyServletRequester) By: " + strReplacing);
}
Engine.logEngine.debug("(ProxyServletRequester) Replacements in progress");
sxResponse.replaceAll(replacements.strSearched, replacements.strReplacing);
Engine.logEngine.debug("(ProxyServletRequester) Replacements done!");
result = sxResponse.toString().getBytes();
}
if (infoShuttle.httpCode == 200) {
Engine.logEngine.debug("(ProxyServletRequester) Resource stored: " + resourceUrl);
cacheEntry = proxyCacheManager.storeResponse(resourceUrl, (byte[]) result);
cacheEntry.contentLength = ((byte[]) result).length;
infoShuttle.siteContentSize = cacheEntry.contentLength;
cacheEntry.contentType = infoShuttle.siteContentType;
}
} else {
infoShuttle.httpCode = 200;
infoShuttle.siteContentSize = cacheEntry.contentLength;
infoShuttle.siteContentType = cacheEntry.contentType;
}
baos.close();
}
Engine.logEngine.debug("(ProxyServletRequester) End of document retransmission");
return result;
} finally {
if (siteIn != null) {
try {
siteIn.close();
} catch (Exception e) {
}
}
}
} finally {
context.contentType = infoShuttle.siteContentType;
httpClient.disconnect();
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ProjectContinuousIntegrationGradle method getJSON.
private JSONObject getJSON(String url) throws Exception {
HttpGet get = new HttpGet(url);
try (CloseableHttpResponse response = Engine.theApp.httpClient4.execute(get)) {
int code = response.getStatusLine().getStatusCode();
if (code != 200) {
throw new EngineException("Code " + code + " for " + url);
}
String sContent = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
return new JSONObject(sContent);
}
}
Aggregations