| | |
| | | HttpHelper hh = new HttpHelper(); |
| | | String route = hh.getRouteString(exchange); |
| | | Type requestMethod = Type.valueOf(exchange.getRequestMethod()); |
| | | Map queryParams = hh.getQueryMap(exchange); |
| | | Object o; |
| | | //Map queryParams = hh.getQueryMap(exchange); |
| | | //Object o; |
| | | |
| | | /* |
| | | Es wird erst geprueft, ob zu einer bestimmten Route |
| | |
| | | Route existiert, wird geprueft, ob ein Actor |
| | | mit der Route '/' vorhanden ist. |
| | | */ |
| | | o = dispatcher.get(requestMethod).get(route); |
| | | Object md = dispatcher.get(requestMethod); |
| | | if(md instanceof Map) { |
| | | Object o = ((Map) md).get(route); |
| | | if (!(o instanceof String)) { |
| | | o = dispatcher.get(requestMethod).get("/"); |
| | | } |
| | |
| | | Action action = method.getAnnotation(Action.class); |
| | | if (action != null) { |
| | | if (action.route().equals("/") || action.route().equals(route)) { |
| | | Object[] actionArgs = getActionArgs(exchange, method, queryParams); |
| | | Object[] actionArgs = getActionArgs(exchange, method/*, queryParams*/); |
| | | Object actorObj = actorClass.getDeclaredConstructor().newInstance(); |
| | | addDataProvider(exchange, actorObj); |
| | | Object antwort = method.invoke(actorObj, actionArgs); |
| | | if(!action.handlesResponse()) { |
| | | respond(exchange, antwort); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | // Klasse nicht gefunden. Muss das geloggt oder sonstwie behandel werden? |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private Object[] getActionArgs(HttpExchange exchange, Method method, Map queryParams) { |
| | | Object[] actionArgs = new Object[method.getParameterCount()]; |
| | | int k = 0; |
| | | private Object[] getActionArgs(HttpExchange exchange, Method method/*, Map queryParams*/) { |
| | | int count = method.getParameterCount(); |
| | | Parameter[] methodParams = method.getParameters(); |
| | | Object[] actionArgs = new Object[count]; |
| | | Map queryParams = new HashMap(); |
| | | /* |
| | | Lesen des Body der Anfrage geht nur einmal. |
| | | |
| | | bodyLesen soll nur in getQueryMap gerufen werden, wenn |
| | | die Liste der Parameter mehr als einen Parameter umfasst |
| | | oder wenn es nur ein Parameter ist, der nicht |
| | | der HttpExchange ist. |
| | | |
| | | Anderenfalls sollte erst der Actor den Body aus dem |
| | | HttpExchange lesen und nicht hier schon der Handler. |
| | | */ |
| | | if(count > 1 || !methodParams[0].getType().equals(HttpExchange.class)) { |
| | | queryParams = new HttpHelper().getQueryMap(exchange); |
| | | } |
| | | int k = 0; |
| | | for (Parameter methodParam : methodParams) { |
| | | if (methodParam.getType().equals(HttpExchange.class)) { |
| | | actionArgs[k] = exchange; |