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.HttpRequest;
33  import org.apache.http.HttpResponse;
34  import org.apache.http.nio.entity.ConsumingNHttpEntity;
35  import org.apache.http.protocol.HttpContext;
36  
37  /**
38   * HTTP request execution handler can be used by client-side protocol handlers
39   * to trigger the submission of a new HTTP request and the processing of an HTTP
40   * response. When a new response entity is available for consumption,
41   * {@link #responseEntity(HttpResponse, HttpContext)} is called.
42   * After the {@link ConsumingNHttpEntity} consumes the response body,
43   * {@link #handleResponse(HttpResponse, HttpContext)} is notified that the
44   * response is fully read.
45   *
46   * @since 4.0
47   *
48   * @deprecated (4.2) use {@link HttpAsyncRequestExecutor} and {@link HttpAsyncRequester}
49   */
50  @Deprecated
51  public interface NHttpRequestExecutionHandler {
52  
53      /**
54       * Triggered when a new connection has been established and the
55       * HTTP context needs to be initialized.
56       *
57       * <p>The attachment object is the same object which was passed
58       * to the connecting I/O reactor when the connection request was
59       * made. The attachment may optionally contain some state information
60       * required in order to correctly initalize the HTTP context.
61       *
62       * @see org.apache.http.nio.reactor.ConnectingIOReactor#connect
63       *
64       * @param context the actual HTTP context
65       * @param attachment the object passed to the connecting I/O reactor
66       *   upon the request for a new connection.
67       */
68      void initalizeContext(HttpContext context, Object attachment);
69  
70      /**
71       * Triggered when the underlying connection is ready to send a new
72       * HTTP request to the target host. This method may return
73       * <code>null</null> if the client is not yet ready to send a
74       * request. In this case the connection will remain open and
75       * can be activated at a later point.
76       * <p>
77       * If the request has an entity, the entity <b>must</b> be an
78       * instance of {@link org.apache.http.nio.entity.ProducingNHttpEntity}.
79       *
80       * @param context the actual HTTP context
81       * @return an HTTP request to be sent or <code>null</null> if no
82       *   request needs to be sent
83       */
84      HttpRequest submitRequest(HttpContext context);
85  
86      /**
87       * Triggered when a response is received with an entity. This method should
88       * return a {@link ConsumingNHttpEntity} that will be used to consume the
89       * entity. <code>null</code> is a valid response value, and will indicate
90       * that the entity should be silently ignored.
91       * <p>
92       * After the entity is fully consumed,
93       * {@link NHttpRequestExecutionHandler#handleResponse(HttpResponse, HttpContext)}
94       * is called to notify a full response & entity are ready to be processed.
95       *
96       * @param response
97       *            The response containing the existing entity.
98       * @param context
99       *            the actual HTTP context
100      * @return An entity that will asynchronously consume the response's content
101      *         body.
102      */
103     ConsumingNHttpEntity responseEntity(HttpResponse response, HttpContext context)
104         throws IOException;
105 
106     /**
107      * Triggered when an HTTP response is ready to be processed.
108      *
109      * @param response
110      *            the HTTP response to be processed
111      * @param context
112      *            the actual HTTP context
113      */
114     void handleResponse(HttpResponse response, HttpContext context)
115         throws IOException;
116 
117     /**
118      * Triggered when the connection is terminated. This event can be used
119      * to release objects stored in the context or perform some other kind
120      * of cleanup.
121      *
122      * @param context the actual HTTP context
123      */
124     void finalizeContext(HttpContext context);
125 
126 }