Search in sources :

Example 6 with MatchInfo

use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.

the class ScopedRouteBuilderImpl method addStreamRoute.

@Override
public void addStreamRoute(Port port, HttpMethod method, String path, String controllerMethod, RouteId routeId) {
    UrlPath p = new UrlPath(routerInfo, path);
    RouteModuleInfo moduleInfo = CurrentRoutes.get();
    RouteInfo routeInfo = new RouteInfo(moduleInfo, controllerMethod);
    // MUST DO loadControllerIntoMeta HERE so stack trace has customer's line in it so he knows EXACTLY what
    // he did wrong when reading the exception!!
    MethodMetaAndController container = holder.getFinder().loadGenericController(resettingLogic.getInjector(), routeInfo);
    MatchInfo matchInfo = createMatchInfo(p, port, method, holder.getUrlEncoding());
    FStreamingRouter router = new FStreamingRouter(holder.getRouteInvoker2(), container.getLoadedController(), moduleInfo.getI18nBundleName(), matchInfo);
    SvcProxyForContent svc = new SvcProxyForContent(holder.getSvcProxyLogic(), futureUtil);
    RouterAndInfo routerAndInfo = new RouterAndInfo(router, routeInfo, container, svc);
    newDynamicRoutes.add(routerAndInfo);
    if (// if there is a routeId, then add the reverse mapping
    routeId != null)
        resettingLogic.getReverseRoutes().addRoute(routeId, router);
    log.info("scope:'" + routerInfo + "' added content route=" + matchInfo + " method=" + routeInfo.getControllerMethodString());
}
Also used : FStreamingRouter(org.webpieces.router.impl.routers.FStreamingRouter) UrlPath(org.webpieces.router.impl.UrlPath) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) SvcProxyForContent(org.webpieces.router.impl.services.SvcProxyForContent) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo) MethodMetaAndController(org.webpieces.router.impl.loader.MethodMetaAndController)

Example 7 with MatchInfo

use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.

the class ContentTypeBuilderImpl method addRoute.

@Override
public void addRoute(String path, String controllerMethod) {
    if (!controllerMethod.contains("."))
        throw new IllegalArgumentException("controllerMethod must contain a . for the form Controller.method");
    UrlPath p = new UrlPath(routerInfo, path);
    RouteModuleInfo moduleInfo = CurrentRoutes.get();
    RouteInfo routeInfo = new RouteInfo(moduleInfo, controllerMethod);
    // MUST DO loadControllerIntoMeta HERE so stack trace has customer's line in it so he knows EXACTLY what
    // he did wrong when reading the exception!!
    BinderAndLoader container = holder.getFinder().loadContentController(resettingLogic.getInjector(), routeInfo);
    MatchInfo matchInfo = createMatchInfo(p, Port.HTTPS, HttpMethod.POST, holder.getUrlEncoding());
    LoadedController loadedController = container.getMetaAndController().getLoadedController();
    FContentRouter router = new FContentRouter(holder.getRouteInvoker2(), loadedController, moduleInfo, matchInfo, container.getBinder());
    SvcProxyForContent svc = new SvcProxyForContent(holder.getSvcProxyLogic(), futureUtil);
    RouterAndInfo routerAndInfo = new RouterAndInfo(router, routeInfo, container.getMetaAndController(), svc);
    newDynamicRoutes.add(routerAndInfo);
    // There is no routeId...
    // if(routeId != null) //if there is a routeId, then add the reverse mapping
    // resettingLogic.getReverseRoutes().addRoute(routeId, router);
    log.info("scope:'" + routerInfo + "' added content route=" + matchInfo + " method=" + routeInfo.getControllerMethodString());
}
Also used : BinderAndLoader(org.webpieces.router.impl.loader.BinderAndLoader) LoadedController(org.webpieces.router.impl.loader.LoadedController) UrlPath(org.webpieces.router.impl.UrlPath) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) SvcProxyForContent(org.webpieces.router.impl.services.SvcProxyForContent) FContentRouter(org.webpieces.router.impl.routers.FContentRouter) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo)

Example 8 with MatchInfo

use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.

