Beispiel #1
0
  private RequestHandler lookupHandler(String uri, String methodName) {
    // We don't normalize the URI here because it is normalized when
    // the HTTP request comes in.
    if (log.logDebug()) {
      log.debug("Look up handler for URI [" + uri + "] and method [" + methodName + "]");
    }

    RequestHandler handler = null;
    Map patternMap = (Map) this.uriHandlers.get(uri);
    if (patternMap == null) {
      if (log.logDebug()) {
        log.debug("Nothing registered for uri [" + uri + "]");
      }
      return null;
    }
    Iterator patterns = patternMap.entrySet().iterator();
    while (patterns.hasNext()) {
      Map.Entry entry = (Map.Entry) patterns.next();
      Pattern pattern = (Pattern) this.globalPatternMap.get(entry.getKey());
      if (pattern.matcher(methodName).find()) {
        if (log.logDebug()) {
          log.debug("Handler matched on pattern [" + pattern + "]");
        }
        handler = (RequestHandler) entry.getValue();
      }
    }
    return handler;
  }
Beispiel #2
0
  private SocketResponseChannel newSocketResponseChannel(Socket socket, HttpRequestBuffer request) {
    Encoding rspEncoding = this.selectResponseEncoding(request);

    ResponseCoordinator rc;
    synchronized (socketResponseCoordinators) {
      rc = socketResponseCoordinators.get(socket);
      if (rc == null) {
        socketResponseCoordinators.put(socket, rc = this.newResponseCoordinator(socket));
      }
    }
    return new SocketResponseChannel(rc, request, rspEncoding);
  }
Beispiel #3
0
  // TODO: Document
  protected Encoding selectResponseEncoding(HttpRequestBuffer request) {
    Map accepted = request.getAcceptedEncodings();
    if (accepted == null) {
      return null;
    }

    Iterator encodings = accepted.keySet().iterator();
    while (encodings.hasNext()) {
      String encodingName = (String) encodings.next();
      Encoding encoding = this.contentEncodingMap.getEncoding(encodingName);
      if (encoding != null) {
        return encoding;
      }
    }

    return null;
  }
Beispiel #4
0
  private RequestHandler registerHandler(
      String uriPath, String method, RequestHandler handler, MethodCallUnmarshallerAid aid) {
    // I anticipate a common mistake when using the ProxyingRequestHandler
    // will be to forget to pass it in as the aid, so let's
    // cater for that.
    if (aid == null && handler instanceof MethodCallUnmarshallerAid) {
      aid = (MethodCallUnmarshallerAid) handler;
    }

    synchronized (this.uriHandlers) {
      if (uriPath != null) {
        uriPath = Utils.normalizeURIPath(uriPath);
      }

      Map patternMap = (Map) this.uriHandlers.get(uriPath);
      if (patternMap == null) {
        patternMap = new LinkedHashMap();
        this.uriHandlers.put(uriPath, patternMap);
      }

      Pattern pattern = (Pattern) this.globalPatternMap.get(method);
      if (pattern == null) {
        pattern = Pattern.compile(method);
        this.globalPatternMap.put(method, pattern);
      }
      RequestHandler prevHandler = (RequestHandler) patternMap.put(method, handler);
      synchronized (this.handlerUnmarshallerAids) {
        if (prevHandler != null) {
          this.handlerUnmarshallerAids.remove(prevHandler);
        }
        if (aid != null) {
          this.handlerUnmarshallerAids.put(handler, aid);
        }
      }
      return prevHandler;
    }
  }
Beispiel #5
0
 protected void deregisterResponseCoordinator(ResponseCoordinator coordinator) {
   synchronized (socketResponseCoordinators) {
     socketResponseCoordinators.remove(coordinator);
   }
 }