summaryrefslogtreecommitdiffhomepage
path: root/src/java/nginx/unit/Context.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/java/nginx/unit/Context.java139
1 files changed, 85 insertions, 54 deletions
diff --git a/src/java/nginx/unit/Context.java b/src/java/nginx/unit/Context.java
index e1482903..6fcd6018 100644
--- a/src/java/nginx/unit/Context.java
+++ b/src/java/nginx/unit/Context.java
@@ -98,10 +98,14 @@ import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
+import javax.websocket.server.ServerEndpoint;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import nginx.unit.websocket.WsSession;
+
import org.eclipse.jetty.http.MimeTypes;
import org.w3c.dom.Document;
@@ -421,6 +425,9 @@ public class Context implements ServletContext, InitParams
loader_ = new AppClassLoader(urls,
Context.class.getClassLoader().getParent());
+ Class wsSession_class = WsSession.class;
+ trace("wsSession.test: " + WsSession.wsSession_test());
+
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(loader_);
@@ -429,28 +436,30 @@ public class Context implements ServletContext, InitParams
addListener(listener_classname);
}
- ScanResult scan_res = null;
+ ClassGraph classgraph = new ClassGraph()
+ //.verbose()
+ .overrideClassLoaders(loader_)
+ .ignoreParentClassLoaders()
+ .enableClassInfo()
+ .enableAnnotationInfo()
+ //.enableSystemPackages()
+ .whitelistModules("javax.*")
+ //.enableAllInfo()
+ ;
- if (!metadata_complete_) {
- ClassGraph classgraph = new ClassGraph()
- //.verbose()
- .overrideClassLoaders(loader_)
- .ignoreParentClassLoaders()
- .enableClassInfo()
- .enableAnnotationInfo()
- //.enableSystemPackages()
- .whitelistModules("javax.*")
- //.enableAllInfo()
- ;
-
- String verbose = System.getProperty("nginx.unit.context.classgraph.verbose", "").trim();
-
- if (verbose.equals("true")) {
- classgraph.verbose();
- }
+ String verbose = System.getProperty("nginx.unit.context.classgraph.verbose", "").trim();
+
+ if (verbose.equals("true")) {
+ classgraph.verbose();
+ }
+
+ ScanResult scan_res = classgraph.scan();
+
+ javax.websocket.server.ServerEndpointConfig.Configurator.setDefault(new nginx.unit.websocket.server.DefaultServerEndpointConfigurator());
- scan_res = classgraph.scan();
+ loadInitializer(new nginx.unit.websocket.server.WsSci(), scan_res);
+ if (!metadata_complete_) {
loadInitializers(scan_res);
}
@@ -1471,54 +1480,61 @@ public class Context implements ServletContext, InitParams
ServiceLoader.load(ServletContainerInitializer.class, loader_);
for (ServletContainerInitializer sci : initializers) {
+ loadInitializer(sci, scan_res);
+ }
+ }
- trace("loadInitializers: initializer: " + sci.getClass().getName());
+ private void loadInitializer(ServletContainerInitializer sci, ScanResult scan_res)
+ {
+ trace("loadInitializer: initializer: " + sci.getClass().getName());
- HandlesTypes ann = sci.getClass().getAnnotation(HandlesTypes.class);
- if (ann == null) {
- trace("loadInitializers: no HandlesTypes annotation");
- continue;
- }
+ HandlesTypes ann = sci.getClass().getAnnotation(HandlesTypes.class);
+ if (ann == null) {
+ trace("loadInitializer: no HandlesTypes annotation");
+ return;
+ }
- Class<?>[] classes = ann.value();
- if (classes == null) {
- trace("loadInitializers: no handles classes");
- continue;
- }
+ Class<?>[] classes = ann.value();
+ if (classes == null) {
+ trace("loadInitializer: no handles classes");
+ return;
+ }
- Set<Class<?>> handles_classes = new HashSet<>();
+ Set<Class<?>> handles_classes = new HashSet<>();
- for (Class<?> c : classes) {
- trace("loadInitializers: find handles: " + c.getName());
+ for (Class<?> c : classes) {
+ trace("loadInitializer: find handles: " + c.getName());
- ClassInfoList handles = c.isInterface()
+ ClassInfoList handles =
+ c.isAnnotation()
+ ? scan_res.getClassesWithAnnotation(c.getName())
+ : c.isInterface()
? scan_res.getClassesImplementing(c.getName())
: scan_res.getSubclasses(c.getName());
- for (ClassInfo ci : handles) {
- if (ci.isInterface()
- || ci.isAnnotation()
- || ci.isAbstract())
- {
- continue;
- }
-
- trace("loadInitializers: handles class: " + ci.getName());
- handles_classes.add(ci.loadClass());
+ for (ClassInfo ci : handles) {
+ if (ci.isInterface()
+ || ci.isAnnotation()
+ || ci.isAbstract())
+ {
+ return;
}
- }
- if (handles_classes.isEmpty()) {
- trace("loadInitializers: no handles implementations");
- continue;
+ trace("loadInitializer: handles class: " + ci.getName());
+ handles_classes.add(ci.loadClass());
}
+ }
- try {
- sci.onStartup(handles_classes, this);
- metadata_complete_ = true;
- } catch(Exception e) {
- System.err.println("loadInitializers: exception caught: " + e.toString());
- }
+ if (handles_classes.isEmpty()) {
+ trace("loadInitializer: no handles implementations");
+ return;
+ }
+
+ try {
+ sci.onStartup(handles_classes, this);
+ metadata_complete_ = true;
+ } catch(Exception e) {
+ System.err.println("loadInitializer: exception caught: " + e.toString());
}
}
@@ -1691,6 +1707,21 @@ public class Context implements ServletContext, InitParams
listener_classnames_.add(ci.getName());
}
+
+
+ ClassInfoList endpoints = scan_res.getClassesWithAnnotation(ServerEndpoint.class.getName());
+
+ for (ClassInfo ci : endpoints) {
+ if (ci.isInterface()
+ || ci.isAnnotation()
+ || ci.isAbstract())
+ {
+ trace("scanClasses: skip server end point: " + ci.getName());
+ continue;
+ }
+
+ trace("scanClasses: server end point: " + ci.getName());
+ }
}
public void stop() throws IOException