| | |
| | | * ausgefuehrt werden soll |
| | | */ |
| | | public void setActor(Type methodType, String route, String className) { |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "type {0} route {1} className {2}", new Object[]{methodType, route, className}); |
| | | ActionDescriptor ad = new ActionDescriptor(); |
| | | ad.className = className; |
| | | ad.routeParams = new HashMap<>(); |
| | |
| | | .split("/"); |
| | | for (int i = 0; i < params.length; i++) { |
| | | ad.routeParams.put(params[i], i); |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "ActionDescriptor param {0} no. {1}", new Object[]{params[i], i}); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "ActionDescriptor param {0} no. {1}", new Object[]{params[i], i}); |
| | | } |
| | | ad.route = route.substring(0, pos - 1); |
| | | } else { |
| | |
| | | @SuppressWarnings("unchecked") |
| | | HashMap<String, ActionDescriptor> map = (HashMap) adMapObj; |
| | | map.put(ad.route, ad); |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "ActionDescriptor route {0} className {1}", new Object[]{route, className}); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "ActionDescriptor route {0} className {1}", new Object[]{route, className}); |
| | | //dispatcher.put(methodType, map); |
| | | } else { |
| | | Logger.getLogger(Handler.class.getName()).finer("ActionDescriptorMap nicht gefunden"); |
| | | } |
| | |
| | | .getPath() |
| | | .length()); |
| | | String requestMethodStr = exchange.getRequestMethod(); |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "method {0} route {1}", new Object[]{requestMethodStr, route}); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "method {0} route {1}", new Object[]{requestMethodStr, route}); |
| | | Type requestMethod = Type.valueOf(requestMethodStr); |
| | | /* |
| | | Es wird erst geprueft, ob zu einer bestimmten Route |
| | |
| | | if (!(o instanceof ActionDescriptor)) { |
| | | while (!found && (pos > -1)) { |
| | | String routeRest = route.substring(0, pos); |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "pos {0} routeRest {1}", new Object[]{pos, routeRest}); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "pos {0} routeRest {1}", new Object[]{pos, routeRest}); |
| | | o = ((Map) md).get(routeRest); |
| | | if (o instanceof ActionDescriptor) { |
| | | found = true; |
| | |
| | | } |
| | | } else { |
| | | // keine Actions fuer HTTP Methode |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "Kein Actions fuer HTTP-Methode {0}", requestMethodStr); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "Kein Actions fuer HTTP-Methode {0}", requestMethodStr); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void handleRequest(HttpExchange exchange, Object o, String route, String subroute, Type requestMethod) throws IOException { |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "Handle Request route {0} subroute {1}", new Object[]{route, subroute}); |
| | | private void handleRequest(HttpExchange exchange, Object o, String route, String subroute, |
| | | Type requestMethod) |
| | | throws IOException { |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "Handle Request route {0} subroute {1}", new Object[]{route, subroute}); |
| | | ActionDescriptor ad = (ActionDescriptor) o; |
| | | String actorClassName = ad.className; |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "Handle Request actor class name {0}", new Object[]{actorClassName}); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "Handle Request actor class name {0}", new Object[]{actorClassName}); |
| | | try { |
| | | Class actorClass = Class.forName(actorClassName); |
| | | Logger.getLogger(Handler.class.getName()).log(Level.FINER, "Handle Request actor class found: {0}", new Object[]{actorClass.getName()}); |
| | | //Class actorClass = Class.forName(actorClassName); |
| | | Scanner s = new Scanner(o.getClass(), Actor.class); |
| | | Class actorClass = s.getCl().loadClass(actorClassName); |
| | | Logger.getLogger(Handler.class.getName()).log( |
| | | Level.FINER, "Handle Request actor class found: {0}", new Object[]{actorClass.getName()}); |
| | | Method[] methods = actorClass.getMethods(); |
| | | for (Method method : methods) { |
| | | Action action = method.getAnnotation(Action.class); |
| | | if (action != null) { |
| | | if ((action.route().equals("/") || action.route().startsWith(route)) && action.type().equals(requestMethod)) { |
| | | if ((action.route().equals("/") || |
| | | action.route().startsWith(route)) && action.type().equals(requestMethod)) { |
| | | Object[] actionArgs = getActionArgs(exchange, method, ad, subroute); |
| | | @SuppressWarnings("unchecked") |
| | | Object conObj = actorClass.getDeclaredConstructor(); |
| | |
| | | if (methodParam.getType().equals(HttpExchange.class)) { |
| | | actionArgs[k] = exchange; |
| | | } else { |
| | | Logger.getLogger(Handler.class.getName()).finer("method name " + methodParam.getName()); |
| | | Integer i = ad.routeParams.getOrDefault(methodParam.getName(), -1); |
| | | Logger.getLogger(Handler.class.getName()).finer("param no " + i); |
| | | if (i < 0) { |
| | | actionArgs[k] = queryParams.get(methodParam.getName()); |
| | | i = getArgNoFromArgStr(methodParam.getName()); |
| | | Logger.getLogger(Handler.class.getName()).finer("param no " + i); |
| | | if(i < 0) { |
| | | actionArgs[k] = queryParams.get(methodParam.getName()); |
| | | } else { |
| | | actionArgs[k] = routeParams[i]; |
| | | Logger.getLogger(Handler.class.getName()).finer("routeParam " + i + ": " + routeParams[i]); |
| | | } |
| | | } else { |
| | | actionArgs[k] = routeParams[i + 1]; |
| | | Logger.getLogger(Handler.class.getName()).finer("routeParam " + i+1 + ": " + routeParams[i + 1]); |
| | |
| | | } |
| | | return actionArgs; |
| | | } |
| | | |
| | | private int getArgNoFromArgStr(String argStr) { |
| | | int argNo = -1; |
| | | if(argStr.contains("arg")) { |
| | | String numStr = argStr.substring("arg".length()); |
| | | Logger.getLogger(Handler.class.getName()).finer("numStr " + numStr); |
| | | argNo = Integer.parseInt(numStr); |
| | | } |
| | | return argNo; |
| | | } |
| | | |
| | | private void addDataProvider(HttpExchange exchange, Object actorObj) { |
| | | if (actorObj instanceof DataConsumer) { |