From 9d3717abd59e1672f5d8d7888ce613afdc7fb3c5 Mon Sep 17 00:00:00 2001 From: ulrich Date: Wed, 24 Jan 2024 13:00:11 +0000 Subject: [PATCH] HttpResponder.finish aufgeteilt --- src/de/uhilger/httpserver/base/handler/PatternDelegator.java | 46 ++-------------------------------------------- 1 files changed, 2 insertions(+), 44 deletions(-) diff --git a/src/de/uhilger/httpserver/base/handler/PatternDelegator.java b/src/de/uhilger/httpserver/base/handler/PatternDelegator.java index fca02f9..b38399f 100644 --- a/src/de/uhilger/httpserver/base/handler/PatternDelegator.java +++ b/src/de/uhilger/httpserver/base/handler/PatternDelegator.java @@ -18,15 +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; /** * Der PatternDelegator delegiert HTTP-Aufrufe an HttpHandler, indem @@ -42,9 +37,6 @@ * @version 1, 29.06.2021 */ public class PatternDelegator extends FileHandler { - - /** Der Logger dieser Klasse */ - private static final Logger logger = Logger.getLogger(PatternDelegator.class.getName()); /** die HttpHandler, an die dieser Delegator passende Anfragen weitergibt */ //private Map<String, HttpHandler> handlers; @@ -91,41 +83,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