Iterate over all registered controllers to get the first suitable one.

@param jsonPath built JsonPath object mad from request path
@param method   type of a HTTP request
@return suitable controller
549216
public Controller getController(JsonPath jsonPath, String method) {
		for (Controller controller : controllers) {
			if (controller.isAcceptable(jsonPath, method)) {
				LOGGER.debug("using controller {}", controller);
				return controller;
			}
		}
		throw new BadRequestException(jsonPath + " with method " + method);
	}
19249
public  <T extends AppController> RouteBuilder to(Class<T> type) {

        boolean hasControllerSegment = false;
        for (Segment segment : segments) {
            hasControllerSegment = segment.controller;
        }

        if (type != null && hasControllerSegment) {
            throw new IllegalArgumentException("Cannot combine {controller} segment and .to(\"...\") method. Failed route: " + routeConfig);
        }

        this.type = type;
        return this;
    }
928944
public <C> C mapTo(JavaType type) {
    JacksonJsonDataFormatMapper mapper = dataFormat.getMapper();
    return mapper.mapInternalToJava(jsonNode, type);
  }
763915
public static Type parameterizedRequestType(Method method) {
    if (method != null && method.getGenericParameterTypes().length > 0) {
      Type type = method.getGenericParameterTypes()[0];
      if (type instanceof ParameterizedType) {
        return ((ParameterizedType) type).getActualTypeArguments()[0];
      }
    }

    return Object.class;
  }
1321737
@Override
    public String getReverseRouteFor(Controller controller, String method) {
        return getReverseRouteFor(controller.getClass(), method, null);
    }
854369
private void registerControllerMethods(Map<Method, Class<? extends Annotation>> controllerMethods, Controller controller) {
        List<Route> controllerRoutes = createControllerRoutes(controllerMethods);
        for (Route controllerRoute : controllerRoutes) {
            if (controller != null) {
                ((ControllerHandler) controllerRoute.getRouteHandler()).setController(controller);
                controllerRoute.bind("__controller", controller);
            }
        }

        this.routes.addAll(controllerRoutes);
    }
546776
private ApiDoc getApiDoc(Class<?> controller, MethodDisplay displayMethodAs) {
		log.debug("Getting JSONDoc for class: " + controller.getName());
		ApiDoc apiDoc = initApiDoc(controller);

		apiDoc.setSupportedversions(JSONDocApiVersionDocBuilder.build(controller));
		apiDoc.setAuth(JSONDocApiAuthDocBuilder.getApiAuthDocForController(controller));
		apiDoc.setMethods(getApiMethodDocs(controller, displayMethodAs));
		
		if(controller.isAnnotationPresent(Api.class)) {
			apiDoc = mergeApiDoc(controller, apiDoc);
		}
		
		return apiDoc;
	}
291295
function getController (method, path, role) {
    // if path does not exist return
    if (!this.paths[path]) {
        return
    }
    // if method does not exist return
    if (!this.paths[path][method]) {
        return
    }
    // set role to default if not defined
    if (role === undefined) {
        role = 'all'
    }
    // find controller matching role
    return _.find(this.paths[path][method], controller => {
        return controller.role === role ? true : false
    })
}
569865
public static Set<ApiParamDoc> buildQueryParams(Method method) {
		Set<ApiParamDoc> apiParamDocs = new LinkedHashSet<ApiParamDoc>();
		Class<?> controller = method.getDeclaringClass();

		if (isAnnotated(controller, RequestMapping.class)) {
			RequestMapping requestMapping = getAnnotation(controller, RequestMapping.class);
			addRequestMappingParamDoc(apiParamDocs, requestMapping);
		}

		if (isAnnotated(method, RequestMapping.class)) {
			RequestMapping requestMapping = getAnnotation(method, RequestMapping.class);
			addRequestMappingParamDoc(apiParamDocs, requestMapping);
		}

		Annotation[][] parametersAnnotations = method.getParameterAnnotations();
		for (int i = 0; i < parametersAnnotations.length; i++) {
			RequestParam requestParam = null;
			ModelAttribute modelAttribute = null;
			ApiQueryParam apiQueryParam = null;
			ApiParamDoc apiParamDoc = null;
			
			for (Annotation annotation : parametersAnnotations[i]) {
				if (annotation instanceof RequestParam) {
					requestParam = (RequestParam) annotation;
				}
				if(annotation instanceof ModelAttribute) {
					modelAttribute = (ModelAttribute) annotation;
				}
				if (annotation instanceof ApiQueryParam) {
					apiQueryParam = (ApiQueryParam) annotation;
				}
				
				if (requestParam != null) {
					apiParamDoc = new ApiParamDoc(requestParam.value().isEmpty() ? requestParam.name() : requestParam.value(), "", JSONDocTypeBuilder.build(new JSONDocType(), method.getParameterTypes()[i], method.getGenericParameterTypes()[i]), String.valueOf(requestParam.required()), new String[] {}, null, requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE) ? "" : requestParam.defaultValue());
					mergeApiQueryParamDoc(apiQueryParam, apiParamDoc);
				}
				if(modelAttribute != null) {
					apiParamDoc = new ApiParamDoc(modelAttribute.value(), "", JSONDocTypeBuilder.build(new JSONDocType(), method.getParameterTypes()[i], method.getGenericParameterTypes()[i]), "false", new String[] {}, null, null);
					mergeApiQueryParamDoc(apiQueryParam, apiParamDoc);
				}
				
			}
			
			if(apiParamDoc != null) {
				apiParamDocs.add(apiParamDoc);
			}
		}
		
		return apiParamDocs;
	}
