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.http.protocol;
29
30 import org.apache.hc.core5.http.HttpRequestInterceptor;
31 import org.apache.hc.core5.http.HttpResponseInterceptor;
32
33
34
35
36
37
38 public class HttpProcessorBuilder {
39
40 private ChainBuilder<HttpRequestInterceptor> requestChainBuilder;
41 private ChainBuilder<HttpResponseInterceptor> responseChainBuilder;
42
43 public static HttpProcessorBuilder create() {
44 return new HttpProcessorBuilder();
45 }
46
47 HttpProcessorBuilder() {
48 super();
49 }
50
51 private ChainBuilder<HttpRequestInterceptor> getRequestChainBuilder() {
52 if (requestChainBuilder == null) {
53 requestChainBuilder = new ChainBuilder<>();
54 }
55 return requestChainBuilder;
56 }
57
58 private ChainBuilder<HttpResponseInterceptor> getResponseChainBuilder() {
59 if (responseChainBuilder == null) {
60 responseChainBuilder = new ChainBuilder<>();
61 }
62 return responseChainBuilder;
63 }
64
65 public HttpProcessorBuilder addFirst(final HttpRequestInterceptor e) {
66 if (e == null) {
67 return this;
68 }
69 getRequestChainBuilder().addFirst(e);
70 return this;
71 }
72
73 public HttpProcessorBuilder addLast(final HttpRequestInterceptor e) {
74 if (e == null) {
75 return this;
76 }
77 getRequestChainBuilder().addLast(e);
78 return this;
79 }
80
81 public HttpProcessorBuilder add(final HttpRequestInterceptor e) {
82 return addLast(e);
83 }
84
85 public HttpProcessorBuilder addAllFirst(final HttpRequestInterceptor... e) {
86 if (e == null) {
87 return this;
88 }
89 getRequestChainBuilder().addAllFirst(e);
90 return this;
91 }
92
93 public HttpProcessorBuilder addAllLast(final HttpRequestInterceptor... e) {
94 if (e == null) {
95 return this;
96 }
97 getRequestChainBuilder().addAllLast(e);
98 return this;
99 }
100
101 public HttpProcessorBuilder addAll(final HttpRequestInterceptor... e) {
102 return addAllLast(e);
103 }
104
105 public HttpProcessorBuilder addFirst(final HttpResponseInterceptor e) {
106 if (e == null) {
107 return this;
108 }
109 getResponseChainBuilder().addFirst(e);
110 return this;
111 }
112
113 public HttpProcessorBuilder addLast(final HttpResponseInterceptor e) {
114 if (e == null) {
115 return this;
116 }
117 getResponseChainBuilder().addLast(e);
118 return this;
119 }
120
121 public HttpProcessorBuilder add(final HttpResponseInterceptor e) {
122 return addLast(e);
123 }
124
125 public HttpProcessorBuilder addAllFirst(final HttpResponseInterceptor... e) {
126 if (e == null) {
127 return this;
128 }
129 getResponseChainBuilder().addAllFirst(e);
130 return this;
131 }
132
133 public HttpProcessorBuilder addAllLast(final HttpResponseInterceptor... e) {
134 if (e == null) {
135 return this;
136 }
137 getResponseChainBuilder().addAllLast(e);
138 return this;
139 }
140
141 public HttpProcessorBuilder addAll(final HttpResponseInterceptor... e) {
142 return addAllLast(e);
143 }
144
145 public HttpProcessor build() {
146 return new DefaultHttpProcessor(
147 requestChainBuilder != null ? requestChainBuilder.build() : null,
148 responseChainBuilder != null ? responseChainBuilder.build() : null);
149 }
150
151 }