Ejemplo n.º 1
0
  /**
   * Returns the server container responsible for handling the request
   *
   * @param pathInfo the path info of the request
   * @return the server bean responsible for handling the request
   */
  Skeleton getSkeleton(String pathInfo, String queryString) throws Exception {
    CharBuffer cb = CharBuffer.allocate();
    cb.append(pathInfo);
    cb.append('?');
    cb.append(queryString);

    Skeleton skeleton = (Skeleton) _beanMap.get(cb);

    if (skeleton != null) {
      cb.free();
      return skeleton;
    }

    skeleton = _protocolContainer.getSkeleton(pathInfo, queryString);

    _beanMap.put(cb, skeleton);

    return skeleton;
  }
Ejemplo n.º 2
0
  /**
   * Execute a request. The path-info of the request selects the bean. Once the bean's selected, it
   * will be applied.
   */
  public void service(ServletRequest request, ServletResponse response)
      throws IOException, ServletException {
    CauchoRequest req = (CauchoRequest) request;
    CauchoResponse res = (CauchoResponse) response;

    if (_urlPrefix == null) {
      synchronized (this) {
        if (_urlPrefix == null) serverInit(req);
      }
    }

    if (!req.getMethod().equals("POST")) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, this + " unexpected method " + req.getMethod());

      String protocol = _protocolContainer.getName();
      res.setStatus(500, protocol + " Protocol Error");
      PrintWriter out = res.getWriter();
      out.println(protocol + " expects a POST containing an RPC call.");
      return;
    }

    try {
      String pathInfo = req.getPathInfo();
      String queryString = req.getQueryString();

      CharBuffer cb = new CharBuffer();
      cb.append(pathInfo);
      cb.append('?');
      cb.append(queryString);

      InputStream is = req.getInputStream();

      if (_isDebug) {}

      Skeleton skeleton = (Skeleton) _beanMap.get(cb);

      if (skeleton == null) {
        // If this was a load just to force the initialization, then return
        if (req.getParameter("ejb-load") != null) return;

        if (_exception != null) throw _exception;

        try {
          if (pathInfo == null) pathInfo = "";

          skeleton = _protocolContainer.getSkeleton(pathInfo, queryString);
        } catch (Exception e) {
          log.log(Level.WARNING, e.toString(), e);

          skeleton = _protocolContainer.getExceptionSkeleton();

          if (skeleton != null) {
            skeleton._service(req.getInputStream(), res.getOutputStream(), e);

            return;
          } else throw e;
        }

        if (skeleton == null)
          throw new ServletException(
              L.l("Can't load skeleton for '{0}?{1}'", pathInfo, queryString));

        if (skeleton != null) {
          skeleton.setDebug(_isDebug);
          _beanMap.put(cb, skeleton);
        }
      }

      skeleton._service(req.getInputStream(), res.getOutputStream());
    } catch (ServletException e) {
      e.printStackTrace();
      throw e;
    } catch (Throwable e) {
      e.printStackTrace();
      log.log(Level.WARNING, e.toString(), e);

      throw new ServletException(e);
    }
  }