コード例 #1
0
 public void handleRequest(String request) {
   System.out.println("Handler3 got the request...");
   if (request.equalsIgnoreCase("R3")) {
     System.out.println("Request handled by Handler3 !!!");
   } else {
     if (successor != null) {
       successor.handleRequest(request);
     }
   }
 }
コード例 #2
0
ファイル: Handler.java プロジェクト: Mohitkumar/Learning
 public final void handleRequest(Request req) {
   boolean isHandled = handleRequestImpl(req);
   if (successor != null && !isHandled) {
     successor.handleRequest(req);
   }
 }
コード例 #3
0
ファイル: API.java プロジェクト: rcamus/platform
  void process(MessageContext synCtx) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Processing message with ID: "
              + synCtx.getMessageID()
              + " through the "
              + "API: "
              + name);
    }

    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API, getName());
    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API_VERSION, versionStrategy.getVersion());
    synCtx.setProperty(RESTConstants.REST_API_CONTEXT, context);

    // Remove the API context part from the REST_URL_POSTFIX
    String restURLPostfix =
        (String)
            ((Axis2MessageContext) synCtx)
                .getAxis2MessageContext()
                .getProperty(NhttpConstants.REST_URL_POSTFIX);
    if (restURLPostfix != null) {
      if (!restURLPostfix.startsWith("/")) {
        restURLPostfix = "/" + restURLPostfix;
      }
      if (restURLPostfix.startsWith(context)) {
        restURLPostfix = restURLPostfix.substring(context.length());
        if (versionStrategy instanceof URLBasedVersionStrategy) {
          String version = versionStrategy.getVersion();
          if (restURLPostfix.startsWith(version)) {
            restURLPostfix = restURLPostfix.substring(version.length());
          } else if (restURLPostfix.startsWith("/" + version)) {
            restURLPostfix = restURLPostfix.substring(version.length() + 1);
          }
        }
        ((Axis2MessageContext) synCtx)
            .getAxis2MessageContext()
            .setProperty(NhttpConstants.REST_URL_POSTFIX, restURLPostfix);
      }
    }

    for (Handler handler : handlers) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Processing message with ID: "
                + synCtx.getMessageID()
                + " through "
                + "handler: "
                + handler.getClass().getName());
      }

      boolean proceed;
      if (synCtx.isResponse()) {
        proceed = handler.handleResponse(synCtx);
      } else {
        proceed = handler.handleRequest(synCtx);
      }

      if (!proceed) {
        return;
      }
    }

    if (synCtx.isResponse()) {
      String resourceName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_RESOURCE);
      if (resourceName != null) {
        Resource resource = resources.get(resourceName);
        if (resource != null) {
          resource.process(synCtx);
        }
      } else if (log.isDebugEnabled()) {
        log.debug("No resource information on the response: " + synCtx.getMessageID());
      }
      return;
    }

    String path = RESTUtils.getFullRequestPath(synCtx);
    String subPath;
    if (versionStrategy.getVersionType().equals(VersionStrategyFactory.TYPE_URL)) {
      // for URL based
      // request --> http://{host:port}/context/version/path/to/resource
      subPath = path.substring(context.length() + versionStrategy.getVersion().length() + 1);
    } else {
      subPath = path.substring(context.length());
    }
    if ("".equals(subPath)) {
      subPath = "/";
    }
    synCtx.setProperty(RESTConstants.REST_SUB_REQUEST_PATH, subPath);

    org.apache.axis2.context.MessageContext msgCtx =
        ((Axis2MessageContext) synCtx).getAxis2MessageContext();
    String hostHeader = getHostHeader(msgCtx);
    if (hostHeader != null) {
      synCtx.setProperty(
          RESTConstants.REST_URL_PREFIX, msgCtx.getIncomingTransportName() + "://" + hostHeader);
    }

    Set<Resource> acceptableResources = new HashSet<Resource>();
    for (Resource r : resources.values()) {
      if (r.canProcess(synCtx)) {
        acceptableResources.add(r);
      }
    }

    boolean processed = false;
    if (!acceptableResources.isEmpty()) {
      for (RESTDispatcher dispatcher : RESTUtils.getDispatchers()) {
        Resource resource = dispatcher.findResource(synCtx, acceptableResources);
        if (resource != null) {
          resource.process(synCtx);
          processed = true;
          break;
        }
      }
    }

    if (!processed) {
      if (log.isDebugEnabled()) {
        log.debug("No matching resource was found for the request: " + synCtx.getMessageID());
      }

      Mediator sequence = synCtx.getSequence(RESTConstants.NO_MATCHING_RESOURCE_HANDLER);
      if (sequence != null) {
        sequence.mediate(synCtx);
      }
    }
  }
コード例 #4
0
ファイル: Handler.java プロジェクト: sky54521/DesignPattern
 public void handleRequest(char c) {
   if (successor != null) successor.handleRequest(c);
 }