View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.nio.protocol;
29  
30  import java.io.IOException;
31  
32  import org.apache.http.HttpEntityEnclosingRequest;
33  import org.apache.http.HttpException;
34  import org.apache.http.HttpRequest;
35  import org.apache.http.HttpResponse;
36  import org.apache.http.nio.entity.ConsumingNHttpEntity;
37  import org.apache.http.protocol.HttpContext;
38  
39  /**
40   * NHttpRequestHandler represents a routine for asynchronous processing of
41   * a specific group of non-blocking HTTP requests. Protocol handlers are
42   * designed to take care of protocol specific aspects, whereas individual
43   * request handlers are expected to take care of application specific HTTP
44   * processing. The main purpose of a request handler is to generate a response
45   * object with a content entity to be sent back to the client in response to
46   * the given request
47   *
48   * @since 4.0
49   *
50   * @deprecated (4.2) use {@link HttpAsyncRequestHandler}
51   */
52  @Deprecated
53  public interface NHttpRequestHandler {
54  
55      /**
56       * Triggered when a request is received with an entity. This method should
57       * return a {@link ConsumingNHttpEntity} that will be used to consume the
58       * entity. {@code null} is a valid response value, and will indicate
59       * that the entity should be silently ignored.
60       * <p>
61       * After the entity is fully consumed,
62       * {@link #handle(HttpRequest, HttpResponse, NHttpResponseTrigger, HttpContext)}
63       * is called to notify a full request &amp; entity are ready to be processed.
64       *
65       * @param request the entity enclosing request.
66       * @param context the execution context.
67       * @return non-blocking HTTP entity.
68       * @throws IOException in case of an I/O error.
69       * @throws HttpException in case of HTTP protocol violation or a processing
70       *   problem.
71       */
72      ConsumingNHttpEntity entityRequest(HttpEntityEnclosingRequest request,
73              HttpContext context)
74          throws HttpException, IOException;
75  
76      /**
77       * Initiates processing of the request. This method does not have to submit
78       * a response immediately. It can defer transmission of the HTTP response
79       * back to the client without blocking the I/O thread by delegating the
80       * process of handling the HTTP request to a worker thread. The worker
81       * thread in its turn can use the instance of {@link NHttpResponseTrigger}
82       * passed as a parameter to submit a response as at a later point of time
83       * once content of the response becomes available.
84       *
85       * @param request the HTTP request.
86       * @param response the HTTP response.
87       * @param trigger the response trigger.
88       * @param context the HTTP execution context.
89       * @throws IOException in case of an I/O error.
90       * @throws HttpException in case of HTTP protocol violation or a processing
91       *   problem.
92       */
93      void handle(HttpRequest request, HttpResponse response,
94              NHttpResponseTrigger trigger, HttpContext context)
95          throws HttpException, IOException;
96  
97  }