1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.http.Header;
23 import org.apache.http.message.BasicHeader;
24 import org.apache.maven.wagon.Wagon;
25
26 import java.util.Map;
27 import java.util.Properties;
28
29
30
31
32 public class HttpMethodConfiguration
33 {
34
35 private Boolean useDefaultHeaders;
36
37 private Properties headers = new Properties();
38
39 private Properties params = new Properties();
40
41 private int connectionTimeout = Wagon.DEFAULT_CONNECTION_TIMEOUT;
42
43 private int readTimeout =
44 Integer.parseInt( System.getProperty( "maven.wagon.rto", Integer.toString( Wagon.DEFAULT_READ_TIMEOUT ) ) );
45
46 private boolean usePreemptive = false;
47
48 public boolean isUseDefaultHeaders()
49 {
50 return useDefaultHeaders == null || useDefaultHeaders.booleanValue();
51 }
52
53 public HttpMethodConfiguration setUseDefaultHeaders( boolean useDefaultHeaders )
54 {
55 this.useDefaultHeaders = Boolean.valueOf( useDefaultHeaders );
56 return this;
57 }
58
59 public Boolean getUseDefaultHeaders()
60 {
61 return useDefaultHeaders;
62 }
63
64 public HttpMethodConfiguration addHeader( String header, String value )
65 {
66 headers.setProperty( header, value );
67 return this;
68 }
69
70 public Properties getHeaders()
71 {
72 return headers;
73 }
74
75 public HttpMethodConfiguration setHeaders( Properties headers )
76 {
77 this.headers = headers;
78 return this;
79 }
80
81 public HttpMethodConfiguration addParam( String param, String value )
82 {
83 params.setProperty( param, value );
84 return this;
85 }
86
87 public Properties getParams()
88 {
89 return params;
90 }
91
92 public HttpMethodConfiguration setParams( Properties params )
93 {
94 this.params = params;
95 return this;
96 }
97
98 public int getConnectionTimeout()
99 {
100 return connectionTimeout;
101 }
102
103 public HttpMethodConfiguration setConnectionTimeout( int connectionTimeout )
104 {
105 this.connectionTimeout = connectionTimeout;
106 return this;
107 }
108
109 public int getReadTimeout()
110 {
111 return readTimeout;
112 }
113
114 public HttpMethodConfiguration setReadTimeout( int readTimeout )
115 {
116 this.readTimeout = readTimeout;
117 return this;
118 }
119
120 public boolean isUsePreemptive()
121 {
122 return usePreemptive;
123 }
124
125 public HttpMethodConfiguration setUsePreemptive( boolean usePreemptive )
126 {
127 this.usePreemptive = usePreemptive;
128 return this;
129 }
130
131 public Header[] asRequestHeaders()
132 {
133 if ( headers == null )
134 {
135 return new Header[0];
136 }
137
138 Header[] result = new Header[headers.size()];
139
140 int index = 0;
141 for ( Map.Entry entry : headers.entrySet() )
142 {
143 String key = (String) entry.getKey();
144 String value = (String) entry.getValue();
145
146 Header header = new BasicHeader( key, value );
147 result[index++] = header;
148 }
149
150 return result;
151 }
152
153 HttpMethodConfiguration copy()
154 {
155 HttpMethodConfiguration copy = new HttpMethodConfiguration();
156
157 copy.setConnectionTimeout( getConnectionTimeout() );
158 copy.setReadTimeout( getReadTimeout() );
159 if ( getHeaders() != null )
160 {
161 copy.getHeaders().putAll( getHeaders() );
162 }
163
164 if ( getParams() != null )
165 {
166 copy.getParams().putAll( getParams() );
167 }
168
169 copy.setUseDefaultHeaders( isUseDefaultHeaders() );
170
171 return copy;
172 }
173
174 }