protected void inject() {
    WebApplicationContext applicationContext = getApplicationContext();

    applicationContext
        .getAutowireCapableBeanFactory()
        .autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
  }
  public int doStartTagInternal() throws JspException {
    try {

      if (filePathUtils == null || imageUtils == null) {
        WebApplicationContext wac = getRequestContext().getWebApplicationContext();
        AutowireCapableBeanFactory factory = wac.getAutowireCapableBeanFactory();
        factory.autowireBean(this);
      }

      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

      MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE);

      StringBuilder imagePath = new StringBuilder();

      String baseUrl = filePathUtils.buildStoreUri(merchantStore, request);
      imagePath.append(baseUrl);

      pageContext.getOut().print(imagePath.toString());

    } catch (Exception ex) {
      LOGGER.error("Error while getting content url", ex);
    }
    return SKIP_BODY;
  }
Esempio n. 3
0
  /**
   * Executes Grails bootstrap classes
   *
   * @param application The Grails ApplicationContext instance
   * @param webContext The WebApplicationContext instance
   * @param servletContext The ServletContext instance
   */
  public static void executeGrailsBootstraps(
      GrailsApplication application,
      WebApplicationContext webContext,
      ServletContext servletContext) {

    PersistenceContextInterceptor interceptor = null;
    String[] beanNames = webContext.getBeanNamesForType(PersistenceContextInterceptor.class);
    if (beanNames.length > 0) {
      interceptor = (PersistenceContextInterceptor) webContext.getBean(beanNames[0]);
    }

    if (interceptor != null) {
      interceptor.init();
    }
    // init the Grails application
    try {
      GrailsClass[] bootstraps = application.getArtefacts(BootstrapArtefactHandler.TYPE);
      for (GrailsClass bootstrap : bootstraps) {
        final GrailsBootstrapClass bootstrapClass = (GrailsBootstrapClass) bootstrap;
        final Object instance = bootstrapClass.getReferenceInstance();
        webContext
            .getAutowireCapableBeanFactory()
            .autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
        bootstrapClass.callInit(servletContext);
      }
      if (interceptor != null) {
        interceptor.flush();
      }
    } finally {
      if (interceptor != null) {
        interceptor.destroy();
      }
    }
  }
 public void init() throws ServletException {
   super.init();
   WebApplicationContext ctx =
       WebApplicationContextUtils.getWebApplicationContext(getServletContext());
   AutowireCapableBeanFactory factory = ctx.getAutowireCapableBeanFactory();
   factory.autowireBean(this);
 }
Esempio n. 5
0
 /*
  * This complicated getter needed so the EditServiceHelper object will be in the Spring context
  */
 public EditServiceHelper getEditServiceHelper() {
   if (editServiceHelper == null) {
     ServletContext servletContext =
         (ServletContext) context.getMessageContext().get("javax.xml.ws.servlet.context");
     WebApplicationContext webApplicationContext =
         WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
     editServiceHelper =
         webApplicationContext.getAutowireCapableBeanFactory().getBean(EditServiceHelper.class);
   }
   return editServiceHelper;
 }
  public int doStartTagInternal() throws JspException {
    try {

      if (filePathUtils == null) {
        WebApplicationContext wac = getRequestContext().getWebApplicationContext();
        AutowireCapableBeanFactory factory = wac.getAutowireCapableBeanFactory();
        factory.autowireBean(this);
      }

      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

      MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE);

      HttpSession session = request.getSession();

      StringBuilder filePath = new StringBuilder();

      // TODO domain from merchant, else from global config, else from property (localhost)

      // example -> "/files/{storeCode}/{fileName}.{extension}"

      @SuppressWarnings("unchecked")
      Map<String, String> configurations =
          (Map<String, String>) session.getAttribute(Constants.STORE_CONFIGURATION);
      String scheme = Constants.HTTP_SCHEME;
      if (configurations != null) {
        scheme = (String) configurations.get("scheme");
      }

      filePath
          .append(scheme)
          .append("://")
          .append(merchantStore.getDomainName())
          // .append("/")
          .append(request.getContextPath());

      filePath
          .append(filePathUtils.buildAdminDownloadProductFilePath(merchantStore, digitalProduct))
          .toString();

      pageContext.getOut().print(filePath.toString());

    } catch (Exception ex) {
      LOGGER.error("Error while getting content url", ex);
    }
    return SKIP_BODY;
  }
  @SuppressWarnings("unchecked")
  @Override
  public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
    // this is servlet container application context
    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();

    if (wac == null) {
      String message =
          "Failed to find the root WebApplicationContext. Was ContextLoaderListener not used?";
      logger.error(message);
      throw new IllegalStateException(message);
    }

    // obtain spring application context
    WebApplicationContext springWac =
        WebApplicationContextUtils.getWebApplicationContext(
            wac.getServletContext(), FrameworkServlet.SERVLET_CONTEXT_PREFIX + "appServlet");

    String beanName = ClassUtils.getShortNameAsProperty(endpointClass);
    if (springWac.containsBean(beanName)) {
      T endpoint = springWac.getBean(beanName, endpointClass);
      if (logger.isTraceEnabled()) {
        logger.trace("Using @ServerEndpoint singleton " + endpoint);
      }
      return endpoint;
    }

    Component annot = AnnotationUtils.findAnnotation(endpointClass, Component.class);
    if ((annot != null) && springWac.containsBean(annot.value())) {
      T endpoint = springWac.getBean(annot.value(), endpointClass);
      if (logger.isTraceEnabled()) {
        logger.trace("Using @ServerEndpoint singleton " + endpoint);
      }
      return endpoint;
    }

    beanName = getBeanNameByType(springWac, endpointClass);
    if (beanName != null) {
      return (T) springWac.getBean(beanName);
    }

    if (logger.isTraceEnabled()) {
      logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass);
    }
    return springWac.getAutowireCapableBeanFactory().createBean(endpointClass);
  }