| | |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.logging.Logger; |
| | | import java.util.logging.Level; |
| | | |
| | | /** |
| | | * Der DelegateActor delegiert die Bearbeitung einer HTTP-Anfrage an einen |
| | |
| | | */ |
| | | public class DelegateActor { |
| | | |
| | | /** Der Logger dieser Klasse */ |
| | | private static final Logger logger = Logger.getLogger(DelegateActor.class.getName()); |
| | | |
| | | public boolean handle(HttpExchange exchange, Map<String, HandlerDescriptor> handlers) throws IOException { |
| | | String path = exchange.getRequestURI().getPath(); |
| | | logger.fine("path: " + path); |
| | | //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); |
| | | //logger.fine("regex: " + regex); |
| | | if(path.matches(regex)) { |
| | | try { |
| | | noMatch = false; |
| | | logger.fine("match"); |
| | | //logger.fine("match"); |
| | | //HttpHandler handler = handlers.get(regex); |
| | | HandlerDescriptor hd = handlers.get(regex); |
| | | String handlerClass = hd.getHandlerClassName(); |
| | |
| | | handler.handle(exchange); |
| | | } |
| | | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { |
| | | Logger.getLogger(PatternDelegator.class.getName()).log(Level.SEVERE, null, ex); |
| | | //Logger.getLogger(PatternDelegator.class.getName()).log(Level.SEVERE, null, ex); |
| | | } |
| | | } |
| | | } |