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  package org.apache.http.impl.nio.client;
28  
29  import org.apache.http.HttpVersion;
30  import org.apache.http.client.protocol.RequestAddCookies;
31  import org.apache.http.client.protocol.RequestAuthCache;
32  import org.apache.http.client.protocol.RequestClientConnControl;
33  import org.apache.http.client.protocol.RequestDefaultHeaders;
34  import org.apache.http.client.protocol.RequestProxyAuthentication;
35  import org.apache.http.client.protocol.RequestTargetAuthentication;
36  import org.apache.http.client.protocol.ResponseProcessCookies;
37  import org.apache.http.impl.nio.reactor.IOReactorConfig;
38  import org.apache.http.nio.conn.ClientAsyncConnectionManager;
39  import org.apache.http.nio.reactor.IOReactorException;
40  import org.apache.http.params.HttpConnectionParams;
41  import org.apache.http.params.HttpParams;
42  import org.apache.http.params.HttpProtocolParams;
43  import org.apache.http.params.SyncBasicHttpParams;
44  import org.apache.http.protocol.BasicHttpProcessor;
45  import org.apache.http.protocol.HTTP;
46  import org.apache.http.protocol.RequestContent;
47  import org.apache.http.protocol.RequestExpectContinue;
48  import org.apache.http.protocol.RequestTargetHost;
49  import org.apache.http.protocol.RequestUserAgent;
50  import org.apache.http.util.VersionInfo;
51  
52  @Deprecated
53  public class DefaultHttpAsyncClient extends AbstractHttpAsyncClient {
54  
55      public DefaultHttpAsyncClient(final ClientAsyncConnectionManager connmgr) {
56          super(connmgr);
57      }
58  
59      public DefaultHttpAsyncClient(final IOReactorConfig config) throws IOReactorException {
60          super(config);
61      }
62  
63      public DefaultHttpAsyncClient() throws IOReactorException {
64          super(new IOReactorConfig());
65      }
66  
67      @Override
68      protected HttpParams createHttpParams() {
69          final HttpParams params = new SyncBasicHttpParams();
70          setDefaultHttpParams(params);
71          return params;
72      }
73  
74      public static void setDefaultHttpParams(final HttpParams params) {
75          HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
76          HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
77          HttpConnectionParams.setTcpNoDelay(params, true);
78          HttpConnectionParams.setSocketBufferSize(params, 8192);
79          HttpProtocolParams.setUserAgent(params, VersionInfo.getUserAgent(
80                  "Apache-HttpAsyncClient",
81                  "org.apache.http.nio.client", DefaultHttpAsyncClient.class));
82      }
83  
84      @Override
85      protected BasicHttpProcessor createHttpProcessor() {
86          final BasicHttpProcessor httpproc = new BasicHttpProcessor();
87          httpproc.addInterceptor(new RequestDefaultHeaders());
88          // Required protocol interceptors
89          httpproc.addInterceptor(new RequestContent());
90          httpproc.addInterceptor(new RequestTargetHost());
91          // Recommended protocol interceptors
92          httpproc.addInterceptor(new RequestClientConnControl());
93          httpproc.addInterceptor(new RequestUserAgent());
94          httpproc.addInterceptor(new RequestExpectContinue());
95          // HTTP state management interceptors
96          httpproc.addInterceptor(new RequestAddCookies());
97          httpproc.addInterceptor(new ResponseProcessCookies());
98          // HTTP authentication interceptors
99          httpproc.addInterceptor(new RequestAuthCache());
100         httpproc.addInterceptor(new RequestTargetAuthentication());
101         httpproc.addInterceptor(new RequestProxyAuthentication());
102         return httpproc;
103     }
104 
105 }