From d3cc22c6082522c7518fe6e12010f11413b4e0c4 Mon Sep 17 00:00:00 2001
From: ulrich <ulli@ulrichs-mac.fritz.box>
Date: Mon, 24 Nov 2025 17:19:28 +0000
Subject: [PATCH] WsServerDescriptor hinzugefuegt
---
src/de/uhilger/neon/Factory.java | 57 ++++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/src/de/uhilger/neon/Factory.java b/src/de/uhilger/neon/Factory.java
index 9f9ef19..4405332 100644
--- a/src/de/uhilger/neon/Factory.java
+++ b/src/de/uhilger/neon/Factory.java
@@ -17,6 +17,7 @@
*/
package de.uhilger.neon;
+import de.uhilger.neon.entity.ActorDescriptor;
import com.google.gson.Gson;
import com.sun.net.httpserver.Authenticator;
import com.sun.net.httpserver.Filter;
@@ -35,9 +36,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -67,7 +65,7 @@
*/
public class Factory implements ScannerListener {
- private Map<String, List<TempActor>> actorMap;
+ private Map<String, List<ActorDescriptor>> actorMap;
public Factory() {
listeners = new ArrayList<>();
@@ -131,7 +129,7 @@
IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
Logger.getLogger(Factory.class.getName()).log(Level.FINER, System.getProperty("java.class.path"));
-
+
List<ServerDescriptor> serverList = d.server;
for (ServerDescriptor sd : serverList) {
HttpServer server = HttpServer.create(new InetSocketAddress(sd.port), 0);
@@ -152,23 +150,42 @@
server.setExecutor(Executors.newFixedThreadPool(10));
server.start();
}
- fireInstanceStarted();
+
+// List<WsServerDescriptor> wsserverList = d.wsserver;
+// for (WsServerDescriptor wsd : wsserverList) {
+// WebSocketServer wsserver = new SimpleWsServer(new InetSocketAddress(wsd.port));
+// fireWsServerCreated(wsserver);
+// }
+
+ fireInstanceStarted();
+
+
}
private Authenticator createAuthenticator(NeonDescriptor d) {
+ Logger.getLogger(Factory.class.getName()).log(
+ Level.FINER, "{0} ", new Object[]{"creating Authenticator"});
Authenticator auth = null;
if (d.authenticator != null) {
try {
+ Logger.getLogger(Factory.class.getName()).log(
+ Level.FINER, "Authenticator className {0} ", new Object[]{d.authenticator.className});
Object authObj = Class.forName(d.authenticator.className)
.getDeclaredConstructor().newInstance();
if (authObj instanceof Authenticator) {
auth = (Authenticator) authObj;
+ Logger.getLogger(Factory.class.getName()).log(
+ Level.FINER, "Authenticator className {0} created", new Object[]{d.authenticator.className});
return auth;
}
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException
| InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException ex) {
// Klasse nicht gefunden. Muss das geloggt oder sonstwie behandel werden?
+ Logger.getLogger(Factory.class.getName()).log(
+ Level.FINER, "Authenticator className {0} not created, error {1}",
+ new Object[]{d.authenticator.className, ex.getLocalizedMessage()});
+
return null;
}
}
@@ -194,8 +211,8 @@
*/
ctxAttrs.putAll(cd.attributes);
ctxAttrs.put("serverDataProviderList", sdp);
- if (h instanceof Handler handler) {
- wire(handler, cd.attributes.get("contextName"));
+ if (h instanceof Handler) {
+ wire((Handler) h, cd.attributes.get("contextName"));
}
if (cd.authenticator instanceof String) {
if (!(auth instanceof Authenticator)) {
@@ -212,8 +229,8 @@
//
Object filterObj = Class.forName(filterClassName)
.getDeclaredConstructor().newInstance();
- if (filterObj instanceof Filter filter) {
- ctx.getFilters().add(filter);
+ if (filterObj instanceof Filter) {
+ ctx.getFilters().add((Filter) filterObj);
}
}
}
@@ -348,10 +365,13 @@
* @param contextName Name des Kontext, dem der Handler zugeordnet ist
*/
private void wire(Handler h, String contextName) {
- List<TempActor> actorList = actorMap.get(contextName);
- Iterator<TempActor> i = actorList.iterator();
+ List<ActorDescriptor> actorList = actorMap.get(contextName);
+ Iterator<ActorDescriptor> i = actorList.iterator();
while(i.hasNext()) {
- TempActor actor = i.next();
+ ActorDescriptor actor = i.next();
+ Logger.getLogger(Factory.class.getName()).log(
+ Level.FINER, "actorClassName {0} route {1}",
+ new Object[]{actor.getActorClassName(), actor.getRoute()});
h.setActor(actor.getHttpMethod(), actor.getRoute(), actor.getActorClassName());
}
}
@@ -379,6 +399,13 @@
l.serverCreated(server);
}
}
+
+ //private void fireWsServerCreated(WebSocketServer wsserver) {
+ // for (WsFactoryListener l : listeners) {
+ // l.wsServerCreated(wsserver);
+ // }
+ //}
+
private void fireHandlerCreated(HttpContext ctx, HttpHandler h) {
for (FactoryListener l : listeners) {
@@ -413,13 +440,13 @@
if (action != null) {
List<String> actionHandlers = Arrays.asList(action.handler());
for (String contextName : actionHandlers) {
- TempActor tempActor = new TempActor();
+ ActorDescriptor tempActor = new ActorDescriptor();
tempActor.setContextName(contextName);
tempActor.setHttpMethod(action.type());
tempActor.setRoute(action.route());
tempActor.setActorClassName(foundClass.getName());
- List<TempActor> actorList = actorMap.get(contextName);
+ List<ActorDescriptor> actorList = actorMap.get(contextName);
if(actorList == null) {
actorList = new ArrayList<>();
}
--
Gitblit v1.9.3