ApplicationContextFactory.java
7.71 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.CatalogLookupAccessor
* com.scene7.is.catalog.LookupServiceHandlerFactory
* com.scene7.is.catalog.client.CatalogAttributes
* com.scene7.is.catalog.client.CatalogRecord
* com.scene7.is.catalog.client.CatalogServer
* com.scene7.is.catalog.client.CatalogServerBean
* com.scene7.is.catalog.client.DomainInfo
* com.scene7.is.catalog.client.DomainInfo$DomainInfoConverter
* com.scene7.is.catalog.client.ImageDirectory
* com.scene7.is.catalog.client.ImageDirectoryImpl
* com.scene7.is.mbeans.ps.StaticContentMBean
* com.scene7.is.mbeans.ps.StaticContentMBean$class
* com.scene7.is.util.FileUtil
* com.scene7.is.util.IOUtil
* com.scene7.is.util.OneWayConverter
* com.scene7.is.util.PSDeploymentConfigSimple
* com.scene7.is.util.collections.CollectionUtil
* javax.servlet.ServletContext
* org.springframework.beans.factory.config.ConfigurableListableBeanFactory
* org.springframework.beans.factory.config.Scope
* org.springframework.context.ConfigurableApplicationContext
* org.springframework.context.support.ClassPathXmlApplicationContext
* org.springframework.web.context.request.RequestScope
*/
package com.adobe.cq.dam.s7imaging.impl.ps;
import com.adobe.cq.dam.s7imaging.impl.is.ImageServerComponent;
import com.adobe.cq.dam.s7imaging.impl.ps.JcrResourceAccessor;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyAgmConfiguration;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyAgmServer;
import com.adobe.cq.dam.s7imaging.impl.ps.dummies.DummyRunnable;
import com.scene7.is.catalog.CatalogLookupAccessor;
import com.scene7.is.catalog.LookupServiceHandlerFactory;
import com.scene7.is.catalog.client.CatalogAttributes;
import com.scene7.is.catalog.client.CatalogRecord;
import com.scene7.is.catalog.client.CatalogServer;
import com.scene7.is.catalog.client.CatalogServerBean;
import com.scene7.is.catalog.client.DomainInfo;
import com.scene7.is.catalog.client.ImageDirectory;
import com.scene7.is.catalog.client.ImageDirectoryImpl;
import com.scene7.is.mbeans.ps.StaticContentMBean;
import com.scene7.is.util.FileUtil;
import com.scene7.is.util.IOUtil;
import com.scene7.is.util.OneWayConverter;
import com.scene7.is.util.PSDeploymentConfigSimple;
import com.scene7.is.util.collections.CollectionUtil;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationHandler;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.Scope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.request.RequestScope;
public class ApplicationContextFactory {
private static final StaticContentMBean staticContent = new StaticContentMBean(){
public String getRootPaths() {
return StaticContentMBean.class.getRootPaths((StaticContentMBean)this);
}
public void setRootPaths(String v) {
StaticContentMBean.class.setRootPaths((StaticContentMBean)this, (String)v);
}
public String rootPaths() {
return "/";
}
public void rootPaths_$eq(String rootPaths) {
throw new UnsupportedOperationException("Static content root is read only in JCR");
}
};
public static final JcrResourceAccessor resourceAccessor = JcrResourceAccessor.apply("/");
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static ConfigurableApplicationContext apply(File psHome, CatalogLookupAccessor catalogAccessor, ImageServerComponent imageServer, final ServletContext servletContext, Map<String, String> psConfig) throws IOException {
final CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> catalogService = ApplicationContextFactory.catalogServerBean(catalogAccessor);
Properties sysProps = System.getProperties();
sysProps.setProperty("com.scene7.isHome", psHome.getPath());
FileUtil.mkdir((File)psHome, (String)"cache");
File confDir = new File(psHome, "conf");
FileUtil.mkdir((File)confDir);
File svgConf = new File(confDir, "svg.conf");
svgConf.createNewFile();
final File configFile = new File(confDir, "platform-server.conf");
Properties props = new Properties();
props.setProperty("isConnection.host", imageServer.getHost());
props.setProperty("isConnection.port", CollectionUtil.mkString(Arrays.asList(imageServer.getPort()), (String)";"));
props.setProperty("fvctx.useCatalogRecordValidation", "true");
props.setProperty("fvctx.useCache", "false");
props.putAll(psConfig);
FileOutputStream out = new FileOutputStream(configFile);
try {
props.store(out, "");
}
finally {
IOUtil.closeQuietly((Closeable)out);
}
return new ClassPathXmlApplicationContext("/com/scene7/is/ps/j2ee/is-context.xml", ApplicationContextFactory.class){
public ConfigurableListableBeanFactory obtainFreshBeanFactory() {
ConfigurableListableBeanFactory f = super.obtainFreshBeanFactory();
f.registerSingleton("agm", (Object)new DummyAgmConfiguration());
f.registerSingleton("agmServer", (Object)new DummyAgmServer());
f.registerSingleton("statLogger", (Object)new DummyRunnable());
f.registerSingleton("agmRawCleanup", (Object)new DummyRunnable());
f.registerSingleton("psDeploymentConfig", (Object)new PSDeploymentConfigSimple(8080));
f.registerSingleton("servletContext", (Object)servletContext);
f.registerSingleton("defaultConfig", (Object)"classpath:/com/adobe/cq/dam/s7imaging/impl/ps/server.properties");
f.registerSingleton("customConfig", (Object)configFile.getAbsolutePath());
f.registerSingleton("catalogService", (Object)catalogService);
f.registerSingleton("imageDirectory", (Object)ApplicationContextFactory.createImageDirectory((CatalogServer)catalogService));
f.registerSingleton("staticContent", (Object)staticContent);
f.registerSingleton("resourceAccessor", (Object)ApplicationContextFactory.resourceAccessor);
f.registerScope("request", (Scope)new RequestScope());
return f;
}
};
}
private static CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> catalogServerBean(CatalogLookupAccessor catalogAccessor) {
final InvocationHandler localInvoker = LookupServiceHandlerFactory.lookupServiceInvoker((CatalogLookupAccessor)catalogAccessor);
CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo> result = new CatalogServerBean<CatalogAttributes, CatalogRecord, DomainInfo>(CatalogAttributes.catalogAttributesConverter(), CatalogRecord.catalogRecordConverter(), (OneWayConverter)DomainInfo.DomainInfoConverter.apply()){
public InvocationHandler getLocalInvoker() {
return localInvoker;
}
};
result.setCacheMaxCount(0);
return result;
}
private static ImageDirectory createImageDirectory(final CatalogServer<CatalogAttributes, CatalogRecord, DomainInfo> catalogService) {
return new ImageDirectoryImpl(){
protected CatalogServer<CatalogAttributes, CatalogRecord, DomainInfo> getService() {
return catalogService;
}
};
}
}