use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.
the class RouteBuilderImpl method createStaticRouter.
private void createStaticRouter(UrlPath urlPath, Port exposedPort, HttpMethod httpMethod, Charset urlEncoding, VirtualFile file, boolean isOnClassPath, boolean isFile) {
String urlSubPath = urlPath.getSubPath();
List<String> pathParamNames = new ArrayList<>();
Pattern patternToMatch;
if (file.isDirectory() && isFile) {
throw new IllegalArgumentException("directory=" + file.getCanonicalPath() + " is not a file and must be for adding a static file route");
} else if (!file.isDirectory() && !isFile) {
throw new IllegalArgumentException("file=" + file.getCanonicalPath() + " is not a directory and must be for adding a static directory route");
}
if (file.isDirectory()) {
// Customer can supply the resource capture group OR we provide it if it is a simple directory match
if (!urlSubPath.contains("<resource>")) {
patternToMatch = Pattern.compile("^" + urlSubPath + "(?<resource>.*)$");
} else {
patternToMatch = Pattern.compile("^" + urlSubPath + "$");
}
pathParamNames.add("resource");
} else {
// it is a file
patternToMatch = Pattern.compile("^" + urlSubPath + "$");
}
MatchInfo matchInfo = new MatchInfo(urlPath, exposedPort, httpMethod, urlEncoding, patternToMatch, pathParamNames);
String relativePath = urlSubPath.substring(1);
File targetCacheLocation = FileFactory.newFile(holder.getCachedCompressedDirectory(), relativePath);
FStaticRouter router = new FStaticRouter(holder.getRouteInvoker2(), matchInfo, file, isOnClassPath, targetCacheLocation, isFile);
staticRouters.add(router);
log.info("scope:'" + routerInfo + "' added route=" + matchInfo + " fileSystemPath=" + file);
}
use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.
the class SharedMatchUtil method buildRoutes.
protected List<AbstractRouter> buildRoutes(List<FilterInfo<?>> routeFilters) {
List<AbstractRouter> routers = new ArrayList<>();
for (RouterAndInfo routerAndInfo : newDynamicRoutes) {
AbstractDynamicRouter router = routerAndInfo.getRouter();
MatchInfo matchInfo = router.getMatchInfo();
String path = matchInfo.getFullPath();
Port port = matchInfo.getExposedPorts();
ResolvedMethod methodMeta = routerAndInfo.getMetaAndController().getMethodMeta();
StreamService streamSvc;
if (routerAndInfo.getRouteType() == RouteType.STREAMING) {
streamSvc = new StreamProxy(holder.getFutureUtil(), holder.getServiceInvoker());
} else {
// Wire in request/response filters at this point
List<FilterInfo<?>> filters = findMatchingFilters(methodMeta, path, port, routeFilters);
FilterCreationMeta chainInfo = new FilterCreationMeta(resettingLogic.getInjector(), filters, routerAndInfo.getSvcProxy());
Service<MethodMeta, Action> service = holder.getFinder().loadFilters(chainInfo);
Processor processor;
if (routerAndInfo.getRouteType() == RouteType.CONTENT) {
processor = holder.getResponseProcessorContent();
} else if (routerAndInfo.getRouteType() == RouteType.HTML) {
processor = holder.getResponseProcessorHtml();
} else {
throw new IllegalStateException("RouteType not supported here=" + routerAndInfo.getRouteType());
}
String i18nBundleName = routerAndInfo.getRouteInfo().getRouteModuleInfo().getI18nBundleName();
Endpoint svc = new Endpoint(service);
streamSvc = new RequestResponseStream(svc, i18nBundleName, processor, holder.getBodyParsers(), holder.getServiceInvoker());
}
// Add streaming filters at this point here...
router.setDynamicInfo(streamSvc);
routers.add(router);
}
return routers;
}
use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.
the class ScopedRouteBuilderImpl 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);
}
use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.
the class ScopedRouteBuilderImpl method addRoute.
@Override
public void addRoute(Port port, HttpMethod method, String path, String controllerMethod, RouteId routeId, boolean checkToken) {
if (!controllerMethod.contains("."))
throw new IllegalArgumentException("controllerMethod='" + controllerMethod + " does not contain a '.' which is required separating class name and method");
UrlPath p = new UrlPath(routerInfo, path);
boolean isPostOnly = method == HttpMethod.POST;
RouteModuleInfo moduleInfo = CurrentRoutes.get();
RouteInfo routeInfo = new RouteInfo(moduleInfo, controllerMethod);
// MUST DO loadControllerIntoMetat HERE so stack trace has customer's line in it so he knows EXACTLY what
// he did wrong when reading the exception!!
MethodMetaAndController metaAndController = holder.getFinder().loadHtmlController(resettingLogic.getInjector(), routeInfo, isPostOnly);
MatchInfo matchInfo = createMatchInfo(p, port, method, holder.getUrlEncoding());
LoadedController loadedController = metaAndController.getLoadedController();
FHtmlRouter router = new FHtmlRouter(holder.getRouteInvoker2(), loadedController, moduleInfo.getI18nBundleName(), matchInfo, checkToken);
SvcProxyForHtml svc = new SvcProxyForHtml(holder.getSvcProxyLogic(), futureUtil);
RouterAndInfo routerAndInfo = new RouterAndInfo(router, routeInfo, metaAndController, svc);
newDynamicRoutes.add(routerAndInfo);
resettingLogic.getReverseRoutes().addRoute(routeId, router);
log.info("scope:'" + routerInfo + "' added route=" + matchInfo + " method=" + routeInfo.getControllerMethodString());
}
use of org.webpieces.router.impl.routers.MatchInfo in project webpieces by deanhiller.
the class ScopedRouteBuilderImpl method addContentRoute.
@Override
public void addContentRoute(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!!
BinderAndLoader container = holder.getFinder().loadContentController(resettingLogic.getInjector(), routeInfo);
MatchInfo matchInfo = createMatchInfo(p, port, method, 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);
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());
}
Aggregations