DataManagerImpl.java
9.53 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.jmx.statistics.CountStatistic
* org.apache.commons.codec.binary.Hex
* org.apache.commons.io.FileUtils
* org.apache.commons.lang.Validate
* org.apache.commons.lang.math.NumberUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.datamanager.impl;
import com.adobe.CORBA.ServantBase;
import com.adobe.aemds.bedrock.CoreConfigService;
import com.adobe.aemds.datamanager.impl.DataManagerManagedConnection;
import com.adobe.aemds.datamanager.impl.DataManagerService;
import com.adobe.aemds.datamanager.impl.FileDataBufferImpl;
import com.adobe.aemds.datamanager.impl.UrlUtil;
import com.adobe.jmx.statistics.CountStatistic;
import com.adobe.service.DataManager;
import com.adobe.service.DataManagerOperations;
import com.adobe.service.FileDataBuffer;
import com.adobe.service.FileDataBufferHelper;
import com.adobe.service.InvalidSourceException;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.math.NumberUtils;
import org.omg.CORBA.Object;
import org.omg.CORBA.UNKNOWN;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DataManagerImpl
extends ServantBase
implements DataManagerOperations {
private static final String TRANSACTION_MAX_INLINE_SIZE_KEY = "transactionMaxInlineSize";
private static final byte[] EMPTY_BYTES = new byte[0];
private static final String DATAMAN_DIR_PREFIX = "datam";
private static final Logger logger = LoggerFactory.getLogger(DataManager.class);
private static SecureRandom _random;
private final List<File> tmpFileList;
private final DataManagerManagedConnection resource;
private CoreConfigService coreConfigService;
private File temporaryDirectory;
private byte[] _invocationContext = null;
private final Map<String, java.lang.Object> sharedData;
DataManagerImpl(DataManagerManagedConnection resource) {
this.resource = resource;
this.tmpFileList = Collections.synchronizedList(new ArrayList());
this.sharedData = Collections.synchronizedMap(new HashMap());
resource.connect(this);
}
private synchronized void createTempDirectory() throws IOException {
if (this.temporaryDirectory == null) {
String DMPrefix = "datam";
String dirName = DMPrefix + DataManagerImpl.getRandomFileName();
this.temporaryDirectory = new File(this.coreConfigService.getServerTempDir(), dirName);
FileUtils.forceMkdir((File)this.temporaryDirectory);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void cleanup() {
try {
try {
if (this.temporaryDirectory != null) {
FileUtils.deleteQuietly((File)this.temporaryDirectory);
}
for (File file : this.tmpFileList) {
if (file.delete()) continue;
file.deleteOnExit();
}
java.lang.Object var4_4 = null;
this.tmpFileList.clear();
}
catch (Exception e) {
logger.error("Error cleaning up Data Manager files", (Throwable)e);
java.lang.Object var4_5 = null;
this.tmpFileList.clear();
}
}
catch (Throwable var3_7) {
java.lang.Object var4_6 = null;
this.tmpFileList.clear();
throw var3_7;
}
}
public String getTempFileName(boolean create) {
try {
boolean result;
this.createTempDirectory();
File tempFile = create ? this.createTempFile() : new File(this.temporaryDirectory, DataManagerImpl.getRandomFileName());
String retVal = tempFile.getAbsolutePath();
if (!create || !(result = tempFile.createNewFile())) {
// empty if block
}
this.resource.getService().filesAllocated.increment();
return retVal;
}
catch (Exception e) {
logger.error("Error retrieving or creating a Data Manager temporary file", (Throwable)e);
throw new UNKNOWN("Exception in getTempFileName. Exception: " + e.toString());
}
}
public void manageTempFile(String filePath) throws InvalidSourceException {
block5 : {
this.assertNotNull(filePath, "Null filePath arg.");
try {
this.createTempDirectory();
File tempFile = new File(filePath);
if (tempFile.exists()) {
String parentDir = tempFile.getParent();
if (parentDir == null || !parentDir.equals(this.temporaryDirectory.getCanonicalPath())) {
this.tmpFileList.add(new File(filePath));
}
break block5;
}
throw new InvalidSourceException("File " + filePath + " does not exist");
}
catch (InvalidSourceException e) {
logger.error("Temp file to manage does not exist at path " + filePath, (Throwable)e);
throw e;
}
catch (Exception e) {
logger.error("Error trying to manage file " + filePath, (Throwable)e);
throw new InvalidSourceException("Exception in ManageTempFile: " + e.toString());
}
}
}
public FileDataBuffer createFileDataBuffer(String filePath) throws InvalidSourceException {
this.assertNotNull(filePath, "Null filePath arg in createFileDataBuffer");
try {
File tmpFile = new File(filePath);
if (tmpFile.exists() && tmpFile.canRead()) {
FileDataBufferImpl dbImpl = new FileDataBufferImpl(filePath, this.resource);
this.resource.getService().createdFromFile.increment();
return FileDataBufferHelper.narrow(dbImpl._this());
}
}
catch (Exception e) {
logger.error("Error creating FileDataBuffer for file " + filePath, (Throwable)e);
}
throw new InvalidSourceException("Cannot open " + filePath + " for reading");
}
public FileDataBuffer createFileDataBufferFromUrl(String urlStr) throws InvalidSourceException {
return UrlUtil.createFileDataBufferFromUrl(urlStr, this);
}
public byte[] getInvocationContext() {
return this._invocationContext;
}
public void setInvocationContext(byte[] invocationContext) {
this._invocationContext = invocationContext;
}
public int getDefaultMaxInlineSize() {
return 70000;
}
public int getTransactionMaxInlineSize() {
return NumberUtils.toInt((String)this.get("transactionMaxInlineSize"), (int)this.getDefaultMaxInlineSize());
}
public void setTransactionMaxInlineSize(int size) {
this.setTransactionPropertyLong("transactionMaxInlineSize", size);
}
public synchronized byte[] getTransactionPropertyBytes(String name) {
if (this.sharedData == null) {
return EMPTY_BYTES;
}
java.lang.Object o = this.sharedData.get(name);
if (o == null || !(o instanceof byte[])) {
return EMPTY_BYTES;
}
return (byte[])o;
}
public int getTransactionPropertyLong(String name) {
return NumberUtils.toInt((String)this.get(name), (int)-1);
}
public synchronized String getTransactionPropertyString(String name) {
String result = this.get(name);
return result != null ? result : "";
}
public synchronized void setTransactionPropertyBytes(String name, byte[] data) {
Validate.notNull((java.lang.Object)data, (String)"Data cannot be null.");
this.sharedData.put(name, data);
}
public synchronized void setTransactionPropertyLong(String name, int data) {
this.sharedData.put(name, Integer.toString(data));
}
public synchronized void setTransactionPropertyString(String name, String data) {
Validate.notNull((java.lang.Object)data, (String)"Data cannot be null.");
this.sharedData.put(name, data);
}
void setCoreConfigService(CoreConfigService coreConfigService) {
this.coreConfigService = coreConfigService;
}
private String get(String key) {
return this.sharedData != null ? (String)this.sharedData.get(key) : null;
}
private void assertNotNull(java.lang.Object o, String msg) throws InvalidSourceException {
if (o == null) {
throw new InvalidSourceException(msg);
}
}
private File createTempFile() throws IOException {
return File.createTempFile("datam", null, this.temporaryDirectory);
}
private static String getRandomFileName() {
byte[] bytes = new byte[16];
DataManagerImpl.getSecureRandom().nextBytes(bytes);
return new String(Hex.encodeHex((byte[])bytes));
}
private static SecureRandom getSecureRandom() {
if (_random == null) {
try {
_random = SecureRandom.getInstance("SHA1PRNG");
return _random;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
return _random;
}
}