Package org.emrys.webosgi.core.service

Examples of org.emrys.webosgi.core.service.IWABServletContext


    // Validate context path
    validateContextPath();

    // It need wab servlet context be registered to web container early for
    // resource publish.
    IWABServletContext servletContext = getBundleServletContext();
    try {
      if (!getWebContainer().getAllBundledServletContext().contains(
          servletContext)) {
        getWebContainer().regServletContext(servletContext);
      }
View Full Code Here


   *
   * @param wabCtxPath
   * @return
   */
  public static Bundle findWabByContextPath(String wabCtxPath) {
    IWABServletContext ctx = FwkActivator.getInstance().getJeeContainer()
        .getWABServletContext(wabCtxPath);
    if (ctx != null)
      return ctx.getBundle();
    return null;
  }
View Full Code Here

    ClonedExecutableServletObject<ServletDelegate> servletDelegateCopy = calculateServlet(
        originalServletPath, sortedSerlvetCopys);
    if (servletDelegateCopy == null)
      return null;

    IWABServletContext ctx = servletDelegateCopy.getOriginalObj()
        .getBundleContext();

    // switchReqBundleContext(ctx.getBundle());
    String servletPrefix = (String) webContainer.getReqThreadVariants()
        .get(REQ_V_MAPPED_SERVLET_PREFIX);

    String newServletPath = servletPrefix;
    if (servletPrefix.startsWith(ctx.getWABContextPath()))
      newServletPath = new Path(servletPrefix).removeFirstSegments(1)
          .makeAbsolute().toPortableString();

    if (newServletPath.equals("/"))
      newServletPath = null;
View Full Code Here

   */
  public <T extends AbstMultiInstUrlMapObject> List<T> findURLParttensObjects(
      ServletContext ctx, Class<T> type, IServletFilter filter) {
    List<T> result = new ArrayList<T>();
    if (ctx instanceof IWABServletContext) {
      IWABServletContext octx = (IWABServletContext) ctx;
      Collection<? extends AbstMultiInstUrlMapObject> servlets = null;
      if (type.equals(ServletDelegate.class))
        servlets = octx.getServletsInfo();
      if (type.equals(FilterDelegate.class))
        servlets = octx.getFilters();
      for (AbstMultiInstUrlMapObject info : servlets) {
        if (filter == null || filter.intrest(info))
          result.add((T) info);
      }
    } else {
View Full Code Here

   */
  public <T extends EventListener> List<T> findListeners(ServletContext ctx,
      Class<T> type) {
    List<T> result = new ArrayList<T>();
    if (ctx instanceof IWABServletContext) {
      IWABServletContext octx = (IWABServletContext) ctx;
      Collection<ListenerInfo> listeners = octx.getListeners();
      ListenerInfo[] listenerArray = listeners
          .toArray(new ListenerInfo[listeners.size()]);
      for (ListenerInfo info : listenerArray) {
        try {
          EventListener l = info.getListener();
View Full Code Here

   * @param b
   */
  private void triggerReqListener(
      final BundledHttpServletRequestWrapper httpReq,
      final boolean created) {
    IWABServletContext curBundleServletCtx = null;
    // NOTE: In case /p?abc, the servlet path is null.
    String servletPath = httpReq.getServletPath();
    if (!StringUtils.isEmpty(servletPath)) {
      IPath path = new Path(servletPath);
      if (path.segmentCount() > 1) {
        String nsPrefix = path.segment(0);
        curBundleServletCtx = getBundledServletContext(nsPrefix);
      }
    }
    if (curBundleServletCtx == null)
      curBundleServletCtx = findHostServletContext();

    // Invoke Request listeners in current bundle context and modified
    // thread context class loader.
    if (curBundleServletCtx != null) {
      final IWABServletContext ctx = curBundleServletCtx;
      httpReq.setBundle(ctx.getBundle());
      try {
        BundleContextRunnable runnable = new BundleContextRunnable(ctx) {
          @Override
          protected IStatus execute() {
            List<ServletRequestListener> listeners = helper
View Full Code Here

  public ServletContext getContext(String uripath) {
    // Allow to switch to another bundled servlet context.
    IPath path = new Path(uripath);
    String seg1 = path.segment(0);
    IWABServletContext ctx = webContainer.getBundledServletContext(seg1);
    if (ctx != null)
      return ctx;

    return this;// globalContext.getContext(uripath);
  }
View Full Code Here

  private boolean adjustRequestPath(BundledHttpServletRequestWrapper request,
      HttpServletResponseWrapper response) throws IOException {

    IPath path = new Path(request.getServletPath());
    String welcomePagePath = null;
    IWABServletContext hostServletCtx = getFwkContainer()
        .findHostServletContext();
    // Try to process under host bundle servlet context at first.
    if (hostServletCtx != null) {
      // Adjust a resource directory path suffixed with "/" if need.
      if (!request.getServletPath().endsWith("/")
          && getFwkContainerHelper().checkIsResourceDir(
              hostServletCtx, path)) {
        response.sendRedirect(request.getRequestURI() + "/");
        return false;
      }

      welcomePagePath = getFwkContainerHelper().tryRedirectToWelcomPage(
          hostServletCtx, path);
      if (welcomePagePath != null)
        request.setServletPath(path.append(welcomePagePath)
            .toPortableString());
    }

    // Then find a target bundle context.
    if (welcomePagePath == null && path.segmentCount() > 0) {
      IWABServletContext tarBundleServletCtx = getFwkContainer()
          .getBundledServletContext(path.segment(0));
      if (tarBundleServletCtx != null) {
        // Adjust a resource directory path suffixed with "/" if need.
        if (!request.getServletPath().endsWith("/")
            && getFwkContainerHelper().checkIsResourceDir(
View Full Code Here

            // prefix to identifing the jsp file.
            /*
             * resPath = resPath.replaceFirst("/" +
             * webComActivator.getServiceNSPrefix(), "");
             */
            IWABServletContext ctx = ((WebComActivator) activator)
                .getBundleServletContext();
            if (ctx.isStaticResource(resPath)) {
              URL url = ctx.getResource(resPath);
              if (url != null) {
                String lastSeg = new Path(url.getPath())
                    .lastSegment();
                if (lastSeg != null
                    && (lastSeg.endsWith(".jsp") || lastSeg
                        .endsWith(".jsf"))) {
                  processJspFile(null, resPath, ctx
                      .getBundle());
                } else {
                  InputStream resSrcInput = url.openStream();
                  ServletOutputStream output = resp
                      .getOutputStream();
                  int availableByteCount = 0;
                  while ((availableByteCount = resSrcInput
                      .available()) > 0) {
                    byte[] data = new byte[availableByteCount];
                    resSrcInput.read(data);
                    output.write(data);
                  }
                  resSrcInput.close();
                  resSrcInput = null;
                  resp.setContentType(ctx.getMimeType(url
                      .getFile()));
                }
                return;
              }
            }
View Full Code Here

        if (webBundlePrefix.equals("/" + firstSeg))
          return oReqPath;
      }
    }

    IWABServletContext hostServletContext = null;
    // If this req path is "/" and host web context exists, do search its
    // welcome pages and redirect.
    if (oReqPath.equals("/")
        && (hostServletContext = webContainer.findHostServletContext()) != null) {
      // Try to load the welcome page from the root of a web bundle, then
      // redirect the response.
      List<String> welcomePages = hostServletContext.getWelcomePages();
      for (Iterator<String> it = welcomePages.iterator(); it.hasNext();) {
        String welcomeFilePath = it.next();
        if (hostServletContext.getResource(welcomeFilePath) != null) {
          BundledHttpServletRequestWrapper req = (BundledHttpServletRequestWrapper) threadScope
              .get().get(RESPONSE_REQ);
          // oReqPath =
          // path.append(welcomeFilePath).toPortableString();
          // req.setPathInfo(oReqPath);
View Full Code Here

TOP

Related Classes of org.emrys.webosgi.core.service.IWABServletContext

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.