Package org.emrys.webosgi.core.runtime

Examples of org.emrys.webosgi.core.runtime.BundleContextRunnable


    this.filterBase = filterBase;
  }

  public void destroy() {
    if (isInitialized()) {
      BundleContextRunnable runnable = new BundleContextRunnable(
          getBundleContext()) {
        @Override
        protected IStatus execute() {
          filterBase.filter.destroy();
          return Status.OK_STATUS;
        }
      };
      runnable.run();
    }
  }
View Full Code Here


  public void doFilter(final ServletRequest request,
      final ServletResponse response, final FilterChain chain)
      throws IOException, ServletException {

    BundleContextRunnable runnable = new BundleContextRunnable(
        getBundleContext()) {
      @Override
      protected IStatus execute() {
        try {
          if (!isInitialized())
            init(null);
          filterBase.filter.doFilter(request, response, chain);
          return Status.OK_STATUS;
        } catch (Exception e) {
          // e.printStackTrace();
          // If http socket reset by client, may threw IOException
          // like SocketException. Ignore it.
          if (e instanceof IOException) {
            return Status.OK_STATUS;
          } else {
            return new Status(Status.ERROR, FwkActivator
                .getInstance().getBundleSymbleName(),
                "Servlet Filter execute failed["
                    + filterBase.clazzName + "]", e);
          }
        }
      }
    };

    runnable.run();
    IStatus status = runnable.getResult();
    if (!status.isOK()) {
      throw new ServletException(status.getException());
    }
  }
View Full Code Here

      throw new ServletException(status.getException());
    }
  }

  public void init(FilterConfig nullConfig) throws ServletException {
    BundleContextRunnable runnable = new BundleContextRunnable(
        getBundleContext()) {
      @Override
      protected IStatus execute() {
        // Make sure active the web application dynamically.
        IWebApplication webApp = getBundleContext().getWebApplication();
        if (!FwkRuntime.getInstance().makeSureWabActive(webApp)) {
          return new Status(Status.ERROR, FwkActivator.getInstance()
              .getBundleSymbleName(),
              "Web appliction not actived and wait timeout to do servlet filter:"
                  + filterBase.name);
        }

        FilterConfig filterConfig = new FilterConfig() {
          public String getFilterName() {
            return filterBase.name;
          }

          public String getInitParameter(String name) {
            if (filterBase.parameters != null)
              return filterBase.parameters.get(name);
            return null;
          }

          public Enumeration getInitParameterNames() {
            if (filterBase.parameters != null)
              return filterBase.parameters.keys();
            return null;
          }

          public ServletContext getServletContext() {
            return ctx;
          }
        };

        // Lazy load filter class.
        if (filterBase.filter == null) {
          try {
            Class clazz = getWabCtxClassLoader().loadClass(
                filterBase.clazzName);
            filterBase.filter = (Filter) clazz.newInstance();
          } catch (Exception e) {
            // e.printStackTrace();
            return new Status(Status.ERROR, FwkActivator
                .getInstance().getBundleSymbleName(),
                "Filter Instance Create failed["
                    + filterBase.clazzName + "]", e);
          }
        }

        try {
          filterBase.filter.init(filterConfig);
        } catch (ServletException e) {
          // e.printStackTrace();
          return new Status(Status.ERROR, FwkActivator.getInstance()
              .getBundleSymbleName(), "Filter Init failed["
              + filterBase.clazzName + "]", e);
        }
        setInitialized(true);
        return Status.OK_STATUS;
      }
    };

    runnable.run();
    IStatus status = runnable.getResult();
    if (!status.isOK()) {
      Throwable e = status.getException();
      if (e instanceof ServletException)
        throw (ServletException) e;
      else if (e != null)
View Full Code Here

  }

  public void destroy() {
    if (!isInitialized())
      return;
    BundleContextRunnable runnable = new BundleContextRunnable(
        getBundleContext()) {
      @Override
      protected IStatus execute() {
        try {
          servlet.destroy();
          return Status.OK_STATUS;
        } catch (Exception e) {
          // e.printStackTrace();
          return new Status(Status.ERROR, FwkActivator.getInstance()
              .getBundleSymbleName(), "Servlet destroy failed["
              + className + "]", e);
        }
      }
    };
    runnable.run();
  }
View Full Code Here

    return servlet.getServletInfo();
  }

  public void service(final ServletRequest req, final ServletResponse resp)
      throws ServletException, IOException {
    BundleContextRunnable runnable = new BundleContextRunnable(
        getBundleContext()) {
      @Override
      protected IStatus execute() {
        try {
          if (!isInitialized())
            init(null);

          if (servlet != null)
            servlet.service(req, resp);
          else {
            // Process JSP file.
            Bundle bundle = ctx.getBundle();
            JasperServletWrapper jspServlet = JspServletPool
                .getInstance(ctx);
            BundledHttpServletRequestWrapper wrapper = BundledHttpServletRequestWrapper
                .getHttpServletRequestWrapper(req, bundle);
            wrapper.setServletPath(jspFile);
            wrapper.setPathInfo(null);
            jspServlet.service(wrapper, resp);
          }
          return Status.OK_STATUS;
        } catch (Exception e) {
          // e.printStackTrace();
          return new Status(Status.ERROR, FwkActivator.getInstance()
              .getBundleSymbleName(), "Servlet service failed["
              + className + "]", e);
        }
      }
    };

    runnable.run();
    IStatus status = runnable.getResult();
    if (!status.isOK()) {
      throw new ServletException(status.getException());
    }
  }
View Full Code Here

  public void init(ServletConfig nullConfig) throws ServletException {
    // init the servlet with ServletConfig
    config = createServletConfig();
    // Servlet Init method should also be executed in Bundle-ClassLoader
    // Context.
    BundleContextRunnable runnable = new BundleContextRunnable(
        getBundleContext()) {
      @Override
      protected IStatus execute() {
        try {
          // Make sure active the web application dynamically.
          IWebApplication webApp = getBundleContext()
              .getWebApplication();
          if (!FwkRuntime.getInstance().makeSureWabActive(webApp)) {
            return new Status(Status.ERROR, FwkActivator
                .getInstance().getBundleSymbleName(),
                "Web appliction not actived and wait timeout to init servlet:"
                    + config.getServletName());
          }

          // If servlet instance be set, not try to load class.
          if (servlet != null
              || (className != null && className.length() > 0)) {
            if (servlet == null) {
              Class clazz = getWabCtxClassLoader().loadClass(
                  className);
              servlet = (Servlet) clazz.newInstance();
            }
            if (servlet.getServletConfig() == null)
              servlet.init(config);
            setInitialized(true);
          } else if (jspFile != null) {
            URL url = ctx.getResource(jspFile);
            if (url == null)
              throw new ServletException(
                  "Jsp file assigneed for servlet: " + name
                      + "not found.");
          } else
            throw new ServletException(
                "Servlet class or jsp file not assigneed for servlet: "
                    + name + ".");
        } catch (Exception e) {
          return new Status(Status.ERROR, FwkActivator.getInstance()
              .getBundleSymbleName(), "Servlet Init failed["
              + className + "]", e);
        }
        return Status.OK_STATUS;
      }
    };

    runnable.run();
    IStatus status = runnable.getResult();
    if (!status.isOK()) {
      Throwable e = status.getException();
      if (e instanceof ServletException)
        throw (ServletException) e;
      else if (e != null)
View Full Code Here

TOP

Related Classes of org.emrys.webosgi.core.runtime.BundleContextRunnable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.