@Nullable private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) { String wacId = wac.getId(); Map<Class<?>, String> beanNamesByType = cache.get(wacId); if (beanNamesByType == null) { beanNamesByType = new ConcurrentHashMap<>(); cache.put(wacId, beanNamesByType); } if (!beanNamesByType.containsKey(endpointClass)) { String[] names = wac.getBeanNamesForType(endpointClass); if (names.length == 1) { beanNamesByType.put(endpointClass, names[0]); } else { beanNamesByType.put(endpointClass, NO_VALUE); if (names.length > 1) { throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" + endpointClass.getName() + "]: bean names " + Arrays.asList(names)); } } } String beanName = beanNamesByType.get(endpointClass); return (NO_VALUE.equals(beanName) ? null : beanName); }
@Nullable private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) { String wacId = wac.getId(); Map<Class<?>, String> beanNamesByType = cache.get(wacId); if (beanNamesByType == null) { beanNamesByType = new ConcurrentHashMap<>(); cache.put(wacId, beanNamesByType); } if (!beanNamesByType.containsKey(endpointClass)) { String[] names = wac.getBeanNamesForType(endpointClass); if (names.length == 1) { beanNamesByType.put(endpointClass, names[0]); } else { beanNamesByType.put(endpointClass, NO_VALUE); if (names.length > 1) { throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" + endpointClass.getName() + "]: bean names " + Arrays.asList(names)); } } } String beanName = beanNamesByType.get(endpointClass); return (NO_VALUE.equals(beanName) ? null : beanName); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { _logger.debug("Request: {}", request.getRequestURI()); try { ServletContext svCtx = request.getSession().getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(svCtx); String[] resourceProviderNames = wac.getBeanNamesForType(IProtectedResourceProvider.class); for (int i = 0; i < resourceProviderNames.length; i++) { String resourceProviderName = resourceProviderNames[i]; IProtectedResourceProvider provider = (IProtectedResourceProvider) wac.getBean(resourceProviderName); boolean responseCommitted = provider.provideProtectedResource(request, response); if (responseCommitted) { return; } } } catch (Throwable t) { _logger.error("Error providing protected resource", t); throw new ServletException("Error providing protected resource", t); } }
public static <T> T getBean(final Class<T> clazz) { final String[] beanNamesForType = getWebApplicationContext().getBeanNamesForType(clazz); return getWebApplicationContext().getBean(beanNamesForType[0], clazz); } }
@Nullable private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) { String wacId = wac.getId(); Map<Class<?>, String> beanNamesByType = cache.get(wacId); if (beanNamesByType == null) { beanNamesByType = new ConcurrentHashMap<>(); cache.put(wacId, beanNamesByType); } if (!beanNamesByType.containsKey(endpointClass)) { String[] names = wac.getBeanNamesForType(endpointClass); if (names.length == 1) { beanNamesByType.put(endpointClass, names[0]); } else { beanNamesByType.put(endpointClass, NO_VALUE); if (names.length > 1) { throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" + endpointClass.getName() + "]: bean names " + Arrays.asList(names)); } } } String beanName = beanNamesByType.get(endpointClass); return (NO_VALUE.equals(beanName) ? null : beanName); }
@Override protected void initFilterBean() throws ServletException { findWebApplicationContext(); for (String beanName : webApplicationContext.getBeanNamesForType(Filter.class)) { scanBean(webApplicationContext.getBean(beanName), beanName); } }
private static void executeSystemRefresh(WebApplicationContext wac) throws Throwable { RefreshableBean configManager = (RefreshableBean) wac.getBean(SystemConstants.BASE_CONFIG_MANAGER); configManager.refresh(); String[] defNames = wac.getBeanNamesForType(RefreshableBean.class); for (int i=0; i<defNames.length; i++) { Object bean = null; try { bean = wac.getBean(defNames[i]); } catch (Throwable t) { logger.error("error in executeSystemRefresh", t); bean = null; } if (bean != null) { ((RefreshableBean) bean).refresh(); } } }
private List<HookPointElementContainer> extractElements(HttpServletRequest request) { WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); String[] beanNames = wac.getBeanNamesForType(HookPointElementContainer.class); List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>(); for (int i=0; i<beanNames.length; i++) { HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]); if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) { containers.add(container); } } BeanComparator comparator = new BeanComparator("priority"); Collections.sort(containers, comparator); return containers; }
private List<HookPointElementContainer> extractElements(HttpServletRequest request) { WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); String[] beanNames = wac.getBeanNamesForType(HookPointElementContainer.class); List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>(); for (int i=0; i<beanNames.length; i++) { HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]); if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) { containers.add(container); } } BeanComparator comparator = new BeanComparator("priority"); Collections.sort(containers, comparator); return containers; }
private List<HookPointElementContainer> extractElements(HttpServletRequest request) { WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); String[] beanNames = wac.getBeanNamesForType(HookPointElementContainer.class); List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>(); for (int i=0; i<beanNames.length; i++) { HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]); if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) { containers.add(container); } } BeanComparator comparator = new BeanComparator("priority"); Collections.sort(containers, comparator); return containers; }
protected List<IFrameDecoratorContainer> extractDecorators() throws ApsSystemException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); List<IFrameDecoratorContainer> containters = new ArrayList<IFrameDecoratorContainer>(); try { String[] beanNames = wac.getBeanNamesForType(IFrameDecoratorContainer.class); for (int i = 0; i < beanNames.length; i++) { IFrameDecoratorContainer container = (IFrameDecoratorContainer) wac.getBean(beanNames[i]); containters.add(container); } BeanComparator comparator = new BeanComparator("order"); Collections.sort(containters, comparator); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "extractDecorators", "Error extracting widget decorators"); throw new ApsSystemException("Error extracting widget decorators", t); } return containters; }
private static void executeSystemRefresh(WebApplicationContext wac) throws Throwable { RefreshableBean configManager = (RefreshableBean) wac.getBean(SystemConstants.BASE_CONFIG_MANAGER); configManager.refresh(); String[] defNames = wac.getBeanNamesForType(RefreshableBean.class); for (int i=0; i<defNames.length; i++) { Object bean = null; try { bean = wac.getBean(defNames[i]); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, ApsWebApplicationUtils.class, "executeSystemRefresh"); bean = null; } if (bean != null) { ((RefreshableBean) bean).refresh(); } } }
@Override public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>(); ValueStack stack = this.getStack(); try { String[] beanNames = wac.getBeanNamesForType(PluginSubMenuContainer.class); for (int i=0; i<beanNames.length; i++) { PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]); containters.add(container); } if (containters.size()>0) { stack.getContext().put(this.getObjectName(), containters); stack.setValue("#attr['" + this.getObjectName() + "']", containters, false); return EVAL_BODY_INCLUDE; } } catch (Throwable t) { throw new JspException("Error creating the plugins menu list", t); } return super.doStartTag(); }
@Override public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>(); ValueStack stack = this.getStack(); try { String[] beanNames = wac.getBeanNamesForType(PluginSubMenuContainer.class); for (int i=0; i<beanNames.length; i++) { PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]); containters.add(container); } if (containters.size()>0) { stack.getContext().put(this.getObjectName(), containters); stack.setValue("#attr['" + this.getObjectName() + "']", containters, false); return EVAL_BODY_INCLUDE; } } catch (Throwable t) { throw new JspException("Error creating the plugins menu list", t); } return super.doStartTag(); }
@Override public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>(); ValueStack stack = this.getStack(); try { String[] beanNames = wac.getBeanNamesForType(PluginSubMenuContainer.class); for (int i=0; i<beanNames.length; i++) { PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]); containters.add(container); } if (containters.size()>0) { stack.getContext().put(this.getObjectName(), containters); stack.setValue("#attr['" + this.getObjectName() + "']", containters, false); return EVAL_BODY_INCLUDE; } } catch (Throwable t) { throw new JspException("Error creating the plugins menu list", t); } return super.doStartTag(); }
@Override public Map getReferencingObjects(IPage page, HttpServletRequest request) throws ApsSystemException { Map<String, List> references = new HashMap<String, List>(); try { String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageUtilizer.class); for (int i = 0; i < defNames.length; i++) { Object service = null; try { service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]); } catch (Throwable t) { _logger.error("error in hasReferencingObjects", t); service = null; } if (service != null) { PageUtilizer pageUtilizer = (PageUtilizer) service; List utilizers = pageUtilizer.getPageUtilizers(page.getCode()); if (utilizers != null && !utilizers.isEmpty()) { references.put(pageUtilizer.getName() + "Utilizers", utilizers); } } } } catch (Throwable t) { throw new ApsSystemException("Error extracting Referencing Objects", t); } return references; }
@Override public Map getReferencingObjects(Category category, HttpServletRequest request) throws ApsSystemException { Map<String, List> references = new HashMap<String, List>(); try { String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(CategoryUtilizer.class); for (int i=0; i<defNames.length; i++) { Object service = null; try { service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]); } catch (Throwable t) { _logger.error("error checking Referencing Objects", t); service = null; } if (service != null) { CategoryUtilizer categoryUtilizer = (CategoryUtilizer) service; List utilizers = categoryUtilizer.getCategoryUtilizers(category.getCode()); if (utilizers != null && !utilizers.isEmpty()) { references.put(categoryUtilizer.getName()+"Utilizers", utilizers); } } } } catch (Throwable t) { throw new ApsSystemException("Errore in hasReferencingObjects", t); } return references; }
@Override public Map<String, List<Object>> getReferencingObjects(PageModel pageModel, HttpServletRequest request) throws ApsSystemException { Map<String, List<Object>> references = new HashMap<String, List<Object>>(); try { String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageModelUtilizer.class); for (int i=0; i<defNames.length; i++) { Object service = null; try { service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]); } catch (Throwable t) { _logger.error("error in hasReferencingObjects", t); service = null; } if (service != null) { PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service; List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(pageModel.getCode()); if (utilizers != null && !utilizers.isEmpty()) { references.put(pageModelUtilizer.getName()+"Utilizers", utilizers); } } } } catch (Throwable t) { throw new ApsSystemException("Error on getReferencingObjects methods", t); } return references; }
@Override public Map getReferencingObjectsForMove(Category category, HttpServletRequest request) throws ApsSystemException { Map<String, List> references = new HashMap<String, List>(); try { String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(CategoryUtilizer.class); for (int i=0; i<defNames.length; i++) { Object service = null; try { service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]); } catch (Throwable t) { _logger.error("error checking Referencing Objects", t); service = null; } if (service != null) { CategoryUtilizer categoryUtilizer = (CategoryUtilizer) service; List utilizers = categoryUtilizer.getCategoryUtilizersForReloadReferences(category.getCode()); if (utilizers != null && !utilizers.isEmpty()) { references.put(categoryUtilizer.getName()+"Utilizers", utilizers); } } } } catch (Throwable t) { throw new ApsSystemException("Error in getReferencingObjectsForMove", t); } return references; }
@Override public Map getReferencingObjects(Content content, HttpServletRequest request) throws ApsSystemException { Map<String, List> references = new HashMap<String, List>(); try { String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(ContentUtilizer.class); for (int i=0; i<defNames.length; i++) { Object service = null; try { service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "hasReferencingObject"); service = null; } if (service != null) { ContentUtilizer contentUtilizer = (ContentUtilizer) service; List utilizers = contentUtilizer.getContentUtilizers(content.getId()); if (utilizers != null && !utilizers.isEmpty()) { references.put(contentUtilizer.getName()+"Utilizers", utilizers); } } } } catch (Throwable t) { throw new ApsSystemException("Error in hasReferencingObject method", t); } return references; }