the class ContentTypeBuilderImpl method createMatchInfo.

private MatchInfo createMatchInfo(UrlPath urlPath, Port exposedPort, HttpMethod httpMethod, Charset urlEncoding) {
    RegExResult result = RegExUtil.parsePath(urlPath.getSubPath());
    Pattern patternToMatch = Pattern.compile(result.regExToMatch);
    List<String> pathParamNames = result.argNames;
    return new MatchInfo(urlPath, exposedPort, httpMethod, urlEncoding, patternToMatch, pathParamNames);
}
Also used : Pattern(java.util.regex.Pattern) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) RegExResult(org.webpieces.util.urlparse.RegExResult)

Example 9 with MatchInfo

use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.

the class ReverseRoutes method routeToUrl.

// for redirects
public UrlInfo routeToUrl(RouteId routeId, Method method, Map<String, Object> args, RequestContext ctx, HttpPort requestedPort) {
    ReversableRouter routeMeta = get(routeId);
    if (routeMeta == null)
        throw new IllegalReturnValueException("Route=" + routeId + " returned from method='" + method + "' was not added in the RouterModules");
    MatchInfo matchInfo = routeMeta.getMatchInfo();
    if (!matchInfo.matchesMethod(HttpMethod.GET))
        throw new IllegalReturnValueException("method='" + method + "' is trying to redirect to routeid=" + routeId + " but that route is not a GET method route and must be");
    Map<String, String> keysToValues = reverseTranslator.formMap(method, matchInfo.getPathParamNames(), args);
    Set<String> keySet = keysToValues.keySet();
    List<String> argNames = matchInfo.getPathParamNames();
    if (keySet.size() != argNames.size()) {
        throw new IllegalReturnValueException("Method='" + method + "' returns a Redirect action with wrong number of arguments.  args=" + keySet.size() + " when it should be size=" + argNames.size());
    }
    String path = matchInfo.getFullPath();
    for (String name : argNames) {
        String value = keysToValues.get(name);
        if (value == null)
            throw new IllegalArgumentException("Method='" + method + "' returns a Redirect that is missing argument key=" + name + " to form the url on the redirect");
        path = path.replace("{" + name + "}", value);
    }
    PortAndIsSecure info = redirectFormation.calculateInfo(matchInfo, requestedPort, ctx.getRequest());
    boolean isSecure = info.isSecure();
    int port = info.getPort();
    return new UrlInfo(isSecure, port, path);
}
Also used : IllegalReturnValueException(org.webpieces.router.api.exceptions.IllegalReturnValueException) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) PortAndIsSecure(org.webpieces.router.impl.routeinvoker.PortAndIsSecure)

Aggregations

MatchInfo (org.webpieces.router.impl.routers.MatchInfo)9 UrlPath (org.webpieces.router.impl.UrlPath)4 RouteModuleInfo (org.webpieces.router.impl.model.RouteModuleInfo)4 Pattern (java.util.regex.Pattern)3 LoadedController (org.webpieces.router.impl.loader.LoadedController)3 SvcProxyForContent (org.webpieces.router.impl.services.SvcProxyForContent)3 ArrayList (java.util.ArrayList)2 BinderAndLoader (org.webpieces.router.impl.loader.BinderAndLoader)2 MethodMetaAndController (org.webpieces.router.impl.loader.MethodMetaAndController)2 FContentRouter (org.webpieces.router.impl.routers.FContentRouter)2 RegExResult (org.webpieces.util.urlparse.RegExResult)2 File (java.io.File)1 Action (org.webpieces.router.api.controller.actions.Action)1 IllegalReturnValueException (org.webpieces.router.api.exceptions.IllegalReturnValueException)1 MethodMeta (org.webpieces.router.api.routes.MethodMeta)1 Port (org.webpieces.router.api.routes.Port)1 StreamService (org.webpieces.router.api.streams.StreamService)1 ResolvedMethod (org.webpieces.router.impl.loader.ResolvedMethod)1 PortAndIsSecure (org.webpieces.router.impl.routeinvoker.PortAndIsSecure)1 Processor (org.webpieces.router.impl.routeinvoker.Processor)1