1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.testing.classic;
29
30 import java.io.IOException;
31 import java.net.Socket;
32
33 import javax.net.ssl.SSLSocket;
34
35 import org.apache.hc.core5.http.ClassicHttpRequest;
36 import org.apache.hc.core5.http.ClassicHttpResponse;
37 import org.apache.hc.core5.http.ContentLengthStrategy;
38 import org.apache.hc.core5.http.config.CharCodingConfig;
39 import org.apache.hc.core5.http.config.Http1Config;
40 import org.apache.hc.core5.http.impl.CharCodingSupport;
41 import org.apache.hc.core5.http.io.HttpConnectionFactory;
42 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
43 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
44
45 public class LoggingBHttpClientConnectionFactory implements HttpConnectionFactory<LoggingBHttpClientConnection> {
46
47 public static final LoggingBHttpClientConnectionFactory INSTANCE = new LoggingBHttpClientConnectionFactory();
48
49 private final Http1Config http1Config;
50 private final CharCodingConfig charCodingConfig;
51 private final ContentLengthStrategy incomingContentStrategy;
52 private final ContentLengthStrategy outgoingContentStrategy;
53 private final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory;
54 private final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory;
55
56 public LoggingBHttpClientConnectionFactory(
57 final Http1Config http1Config,
58 final CharCodingConfig charCodingConfig,
59 final ContentLengthStrategy incomingContentStrategy,
60 final ContentLengthStrategy outgoingContentStrategy,
61 final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
62 final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
63 super();
64 this.http1Config = http1Config != null ? http1Config : Http1Config.DEFAULT;
65 this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
66 this.incomingContentStrategy = incomingContentStrategy;
67 this.outgoingContentStrategy = outgoingContentStrategy;
68 this.requestWriterFactory = requestWriterFactory;
69 this.responseParserFactory = responseParserFactory;
70 }
71
72 public LoggingBHttpClientConnectionFactory(
73 final Http1Config http1Config,
74 final CharCodingConfig charCodingConfig,
75 final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
76 final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
77 this(http1Config, charCodingConfig, null, null, requestWriterFactory, responseParserFactory);
78 }
79
80 public LoggingBHttpClientConnectionFactory(
81 final Http1Config http1Config,
82 final CharCodingConfig charCodingConfig) {
83 this(http1Config, charCodingConfig, null, null, null, null);
84 }
85
86 public LoggingBHttpClientConnectionFactory() {
87 this(null, null, null, null, null, null);
88 }
89
90 LoggingBHttpClientConnection createDetached() {
91 return new LoggingBHttpClientConnection(
92 http1Config,
93 CharCodingSupport.createDecoder(charCodingConfig),
94 CharCodingSupport.createEncoder(charCodingConfig),
95 incomingContentStrategy,
96 outgoingContentStrategy,
97 requestWriterFactory,
98 responseParserFactory);
99 }
100
101 @Override
102 public LoggingBHttpClientConnection createConnection(final Socket socket) throws IOException {
103 final LoggingBHttpClientConnection conn = createDetached();
104 conn.bind(socket);
105 return conn;
106 }
107
108
109
110
111 @Override
112 public LoggingBHttpClientConnection createConnection(final SSLSocket sslSocket, final Socket socket) throws IOException {
113 final LoggingBHttpClientConnection conn = createDetached();
114 conn.bind(sslSocket, socket);
115 return conn;
116 }
117
118 }