use of com.twinsoft.convertigo.engine.AttachmentManager.Status in project convertigo by convertigo.
the class HtmlTransaction method applyUserRequest.
public void applyUserRequest(Object object) throws EngineException {
final HtmlConnector connector = (HtmlConnector) parent;
if (!runningThread.bContinue) {
return;
}
Cookie[] cookies = new Cookie[] {};
final byte[][] httpData = { null };
try {
Document dom = null;
TriggerXMLizer triggerXML = null;
String t = context.statistics.start(EngineStatistics.HTTP_CONNECT);
try {
// Retrieving Data
if (object instanceof HtmlConnector) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from connector ...");
httpData[0] = connector.getData(context);
triggerXML = trigger;
}
if (object instanceof HTTPStatement) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from http statement ...");
connector.prepareForHTTPStatement(context);
httpData[0] = connector.getData(context);
triggerXML = ((HTTPStatement) object).getTrigger();
}
if (!alreadyConnected)
alreadyConnected = true;
Engine.logBeans.trace("(HtmlTransaction) Data retrieved!");
// Engine.logBeans.trace("(HtmlTransaction) Data html:\n"+ new String(httpData));
} finally {
context.statistics.stop(t);
}
// Retrieve cookies from HttpClient response
if (connector.handleCookie) {
cookies = connector.getCookies();
if (Engine.logBeans.isTraceEnabled()) {
Engine.logBeans.trace("(HtmlTransaction) cookies from HttpClient response :" + Arrays.asList(cookies).toString());
}
}
if (!runningThread.bContinue) {
return;
}
// Parse response : push data into HTML parser
if (!isContentTypeHTML()) {
final String[] filename = { connector.getReferer() };
int id;
if ((id = filename[0].indexOf('?')) != -1) {
filename[0] = filename[0].substring(0, id);
}
if ((id = filename[0].lastIndexOf('/')) != -1) {
filename[0] = filename[0].substring(id + 1);
}
connector.getHtmlParser().downloadRequest(context, new IDownloader() {
public String getUri() {
return connector.getReferer();
}
public String getReferrer() {
return connector.getReferer();
}
public String getFilename() {
return filename[0];
}
public byte[] getData(long timeout, long threshold) {
return httpData[0];
}
public String getContentType() {
return HtmlTransaction.this.getContentType();
}
public void cancel() {
}
public Status getStatus() {
return Status.direct;
}
});
return;
}
dom = connector.parseData(httpData[0], connector.getReferer(), connector.getCharset(), triggerXML.getTrigger());
if (!runningThread.bContinue)
return;
setCurrentXmlDocument(dom);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HtmlTransaction) Parser result dom:\n" + XMLUtils.prettyPrintDOM(dom));
if (!runningThread.bContinue)
return;
// Modify input document if needed
modifyInputDocument();
} 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);
}
if (!runningThread.bContinue)
return;
// Applying handler
executeHandler(EVENT_DATA_RETRIEVED, ((RequestableThread) Thread.currentThread()).javascriptContext);
}
Aggregations