ConverterBslJService.java
14.3 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.bedrock.CoreConfigService
* com.adobe.service.ResourceFactoryManager
* com.adobe.service.Service
* org.apache.commons.io.FilenameUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.sling.commons.osgi.OsgiUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.native2pdf.bmc;
import com.adobe.aemds.bedrock.CoreConfigService;
import com.adobe.native2pdf.bmc.ConverterBslJServiceMBean;
import com.adobe.native2pdf.bmc.ConverterBslJServiceProcessFactoryManager;
import com.adobe.service.ResourceFactoryManager;
import com.adobe.service.Service;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
import org.apache.commons.io.FilenameUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(componentAbstract=1)
public class ConverterBslJService
extends Service
implements ConverterBslJServiceMBean {
private Logger log;
protected ConverterBslJServiceProcessFactoryManager mProcessFactoryManager;
protected String m_ExecutableJava;
protected String m_AutoClassPathJars;
protected String m_MainClassArg;
protected String m_ExecutableArgs;
protected boolean m_RunConversionVisibly;
protected boolean m_ReUseAppComponent;
protected String m_JVMOptions;
protected long m_globalTimeout;
protected String m_osName;
protected String m_JavaExecutableName;
protected String m_classpathSeparator;
protected static final String EXECUTABLE_TRAMPOLINE = "bin/dll/pdfgen.exe";
protected static final String RE_USE_APP_COMPONENT = "ReUseAppComponent";
protected final boolean mUseLauncherProcess = true;
protected String mKillsplwow64;
private static final String DEFAULT_RUN_CONVERSION_VISIBLY = "false";
@Property(value={"false"})
private static final String PROP_RUN_CONVERSION_VISIBLY = "pdfg.bmc.runConversionVisibly";
private static final boolean DEFAULT_DEBUG = false;
@Property(boolValue={0})
private static final String PROP_DEBUG = "pdfg.bmc.debug";
private static final int DEFAULT_POOL_MAX = 20;
@Property(intValue={20})
private static final String PROP_POOL_MAX = "pdfg.bmc.poolMax";
private static final int DEFAULT_MAX_REUSE_COUNT = 500;
@Property(intValue={500})
private static final String PROP_MAX_REUSE_COUNT = "pdfg.bmc.poolMaxReuseCount";
private static final String DEFAULT_ORB_PARAMS = "";
@Property(value={""})
private static final String PROP_ORB_PARAMS = "pdfg.bmc.ORBParams";
private static final String DEFAULT_JVM_OPTIONS = "-Xmx64m";
@Property(value={"-Xmx64m"})
private static final String PROP_JVM_OPTIONS = "pdfg.bmc.jvmOptions";
private static final long DEFAULT_GLOBAL_TIMEOUT = 300;
@Property(longValue={300})
private static final String PROP_GLOBAL_TIMEOUT = "globalTimeout";
private Map _config;
private static final long loadMillis = System.currentTimeMillis();
private static String winstaBaseName = null;
private static int invocationNumber = 0;
public ConverterBslJService() {
this.log = LoggerFactory.getLogger(this.getClass());
this.mProcessFactoryManager = null;
this.m_AutoClassPathJars = "";
this.m_ExecutableArgs = "";
this.m_JVMOptions = "-Xmx64m";
this.m_osName = System.getProperty("os.name").toLowerCase();
this.m_JavaExecutableName = this.m_osName.startsWith("win") ? "javaw.exe" : "java";
this.m_classpathSeparator = System.getProperty("path.separator");
this.mUseLauncherProcess = true;
this.mKillsplwow64 = "False";
if (this.m_ExecutableJava == null) {
this.m_ExecutableJava = this.m_osName.startsWith("win") ? this.getWindowsJavaExecutable() : this.getUnixJavaExecutable();
}
}
private String getJavaHome() {
String java_home_32;
String java_home = java_home_32 = System.getenv("JAVA_HOME_32");
if (java_home_32 == null || "".equals(java_home_32)) {
java_home = System.getProperty("java.home");
}
return java_home;
}
private String getWindowsJavaExecutable() {
StringBuffer buff = new StringBuffer("\"");
StringTokenizer tokenizer = new StringTokenizer(this.getJavaHome(), "\\");
while (tokenizer.hasMoreTokens()) {
buff.append(tokenizer.nextToken());
buff.append("\\\\");
}
buff.append("bin\\\\");
buff.append(this.m_JavaExecutableName);
buff.append('\"');
return buff.toString();
}
private String getUnixJavaExecutable() {
StringBuffer buff = new StringBuffer("/");
StringTokenizer tokenizer = new StringTokenizer(this.getJavaHome(), "/");
while (tokenizer.hasMoreTokens()) {
buff.append(tokenizer.nextToken());
buff.append("/");
}
buff.append("bin/");
buff.append(this.m_JavaExecutableName);
buff.append('\"');
return buff.toString();
}
protected void onStartService(Map config) {
this.mProcessFactoryManager = new ConverterBslJServiceProcessFactoryManager(this);
this.lazyInitialization = true;
this._config = config;
this.registerConnectionFactoryManager((ResourceFactoryManager)this.mProcessFactoryManager);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected synchronized void deferredInitialize() {
if (this.lazyInitialization) {
try {
this.doDeferredInitialize();
}
finally {
this.lazyInitialization = false;
}
}
}
protected void doDeferredInitialize() {
try {
File persistentDir = this.getPersistentDir();
this.log.trace("Persistent Dir is " + persistentDir.getCanonicalPath());
File nativeDir = this.getNativeDir();
this.log.trace("Native Dir is " + nativeDir.getCanonicalPath());
}
catch (IOException e) {
this.log.trace(e.getMessage(), (Object)null, (Object)e);
}
File jarDir = new File(this.getNativeDir(), "bin");
String temp = this.makeClasspathFromDir(jarDir);
File commonJarDir = this.getServerCommonJarDir();
temp = temp + this.m_classpathSeparator;
temp = temp + commonJarDir.getAbsolutePath().replace('\\', '/');
temp = temp + "/";
this.m_AutoClassPathJars = temp = temp + "adobe-bslj.jar";
this.initializeConfig(this._config);
this.updateCommandLine();
}
protected void initializeConfig(Map config) {
int reuseCount = OsgiUtil.toInteger(config.get("pdfg.bmc.poolMaxReuseCount"), (int)500);
int maxPoolSize = OsgiUtil.toInteger(config.get("pdfg.bmc.poolMax"), (int)20);
boolean debug = OsgiUtil.toBoolean(config.get("pdfg.bmc.debug"), (boolean)false);
String orbParams = OsgiUtil.toString(config.get("pdfg.bmc.ORBParams"), (String)"");
String jvmOptions = OsgiUtil.toString(config.get("pdfg.bmc.jvmOptions"), (String)"-Xmx64m");
long globalTimeout = OsgiUtil.toLong(config.get("globalTimeout"), (long)300);
String runConversionVisibly = OsgiUtil.toString(config.get("pdfg.bmc.runConversionVisibly"), (String)"false");
this.setMaximumReUseCount(reuseCount);
this.setPoolMax(maxPoolSize);
this.setDebug(debug);
this.setORBParams(orbParams);
this.setJVMOptions(jvmOptions);
this.setGlobalTimeout(globalTimeout);
this.setRunConversionVisibly(runConversionVisibly);
}
private File getServerCommonJarDir() {
String commonJarDirPath = FilenameUtils.concat((String)this.getCoreConfigService().getServerNativeDir(), (String)"CommonNatives/jars");
return new File(commonJarDirPath);
}
protected synchronized void updateCommandLine() {
StringBuffer javaArgs = new StringBuffer(this.m_JVMOptions);
javaArgs.append(" -cp \"");
javaArgs.append(this.m_AutoClassPathJars);
File commonJarDir = this.getServerCommonJarDir();
File jacorbDir = new File(commonJarDir, "jacorb");
String bsljClassPathDir = jacorbDir.getAbsolutePath();
String bsljClassPath = bsljClassPathDir + File.separator + "jacorb.jar" + File.pathSeparator + bsljClassPathDir + File.separator + "avalon-framework-4.1.5.jar" + File.pathSeparator + bsljClassPathDir + File.separator + "concurrent-1.3.2.jar" + File.pathSeparator + bsljClassPathDir + File.separator + "logkit-1.2.jar" + File.pathSeparator + bsljClassPathDir + File.separator + "antlr-2.7.2.jar";
javaArgs.append(File.pathSeparator + bsljClassPath.replace('\\', '/'));
javaArgs.append("\" ");
javaArgs.append(this.m_MainClassArg);
this.mProcessFactoryManager.setExecutableName("bin/dll/pdfgen.exe");
StringBuffer sWinStaName = new StringBuffer();
StringBuffer sDesktopName = new StringBuffer();
this.getWinStationDesktopName(sWinStaName, sDesktopName);
StringBuffer trampolineArgs = new StringBuffer();
trampolineArgs.append(this.mKillsplwow64);
trampolineArgs.append(" -WinStaName ").append(sWinStaName);
trampolineArgs.append(" -DeskName ").append(sDesktopName);
trampolineArgs.append(" -beginExecutable ");
trampolineArgs.append(this.m_ExecutableJava);
trampolineArgs.append(" -endExecutable ");
trampolineArgs.append(javaArgs);
this.m_ExecutableArgs = trampolineArgs.toString();
this.mProcessFactoryManager.setExecutableArguments(this.m_ExecutableArgs);
}
protected String makeClasspathFromDir(File jarDir) {
if (!jarDir.exists()) {
String svcName = this.getName();
String errorMsg = "No such directory " + jarDir + " exists while initializing service " + svcName;
if (svcName.contains("Native") || svcName.contains("PDFMaker")) {
errorMsg = errorMsg + ". Services like NativeToPdf and PDFMaker are Windows-only, check whether the conversion API invoked is available on this platform.";
}
throw new AssertionError((Object)errorMsg);
}
String jarDirPath = jarDir.getAbsolutePath().replace('\\', '/');
File[] files = jarDir.listFiles(new FilenameFilter(){
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
StringBuffer buff = new StringBuffer();
for (int i = 0; i < files.length; ++i) {
if (i > 0) {
buff.append(this.m_classpathSeparator);
}
buff.append(jarDirPath);
buff.append('/');
buff.append(files[i].getName());
}
return buff.toString();
}
private static boolean isWindowsVista() {
String osVersion = System.getProperty("os.version");
return osVersion.startsWith("6.");
}
protected void getWinStationDesktopName(StringBuffer sWinSta, StringBuffer sDesktop) {
sWinSta.replace(0, sWinSta.length(), "WinSta0");
sDesktop.replace(0, sDesktop.length(), "default");
if (this.m_RunConversionVisibly) {
return;
}
StringBuffer result = new StringBuffer("PDF-");
if (winstaBaseName == null) {
String className = this.getClass().getName();
int lastDot = className.lastIndexOf(46);
String temp = className.substring(lastDot + 1, lastDot + 3).toUpperCase();
String tempMillis = Long.toHexString(loadMillis);
winstaBaseName = temp = temp + tempMillis.substring(tempMillis.length() - 5);
}
result.append(winstaBaseName);
String seq = Integer.toHexString(this.getInvocationNumber());
for (int i = 4 - seq.length(); i > 0; --i) {
result.append('0');
}
result.append(seq);
if (ConverterBslJService.isWindowsVista()) {
sDesktop.replace(0, sDesktop.length(), result.toString());
} else {
sWinSta.replace(0, sWinSta.length(), result.toString());
}
}
protected synchronized int getInvocationNumber() {
return ++invocationNumber;
}
public void onStopService() {
}
public String about() {
return "Adobe Experience Manager PDF Generator Native to PDF Conversion Service";
}
public String getJVMOptions() {
return this.m_JVMOptions;
}
public void setJVMOptions(String options) {
this.m_JVMOptions = options;
this.updateCommandLine();
}
public String getRunConversionVisibly() {
return String.valueOf(this.m_RunConversionVisibly);
}
public void setRunConversionVisibly(String visibility) {
this.m_RunConversionVisibly = "true".equalsIgnoreCase(visibility);
if (this.m_AutoClassPathJars.length() > 0) {
this.updateCommandLine();
}
}
public boolean getReUseAppComponent() {
return this.m_ReUseAppComponent;
}
public void setReUseAppComponent(boolean reUseAppComponent) {
this.m_ReUseAppComponent = reUseAppComponent;
}
public boolean getDebug() {
return this.mProcessFactoryManager.getDebug();
}
public void setDebug(boolean debug) {
this.mProcessFactoryManager.setDebug(debug);
}
public void setPoolMax(int newMax) {
this.mProcessFactoryManager.setPoolMax(newMax);
}
public int getPoolMax() {
return this.mProcessFactoryManager.getPoolMax();
}
public void setORBParams(String params) {
this.mProcessFactoryManager.setORBParams(params);
}
public String getORBParams() {
return this.mProcessFactoryManager.getORBParams();
}
public int getMaximumReUseCount() {
return this.mProcessFactoryManager.getMaximumReUseCount();
}
public void setMaximumReUseCount(int count) {
this.mProcessFactoryManager.setMaximumReUseCount(count);
}
public long getGlobalTimeout() {
return this.m_globalTimeout;
}
public void setGlobalTimeout(long timeout) {
this.m_globalTimeout = timeout;
}
}