HTMLToPDFTransactionCallback.java
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.html2pdf.HTML2PDFConverterService
* com.adobe.html2pdf.HTML2PDFConverterServiceHelper
* com.adobe.html2pdf.Html2PdfFontPaths
* com.adobe.html2pdf.Html2PdfSettings
* com.adobe.html2pdf.HtmlToPdfFailureException
* com.adobe.native2pdf.xml.FiletypeSettings
* com.adobe.native2pdf.xml.FiletypeSettings$Settings
* com.adobe.native2pdf.xml.FiletypeSettings$Settings$Html2Pdf
* com.adobe.native2pdf.xml.Html2PdfSettings
* com.adobe.pdfg.common.AESProperties
* com.adobe.pdfg.common.JobConfiguration
* com.adobe.pdfg.common.Utils
* com.adobe.pdfg.exception.ErrorCode
* com.adobe.pdfg.exception.PDFGError
* com.adobe.pdfg.exception.PDFGRuntimeException
* com.adobe.pdfg.logging.PDFGLogger
* com.adobe.service.ConnectionFactory
* org.apache.commons.io.FileUtils
*/
package com.adobe.pdfg.callbacks;
import com.adobe.html2pdf.HTML2PDFConverterService;
import com.adobe.html2pdf.HTML2PDFConverterServiceHelper;
import com.adobe.html2pdf.Html2PdfFontPaths;
import com.adobe.html2pdf.HtmlToPdfFailureException;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.Html2PdfSettings;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.JobConfiguration;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.ErrorCode;
import com.adobe.pdfg.exception.PDFGError;
import com.adobe.pdfg.exception.PDFGRuntimeException;
import com.adobe.pdfg.impl.Html2PDFPhantomJS;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import java.io.File;
import java.math.BigDecimal;
import org.apache.commons.io.FileUtils;
import org.omg.CORBA.COMM_FAILURE;
import org.omg.CORBA.Object;
import org.omg.CORBA.SystemException;
public class HTMLToPDFTransactionCallback
implements TransactionCallback {
private ConnectionFactory htmlToPdfFactory;
private static final int MAX_RETRY_COUNT = 5;
private static final long WAIT_TIME = 60000;
private static PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(HTMLToPDFTransactionCallback.class);
private static Html2PDFPhantomJS.Pool phantomJSPool;
String m_strSourceURLPath = null;
String m_strDestinationPath = null;
long m_ltimeout = 480000;
boolean m_usePhantomJS = false;
com.adobe.html2pdf.Html2PdfSettings htmlConversionSettings = new com.adobe.html2pdf.Html2PdfSettings();
Html2PdfFontPaths fontsPath = new Html2PdfFontPaths();
public HTMLToPDFTransactionCallback(ConnectionFactory htmlToPdfFactory) {
this.htmlToPdfFactory = htmlToPdfFactory;
this.htmlToPdfFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
}
/*
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
public java.lang.Object doInTransaction() {
String jobIdentityId = (String)Utils.threadLocalValue.get();
StringBuilder debugMsgs = new StringBuilder();
boolean debugMsgsLogged = false;
debugMsgs.append("\nInside HTMLToPDFTransactionCallback.doInTransaction for job=" + jobIdentityId);
if (this.m_usePhantomJS) {
Html2PDFPhantomJS.Process phantomJS = null;
try {
Boolean bl;
block16 : {
try {
String controlFilePath;
debugMsgs.append("\nBefore obtaining a PhantomJS process instance for job=" + jobIdentityId);
phantomJS = Html2PDFPhantomJS.getPool().acquire();
debugMsgs.append("\nBefore phantomJS.convertToPdf() for job=" + jobIdentityId);
pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
String destPdfPathOrig = this.m_strDestinationPath;
if (!this.m_strDestinationPath.endsWith(".pdf")) {
this.m_strDestinationPath = this.m_strDestinationPath + ".pdf";
}
if ((controlFilePath = new File(this.m_strDestinationPath).getParent()) != null) {
controlFilePath = controlFilePath + File.separator + "ControlFile.txt";
}
phantomJS.convertToPdf(this.m_strSourceURLPath, this.m_strDestinationPath, controlFilePath, this.htmlConversionSettings, this.fontsPath, this.m_ltimeout);
FileUtils.waitFor((File)new File(controlFilePath), (int)((int)this.m_ltimeout / 1000));
if (!new File(controlFilePath).exists()) {
phantomJS.rogueProcess = true;
throw new Exception("Conversion timed out");
}
File convertedFile = new File(this.m_strDestinationPath);
convertedFile.renameTo(new File(destPdfPathOrig));
this.m_strDestinationPath = destPdfPathOrig;
bl = true;
java.lang.Object var10_20 = null;
Html2PDFPhantomJS.getPool().release(phantomJS);
if (debugMsgsLogged) break block16;
}
catch (Exception e) {
pdfgLogger.info(e.getMessage(), (java.lang.Object[])null);
PDFGError error = new PDFGError(ErrorCode.JOB_TIMEOUT_ERROR, (java.lang.Object)e.getMessage());
throw new PDFGRuntimeException(error);
}
pdfgLogger.debug(debugMsgs.toString());
}
return bl;
}
catch (Throwable var9_22) {
java.lang.Object var10_21 = null;
Html2PDFPhantomJS.getPool().release(phantomJS);
if (!debugMsgsLogged) {
pdfgLogger.debug(debugMsgs.toString());
}
throw var9_22;
}
}
HTML2PDFConverterService agent = null;
try {
Boolean error;
try {
debugMsgs.append("\nbefore obtaining a CORBA connection for job=" + jobIdentityId);
Object connection = (Object)this.htmlToPdfFactory.getConnection();
debugMsgs.append("\nbefore narrowing the CORBA connection for job=" + jobIdentityId);
agent = HTML2PDFConverterServiceHelper.narrow((Object)connection);
debugMsgs.append("\nbefore agent.ConvertToPDF for job=" + jobIdentityId);
pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
agent.ConvertToPDF(this.m_strSourceURLPath, this.m_strDestinationPath, this.htmlConversionSettings, this.fontsPath, this.m_ltimeout);
error = true;
java.lang.Object var12_23 = null;
if (debugMsgsLogged) return error;
}
catch (HtmlToPdfFailureException pfe) {
pdfgLogger.trace(pfe.getMessage(), null, (Throwable)pfe);
PDFGError error2 = new PDFGError(pfe.errorCode, (java.lang.Object)pfe.getMessage());
throw new PDFGRuntimeException(error2);
}
catch (COMM_FAILURE pfe) {
pdfgLogger.trace(pfe.getMessage(), null, (Throwable)pfe);
PDFGError error3 = new PDFGError(52016, (java.lang.Object)pfe.getMessage());
throw new PDFGRuntimeException(error3);
}
catch (SystemException pfe) {
pdfgLogger.trace(pfe.getMessage(), null, (Throwable)pfe);
PDFGError error4 = new PDFGError(52016, (java.lang.Object)pfe.getMessage());
throw new PDFGRuntimeException(error4);
}
pdfgLogger.debug(debugMsgs.toString());
return error;
}
catch (Throwable var11_25) {
java.lang.Object var12_24 = null;
if (!debugMsgsLogged) {
pdfgLogger.debug(debugMsgs.toString());
}
throw var11_25;
}
}
public void setTimeout(int timeout) {
this.m_ltimeout = (long)timeout * 1000;
}
public void setDestinationPath(String destinationPath) {
this.m_strDestinationPath = destinationPath;
}
public void setSourcePath(String sourcePath) {
this.m_strSourceURLPath = sourcePath;
}
public void setIsURL(boolean isURL) {
this.htmlConversionSettings.isURL = isURL;
}
public void setUsePhantomJS(boolean usePhantomJS) {
this.m_usePhantomJS = usePhantomJS;
}
public void setHtml2PDFparams(JobConfiguration config) {
FiletypeSettings.Settings.Html2Pdf html2pdf = config.getFiletypeSettings().getHtml2Pdf();
Html2PdfSettings htmlSettingsType = html2pdf.getHtml2PdfSettings();
this.htmlConversionSettings.spideringLevel = htmlSettingsType.getLevels();
this.htmlConversionSettings.getEntireSite = false;
this.htmlConversionSettings.isSamePath = htmlSettingsType.isSamePath();
this.htmlConversionSettings.isSameServer = htmlSettingsType.isSameServer();
this.htmlConversionSettings.isPlaceFooter = htmlSettingsType.isPlaceFooter();
this.htmlConversionSettings.isPlaceHeader = htmlSettingsType.isPlaceHeader();
this.htmlConversionSettings.MarginBottom = htmlSettingsType.getMarginBottom().doubleValue();
this.htmlConversionSettings.MarginLeft = htmlSettingsType.getMarginLeft().doubleValue();
this.htmlConversionSettings.MarginRight = htmlSettingsType.getMarginRight().doubleValue();
this.htmlConversionSettings.MarginTop = htmlSettingsType.getMarginTop().doubleValue();
this.htmlConversionSettings.Orientation = htmlSettingsType.getOrientation();
this.htmlConversionSettings.PageHeight = htmlSettingsType.getPageHeight().doubleValue();
this.htmlConversionSettings.PageWidth = htmlSettingsType.getPageWidth().doubleValue();
this.htmlConversionSettings.isBookmarks = htmlSettingsType.isCreateBookmarks();
this.htmlConversionSettings.isTagging = htmlSettingsType.isCreateTaggedPDF();
this.htmlConversionSettings.inputEncoding = htmlSettingsType.getInputEncoding();
if (this.htmlConversionSettings.inputEncoding == null) {
this.htmlConversionSettings.inputEncoding = "";
}
this.htmlConversionSettings.isForceEncoding = htmlSettingsType.isForceEncoding();
}
public void setFontsPath(Html2PdfFontPaths fontPath) {
this.fontsPath.adobeFontPath = fontPath.adobeFontPath != null ? fontPath.adobeFontPath : "";
this.fontsPath.customerFontPath = fontPath.customerFontPath != null ? fontPath.customerFontPath : "";
this.fontsPath.systemFontPath = fontPath.systemFontPath != null ? fontPath.systemFontPath : "";
}
public void setHTMLFont(String useHtmlFont) {
this.htmlConversionSettings.fallbackHTMLFont = useHtmlFont != null ? useHtmlFont : "";
}
public void setHtmlToPdfFactory(ConnectionFactory htmlToPdfFactory) {
this.htmlToPdfFactory = htmlToPdfFactory;
}
}