@Override public final <P extends Profile> P getProfile() { // Check thread cache at first ProfileHolder holder = threadScope.get(ProfileHolder.SCOPE_KEY); if (holder != null) { return (P) holder.getProfile(); } DataPort port = dataPortProv.get(); Profile profile = profileReadControl(port); // Cache the profile threadScope.put(ProfileHolder.SCOPE_KEY, new ProfileHolder(profile)); return (P) profile; }
@Override public Bundle getBundle(final String basePath) { // Check thread scope for bundle final StringKey<Bundle> scopeKey = new StringKey<>(SCOPE_KEY_PREFIX + basePath); Bundle bundle = threadScope.get(scopeKey); if (bundle != null) { return bundle; } bundle = getBundle(basePath, true); // Reference the bundle from thread scope to fast access in the same thread threadScope.put(scopeKey, bundle); return bundle; }
@Override public <T> void invoke(T target, Binder<T, WebletDataPort> binder, InvokeContext context) { try { threadScope.put(DataPort.SCOPE_KEY, dataPort); HttpRequest request = httpContextProv.get().getRequest(); CSRFProtector.check(request); binder.invoke(target, dataPort); } catch (PrincipalRequiredException pre) { if (authenticatorProv.get().authenticate()) { binder.invoke(target, dataPort); } } } }
@Override public final <P extends Principal> P getPrincipal() { // Check thread cache at first PrincipalHolder holder = threadScope.get(PrincipalHolder.SCOPE_KEY); if (holder != null) { return (P) holder.getPrincipal(); } // No principal in cache. Retrieve principal from client DataPort<Object, Object> port = dataPortProv.get(); Principal principal = principalReadControl(port); // Store principal to cache and return threadScope.put(PrincipalHolder.SCOPE_KEY, new PrincipalHolder(principal)); return (P) principal; }
@Override public void perform(HttpMethod httpMethod, String uri) { RouteTrie.RouteResolution<TeleMethod> routeResolution = routeTrie.resolveRoute(StrUtils.concatPath(httpMethod.name(), uri, RouteTrie.SEGMENT_DELEMITER)); if (routeResolution == null) { throw new UnknownRouteException(uri, httpMethod); } TeleMethod telemethod = routeResolution.getNode().getValue(); if (telemethod == null) { throw new UnknownRouteException(uri, httpMethod); } RouterContext routerContext = new RouterContext(uri, routeResolution.getParams()); threadScope.put(RouterContext.SCOPE_KEY, routerContext); telemethod.invoke(); } }