From f9b15dc42ba641cefef8360e4bea6035d9f7e26e Mon Sep 17 00:00:00 2001
From: ulrich
Date: Sat, 03 Jul 2021 08:25:34 +0000
Subject: [PATCH] Helfer fuer Attribute hinzugefuegt

---
 src/de/uhilger/httpserver/base/handler/PatternDelegator.java |   42 ++----------------------------------------
 1 files changed, 2 insertions(+), 40 deletions(-)

diff --git a/src/de/uhilger/httpserver/base/handler/PatternDelegator.java b/src/de/uhilger/httpserver/base/handler/PatternDelegator.java
index fca02f9..2310d17 100644
--- a/src/de/uhilger/httpserver/base/handler/PatternDelegator.java
+++ b/src/de/uhilger/httpserver/base/handler/PatternDelegator.java
@@ -18,14 +18,10 @@
 package de.uhilger.httpserver.base.handler;
 
 import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
+import de.uhilger.httpserver.base.actor.DelegateActor;
 import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
@@ -91,41 +87,7 @@
    */
   @Override
   public void handle(HttpExchange exchange) throws IOException {
-    String path = exchange.getRequestURI().getPath();
-    logger.fine("path: " + path);
-    Set keys = handlers.keySet();
-    Iterator<String> i = keys.iterator();
-    boolean noMatch = true;
-    while(i.hasNext() && noMatch) {
-      String regex = i.next();
-      logger.fine("regex: " + regex);
-      if(path.matches(regex)) {
-        try {
-          noMatch = false;
-          logger.fine("match");
-          //HttpHandler handler = handlers.get(regex);
-          HandlerDescriptor hd = handlers.get(regex);
-          String handlerClass = hd.getHandlerClassName();
-          Object o = Class.forName(handlerClass).getConstructors()[0].newInstance();
-          if(o instanceof AttributeHandler) {
-            AttributeHandler handler = (AttributeHandler) o;
-            Map<String, String> attrs = hd.getAttributes();
-            Iterator<String> it = attrs.keySet().iterator();
-            while(it.hasNext()) {
-              String key = it.next();
-              String value = attrs.get(key);
-              handler.setAttribute(key, value);
-            }
-            handler.handle(exchange);      
-          } else if(o instanceof HttpHandler) {
-            HttpHandler handler = (HttpHandler) o;
-            handler.handle(exchange);      
-          }
-        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-          Logger.getLogger(PatternDelegator.class.getName()).log(Level.SEVERE, null, ex);
-        }
-      }
-    }
+    boolean noMatch = new DelegateActor().handle(exchange, handlers);
     if(noMatch) {
       super.handle(exchange);
     }

--
Gitblit v1.9.3