936326
public void route(HttpMethods meth, String path, API api, Code code) throws Exception {
		String version = "1.0";
		// Get Correct API Class from Mapper
		Class<?> respCls = facade1_0.mapper().getClass(api); 
		if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name());
		// setup Application API HTML ContentTypes for JSON and Route
		String application = applicationJSON(respCls, version);
		route(env,meth,path,code,application,"application/json;version="+version,"*/*");

		// setup Application API HTML ContentTypes for XML and Route
		application = applicationXML(respCls, version);
		route(env,meth,path,code.clone(facade1_0_XML),application,"application/xml;version="+version);
		
		// Add other Supported APIs here as created
	}
509652
public static JSONObject getJSONObject(HttpGet request, Integer method, HashMap<String, String> params) throws JSONException {
        switch (method) {
        case METHOD_GET:
            return doGetRequest(request);
        default:
            throw new RuntimeException("Wrong http method requested");
        }
    }
1058432
@SuppressWarnings("unchecked")
    public static <E> JsonMapper<E> mapperFor(ParameterizedType<E> type) throws NoSuchMapperException {
        return mapperFor(type, null);
    }
606214
private void registerControllerMethods(Map<Method, Class<? extends Annotation>> discoveredMethods) {

        Collection<Method> methods = sortMethods(discoveredMethods.keySet());

        Map<Class<? extends Controller>, Set<String>> controllers = new HashMap<>();
        for (Method method : methods) {
            Class<? extends Controller> controllerClass = (Class<? extends Controller>) method.getDeclaringClass();
            if (!controllers.containsKey(controllerClass)) {
                Set<String> paths = collectPaths(controllerClass);
                controllers.put(controllerClass, paths);
            }

            Class<? extends Annotation> httpMethodAnnotationClass = discoveredMethods.get(method);
            Annotation httpMethodAnnotation = method.getAnnotation(httpMethodAnnotationClass);

            String httpMethod = httpMethodAnnotation.annotationType().getAnnotation(HttpMethod.class).value();
            String[] methodPaths = ClassUtil.executeDeclaredMethod(httpMethodAnnotation, "value");

            Set<String> controllerPaths = controllers.get(controllerClass);
            if (controllerPaths.isEmpty()) {
                // add an empty string to allow controllerPaths iteration
                controllerPaths.add("");
            }

            for (String controllerPath : controllerPaths) {

                if (methodPaths.length == 0) {
                    // method does not specify a path, inherit from controller
                    String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/");
                    ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
                    handler.validateMethodArgs(fullPath);

                    RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
                    configureRegistration(registration, method);
                    routeRegistrations.add(registration);
                } else {
                    // method specifies one or more paths, concatenate with controller paths
                    for (String methodPath : methodPaths) {
                        String path = Joiner.on("/").skipNulls().join(StringUtils.removeEnd(controllerPath, "/"), StringUtils.removeStart(methodPath, "/"));
                        String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");

                        ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
                        handler.validateMethodArgs(fullPath);

                        RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
                        configureRegistration(registration, method);
                        routeRegistrations.add(registration);
                    }
                }

            }

        }
    }
1339768
protected <T extends AppController> HttpBuilder redirect(Class<T> controllerClass, Object id){
        return redirect(controllerClass, map("id", id));
    }
514526
private JsonPath getExpression(LinkRelation rel) {
		return JsonPath.compile(String.format(pathTemplate, rel.value()));
	}
324160
private JsonPathVariableExtractor getJsonPathVariableExtractor() {
        if (jsonPathExtractor == null) {
            jsonPathExtractor = new JsonPathVariableExtractor();

            getAction().getVariableExtractors().add(jsonPathExtractor);
        }

        return jsonPathExtractor;
    }
962825
protected HttpUriRequest setupRequestJson(final String path, final String method, final String params) {
        final HttpUriRequest request = buildMethod(method, path, params);
        request.addHeader(new BasicHeader("Accept", "application/json"));
        request.addHeader(new BasicHeader("Accept-Charset", "utf-8"));
        request.setHeader(new BasicHeader("Authorization", "Basic " + new String(Base64.encodeBase64((this.token + ":" + this.secret).getBytes()))));
        return request;
    }