示例#1
0
  private void initProtocol() {
    normalizeId();

    _protocolContainer.setProtocolManager(_ejbManager.getProtocolManager());
    _protocolContainer.setURLPrefix(_urlPrefix);
    _protocolContainer.setWorkPath(_workPath);

    EjbManager manager = _ejbManager;

    for (; manager != null; manager = manager.getParent()) {
      manager.getProtocolManager().addProtocolContainer(_protocolContainer);
    }
  }
示例#2
0
  private void initEjb() throws ServletException {
    if (_ejbManager != null) return;

    /*
    String cmpJndi = "java:comp/env/cmp";
    try {
    Object cmp = new InitialContext().lookup(cmpJndi);

      if (cmp instanceof LocalContext) {
        LocalContext cxt = (LocalContext) cmp;

        LocalModel model = (LocalModel) cxt.getModel();
        _ejbManager = model.getServerContainer();
      }
    } catch (Exception e) {
    }

    if (_serverContainer == null)
      throw new ServletException(L.l("Can't find servers container at `{0}'",
                                     cmpJndi));
    */

    if (_urlPrefix != null) {
      normalizeId();

      _protocolContainer.setServerManager(_ejbManager);
      _protocolContainer.setURLPrefix(_urlPrefix);
      _protocolContainer.setWorkPath(_workPath);

      EjbManager manager = _ejbManager;

      for (; manager != null; manager = manager.getParent()) {
        manager.getProtocolManager().addProtocolContainer(_protocolContainer);
      }
    }
  }
示例#3
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;
  }
示例#4
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);
    }
  }