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