public int handle(ProcessingContext processingContext) {
      StreamSource source;
      StreamTarget target;

      source = (StreamSource) processingContext.getRequestContext();
      target = (StreamTarget) processingContext.getResponseContext();

      try {
        Reader reader;
        Writer writer;
        char[] buffer;
        int length;

        reader = source.getReader();
        writer = target.getWriter();

        buffer = new char[256];
        while ((length = reader.read(buffer, 0, 256)) != -1) {
          writer.write(buffer, 0, length);
        }
        return Dispatcher.OK;
      } catch (IOException e) {
      }

      return Dispatcher.ERROR;
    }
Ejemplo n.º 2
0
  public Status execute(ProcessingContext<? extends S, ? extends T> processingContext) {
    ProcessingContext<S, T> childProcessingContext;
    Status status;

    status = Status.DECLINE;
    childProcessingContext =
        processingContextFactory.getProcessingContext(
            processingContext.getRequestContext(), processingContext.getResponseContext());

    for (Handler<S, T> handler : handlers) {
      Matches matches;

      matches = null;
      if (!(handler instanceof Matcher)
          || (matches = ((Matcher<S, T>) handler).getMatches(processingContext)) != null) {

        childProcessingContext.setAttribute(ProcessingContext.MATCHES_ATTRIBUTE, matches);
        status = handler.execute(processingContext);

        if (status == Status.ERROR || status == Status.DONE) break;
      }
    }

    return status;
  }
    public boolean preHandle(ProcessingContext processingContext) {

      return (processingContext.getRequestContext() instanceof StreamSource
          && processingContext.getResponseContext() instanceof StreamTarget);
    }